/** * Add a method to the set of methods held by this Supervisor * * @param method the method to add **/ public void addMethod(Method method) { transport.perform(new AddMethod(method)); }
private void run() { while (serverChannel.isOpen()) { try { parent.addConnection(new Connection(parent, owner, serverChannel.accept())); parent.sync(); } catch (ClosedChannelException ignore) { } catch (Exception e) { log.log(Level.WARNING, "Error accepting connection", e); } } while (true) { try { shutdownGate.await(); return; } catch (InterruptedException ignore) {} } }
/** * Perform the given command in such a way that it does not run * concurrently with the transport thread or other commands * performed by invoking this method. This method will continue to * work even after the transport thread has been shut down. * * @param cmd the command to perform **/ public void perform(Runnable cmd) { if (Thread.currentThread() == thread) { cmd.run(); return; } if (!postCommand(cmd)) { join(); synchronized (thread) { cmd.run(); } } }
/** * Add a connection to the set of connections handled by this * Transport. Invoked by the {@link Connector} class. * * @param conn the connection to add **/ void addConnection(Connection conn) { if (!postCommand(new AddConnectionCmd(conn))) { perform(new CloseConnectionCmd(conn)); } }
public RPCHandler(int port) { supervisor = new Supervisor(new Transport()); this.port = port; }
TargetPoolTask(RPCTargetPool pool, Supervisor orb) { this.pool = pool; this.jrtTask = orb.transport().createTask(this); this.jrtTask.schedule(1.0); }
public void connectLater(Connection c) { if ( ! connectQueue.enqueue(c)) { parent.addConnection(c); } }
@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)); } } }
/** * Synchronize with the transport thread. This method will block * until all commands issued before this method was invoked has * completed. If the transport thread has been shut down (or is in * the progress of being shut down) this method will instead wait * for the transport thread to complete, since no more commands * will be performed, and waiting would be forever. Invoking this * method from the transport thread is not a good idea. * * @return this object, to enable chaining **/ public Transport sync() { SyncCmd cmd = new SyncCmd(); if (postCommand(cmd)) { cmd.waitDone(); } else { join(); } return this; }
/** * Create a new MirrorAPI using the given Supervisor and slobrok * connect specs. * * @param orb the Supervisor to use * @param slobroks slobrok connect spec list * @param bop custom backoff policy, mostly useful for testing **/ public Mirror(Supervisor orb, SlobrokList slobroks, BackOffPolicy bop) { this.orb = orb; this.slobroks = slobroks; this.backOff = bop; updateTask = orb.transport().createTask(new Runnable() { public void run() { checkForUpdate(); } }); reqWait = new RequestWaiter() { public void handleRequestDone(Request req) { requestDone = true; updateTask.scheduleNow(); } }; updateTask.scheduleNow(); }
private void run() { try { while (true) { Connection conn = (Connection) connectQueue.dequeue(); parent.addConnection(conn.connect()); } } catch (EndOfQueueException e) {} synchronized (this) { done = true; notifyAll(); while (!exit) { try { wait(); } catch (InterruptedException x) {} } } }
/** * 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; }
/** * Remove a method from the set of methods held by this Supervisor * * @param methodName name of the method to remove **/ public void removeMethod(String methodName) { transport.perform(new RemoveMethod(methodName)); }
public InvocationClient(Connection conn, Request req, double timeout, RequestWaiter waiter) { this.conn = conn; this.req = req; this.timeout = timeout; this.reqWaiter = waiter; req.clientHandler(this); this.replyKey = conn.allocateKey(); this.timeoutTask = conn.transport().createTask(this); }
/** * Connect to the given address. This method is called by a {@link * Supervisor} object. * * @return the new connection * @param owner the one calling this method * @param spec the address to connect to * @param context application context for the new connection * @param sync perform a synchronous connect in the calling thread * if this flag is set */ Connection connect(Supervisor owner, Spec spec, Object context, boolean sync) { Connection conn = new Connection(this, owner, spec, context); if (sync) { addConnection(conn.connect()); } else { connector.connectLater(conn); } return conn; }