public int port() { return listener.port(); }
/** * Listen to the given address. This method is called by a {@link * Supervisor} object. * * @return active object accepting new connections * @param owner the one calling this method * @param spec the address to listen to **/ Acceptor listen(Supervisor owner, Spec spec) throws ListenFailedException { return new Acceptor(this, owner, spec); }
public void run() { try { Acceptor.this.run(); } catch (Throwable problem) { parent.handleFailure(problem, Acceptor.this); } } }
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(); }
/** * Sets the destroyed flag to true. The very first time this method is called, it cleans up all its dependencies. * Even if you retain a reference to this object, all of its content is allowed to be garbage collected. * * @return True if content existed and was destroyed. */ public boolean destroy() { if (!destroyed.getAndSet(true)) { if (slobroksConfig != null) { slobroksConfig.shutdown(); } register.shutdown(); mirror.shutdown(); listener.shutdown().join(); orb.transport().shutdown().join(); targetPool.flushTargets(true); executor.shutdown(); return true; } return false; }
/** * Obtain the port number this network listens to * * @return listening port number */ public int getPort() { return listener.port(); }
@Override public String getConnectionSpec() { return "tcp/" + identity.getHostname() + ":" + listener.port(); }
public String configId() { return "raw:slobrok[1]\n" + "slobrok[0].connectionspec \"" + new Spec("localhost", listener.port()).toString() + "\"\n"; }
/** * 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; }
register = new Register(orb, slobrokConfig.getSlobroks(), identity.getHostname(), listener.port()); mirror = new Mirror(orb, slobrokConfig.getSlobroks());