public Slobrok(int port) throws ListenFailedException { orb = new Supervisor(new Transport()); registerMethods(); try { listener = orb.listen(new Spec(port)); } catch (ListenFailedException e) { orb.transport().shutdown().join(); throw e; } }
public void addMethod(Method method) { supervisor.addMethod(method); }
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); }
this.slobroksConfig = slobrokConfig; identity = params.getIdentity(); orb = new Supervisor(new Transport()); orb.setMaxInputBufferSize(params.getMaxInputBufferSize()); orb.setMaxOutputBufferSize(params.getMaxOutputBufferSize()); targetPool = new RPCTargetPool(params.getConnectionExpireSecs()); servicePool = new RPCServicePool(this, 4096); method.methodDesc("Retrieves the message bus version."); method.returnDesc(0, "version", "The message bus version."); orb.addMethod(method); listener = orb.listen(new Spec(params.getListenPort())); } catch (ListenFailedException e) { orb.transport().shutdown().join(); throw new RuntimeException(e);
connectspec="tcp/" + connectspec; supervisor=new Supervisor(new Transport()); target = supervisor.connect(new Spec(connectspec)); Request request=createRequest(method,arguments); target.invokeSync(request,10.0); target.close(); if (supervisor!=null) supervisor.transport().shutdown().join();
/** * Shut down the Mirror. This will close any open connections, * stop the regular mirror updates, and discard all entries. */ public void shutdown() { updateTask.kill(); orb.transport().perform(new Runnable() { public void run() { handleShutdown(); } }); }
/** * 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; }
public RPCHandler(int port) { supervisor = new Supervisor(new Transport()); this.port = port; }
this.backOff = bop; mySpec = spec.toString(); updateTask = orb.transport().createTask(new Runnable() { public void run() { handleUpdate(); } }); .returnDesc(0, "names", "The rpcserver names this server wants to serve"); orb.addMethod(m_list); m_unreg = new Method("slobrok.callback.notifyUnregistered", "s", "", new MethodHandler() { .methodDesc("Notify a server about removed registration") .paramDesc(0, "name", "RpcServer name"); orb.addMethod(m_unreg); updateTask.scheduleNow();
/** * <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); }
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); } }
/** * Convenience method for connecting to a peer, invoking a method * and disconnecting. * * @param spec the address to connect to * @param req the invocation request * @param timeout request timeout in seconds **/ public void invokeBatch(Spec spec, Request req, double timeout) { Target target = connectSync(spec); try { target.invokeSync(req, timeout); } finally { target.close(); } }
/** * Shut down the Register. This will close any open connections * and stop the regular re-registration. */ public void shutdown() { updateTask.kill(); orb.transport().perform(new Runnable() { public void run() { handleShutdown(); } }); }
/** * Constructs a new instance of this policy. The argument given is the connection spec to the slobrok to use for * resolving recipients, as well as the pattern to use when querying. This constructor does _not_ wait for the * mirror to become ready. * * @param arg The slobrok connection spec. */ public ExternPolicy(String arg) { if (arg == null || arg.length() == 0) { error = "Expected parameter, got empty string."; return; } String[] args = arg.split(";", 2); if (args.length != 2 || args[0].length() == 0 || args[1].length() == 0) { error = "Expected parameter on the form '<spec>;<pattern>', got '" + arg + "'."; return; } int pos = args[1].lastIndexOf('/'); if (pos < 0) { error = "Expected pattern on the form '<service>/<session>', got '" + args[1] + "'."; return; } SlobrokList slobroks = new SlobrokList(); slobroks.setup(args[0].split(",")); pattern = args[1]; session = pattern.substring(pos); orb = new Supervisor(new Transport()); mirror = new Mirror(orb, slobroks); error = null; }
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); }
private void connect(Timer timer) throws InterruptedException { while (timer.isTimeLeft()) { pause(); target = supervisor.connectSync(spec); if (target.isValid()) { log.log(LogLevel.DEBUG, "Successfully connected to '" + spec + "', this = " + System.identityHashCode(this)); pauseTime = 0; logCount = 0; return; } else { logWarning(); } } }
@Override public void destroy() { if (destroyed.getAndSet(true)) throw new RuntimeException("Already destroyed"); mirror.shutdown(); orb.transport().shutdown().join(); }
@Override public void init() { if (slobroks != null) { orb = new Supervisor(new Transport()); mirror = new Mirror(orb, slobroks); } if (configSources != null) { if (mirror == null) { orb = new Supervisor(new Transport()); subscriber = subscribe(slobrokConfigId, new ConfigSourceSet(configSources)); } } }
@Override public final void attach(RPCNetwork net) { this.net = net; String prefix = net.getIdentity().getServicePrefix(); if (prefix != null && prefix.length() > 0) { clientIdent = "'" + prefix + "'"; serverIdent = clientIdent; } net.getSupervisor().addMethod(buildMethod()); }
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); }