/** * Create a new Register using the given Supervisor, slobrok * connect specs, hostname and port * * @param orb the Supervisor to use * @param slobroks slobrok connect spec list * @param myHost the hostname of this host * @param myPort the port number we are listening to */ public Register(Supervisor orb, SlobrokList slobroks, String myHost, int myPort) { this(orb, slobroks, new Spec(myHost, myPort)); }
/** * Returns the raw config needed to connect to the given slobrok. * * @param slobrok The slobrok whose connection spec to include. * @return The raw config string. */ public static String getSlobrokConfig(Slobrok slobrok) { return "raw:slobrok[1]\n" + "slobrok[0].connectionspec \"" + new Spec("localhost", slobrok.port()).toString() + "\"\n"; }
public Connection connect() { if (spec == null || spec.malformed()) { setLostReason(new IllegalArgumentException("jrt: malformed or missing spec")); return this; } try { socket = parent.createCryptoSocket(SocketChannel.open(spec.address()), false); } catch (Exception e) { setLostReason(e); } return this; }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof RPCServiceAddress)) { return false; } RPCServiceAddress rhs = (RPCServiceAddress)obj; if (!serviceName.equals(rhs.serviceName)) { return false; } if (!connectionSpec.host().equals(rhs.connectionSpec.host())) { return false; } if (connectionSpec.port() != rhs.connectionSpec.port()) { return false; } if (!sessionName.equals(rhs.sessionName)) { return false; } return true; }
private static ServerSocketChannel createServerSocketChannel(Spec spec) throws ListenFailedException { ServerSocketChannel serverChannel = null; try { serverChannel = ServerSocketChannel.open(); serverChannel.configureBlocking(true); if (spec.port() != 0) { serverChannel.socket().setReuseAddress(true); } serverChannel.socket().bind(spec.address(), 500); } catch (Exception e) { if (serverChannel != null) { try { serverChannel.socket().close(); } catch (Exception ignore) {} } throw new ListenFailedException("Failed to listen to " + spec, e); } return serverChannel; }
private void logWarning() { if (logCount == 0 || System.currentTimeMillis() > nextLogTime ) { log.warning("Could not connect to the config proxy '" + spec.toString() + "'" + " - " + this + "@" + System.identityHashCode(this)); nextLogTime = System.currentTimeMillis() + Math.min(TimeUnit.DAYS.toMillis(1), TimeUnit.SECONDS.toMillis(30) * (++logCount)); log.info("Next log time = " + nextLogTime + ", current = " + System.currentTimeMillis()); } }
/** * Returns whether or not this service address is malformed. * * @return True if malformed. */ public boolean isMalformed() { return sessionName == null || connectionSpec.malformed(); }
/** * <p>Constructs a new instance of this class.</p> * * @param spec The connection spec of this target. * @param orb The jrt supervisor to use when connecting to target. */ public RPCTarget(Spec spec, Supervisor orb) { this.name = spec.toString(); this.target = orb.connect(spec); }
Acceptor(Transport parent, Supervisor owner, Spec spec) throws ListenFailedException { this.parent = parent; this.owner = owner; if (spec.malformed()) throw new ListenFailedException("Malformed spec '" + spec + "'"); serverChannel = createServerSocketChannel(spec); thread.setDaemon(true); thread.start(); }
/** * Constructs a service address from the given specifications. The last component of the service is stored as the * session name. * * @param serviceName The full service name of the address. * @param connectionSpec The connection specification. */ public RPCServiceAddress(String serviceName, String connectionSpec) { this.serviceName = serviceName; int pos = serviceName.lastIndexOf('/'); if (pos > 0 && pos < serviceName.length() - 1) { sessionName = serviceName.substring(pos + 1); } else { sessionName = null; } this.connectionSpec = new Spec(connectionSpec); }
/** * This method will return a target for the given address. If a target does not currently exist for the given * address, it will be created and added to the internal map. Each target is also reference counted so that an * active target is never expired. * * @param orb The supervisor to use to connect to the target. * @param address The address to resolve to a target. * @return A target for the given address. */ public RPCTarget getTarget(Supervisor orb, RPCServiceAddress address) { Spec spec = address.getConnectionSpec(); String key = spec.toString(); RPCTarget ret; synchronized (this) { Entry entry = targets.get(key); if (entry != null) { if (entry.target.getJRTTarget().isValid()) { entry.target.addRef(); entry.lastUse = timer.milliTime(); return entry.target; } entry.target.subRef(); targets.remove(key); } ret = new RPCTarget(spec, orb); targets.put(key, new Entry(ret, timer.milliTime())); } ret.addRef(); return ret; }
public void start() { try { acceptor = supervisor.listen(new Spec(port)); log.info("Listening for RPC requests on port " + port); } catch (Exception e) { throw new RuntimeException(e); } }
this.slobroks = slobroks; this.backOff = bop; mySpec = spec.toString(); updateTask = orb.transport().createTask(new Runnable() { public void run() { handleUpdate(); }
/** * Obtain the Spec for the local port and host interface this Acceptor * is listening to. If this Acceptor is no longer listening (it has * been shut down), null will be returned. * * @return listening spec, or null if not listening. **/ public Spec spec() { if ( ! serverChannel.isOpen()) { return null; } return new Spec(serverChannel.socket().getInetAddress().getHostName(), serverChannel.socket().getLocalPort()); }
@Override public void configure(FiledistributorrpcConfig filedistributorrpcConfig) { spec = new Spec(filedistributorrpcConfig.connectionspec()); }
public void invokeAsync(Request req, double timeout, RequestWaiter waiter) { // TODO: Consider replacing this by a watcher on the target synchronized(this) { // ensure we have exactly 1 valid connection across threads if (target == null || ! target.isValid()) target = supervisor.connect(new Spec(hostname, port)); } target.invokeAsync(req, timeout, waiter); }
public static void main(String[] args) { //String fileReference = args[0]; String fileReference = "59f93f445438c9db7ccbf1629f583c2aa004a68b"; String filename = "com.yahoo.vespatest.ExtraHitSearcher-1.0.0-deploy.jar"; File file = new File(String.format("/tmp/%s/%s", fileReference, filename)); byte[] blob = null; try { blob = IOUtils.readFileBytes(file); } catch (IOException e) { e.printStackTrace(); } log.log(LogLevel.INFO, "Read blob from " + file.getAbsolutePath()); Supervisor supervisor = new Supervisor(new Transport()); Spec spec = new Spec("tcp/localhost:19090"); log.log(LogLevel.INFO, "Connecting to " + spec); Target target = supervisor.connect(spec); if (! target.isValid()) { log.log(LogLevel.INFO, "Could not connect"); System.exit(1); } else { log.log(LogLevel.INFO, "Connected to " + spec); } new RpcTester(target).call(fileReference, filename, blob); }
public RegisterCallback(Request req, String name, String spec) { req.detach(); registerReq = req; this.name = name; this.spec = spec; target = orb.connect(new Spec(spec)); Request cbReq = new Request("slobrok.callback.listNamesServed"); target.invokeAsync(cbReq, 5.0, this); }
/** * The container has no rpc methods, but we still need an RPC sever * to register in Slobrok to enable orchestration */ private Register registerInSlobrok(SlobroksConfig slobrokConfig, QrConfig qrConfig) { if ( ! qrConfig.rpc().enabled()) return null; // 1. Set up RPC server supervisor = new Supervisor(new Transport()); Spec listenSpec = new Spec(qrConfig.rpc().port()); try { acceptor = supervisor.listen(listenSpec); } catch (ListenFailedException e) { throw new RuntimeException("Could not create rpc server listening on " + listenSpec, e); } // 2. Register it in slobrok SlobrokList slobrokList = new SlobrokList(); slobrokList.setup(slobrokConfig.slobrok().stream().map(SlobroksConfig.Slobrok::connectionspec).toArray(String[]::new)); Spec mySpec = new Spec(HostName.getLocalhost(), acceptor.port()); slobrokRegistrator = new Register(supervisor, slobrokList, mySpec); slobrokRegistrator.registerName(qrConfig.rpc().slobrokId()); log.log(LogLevel.INFO, "Registered name '" + qrConfig.rpc().slobrokId() + "' at " + mySpec + " with: " + slobrokList); return slobrokRegistrator; }