public ClusterMemberContext(ProtocolServer server) { server.addBindingListener( new BindingListener() { @Override public void listeningAt(URI me) { myId = me; } }); }
private void acquireServerId() throws RuntimeException { final Semaphore semaphore = new Semaphore(0); protocolServer.addBindingListener( new BindingListener() { @Override public void listeningAt(URI me) { serverId = me; semaphore.release(); protocolServer.removeBindingListener(this); } }); try { if (!semaphore.tryAcquire(1, TimeUnit.MINUTES)) { throw new RuntimeException("Unable to acquire server id, timed out"); } } catch (InterruptedException e) { Thread.interrupted(); throw new RuntimeException("Unable to acquire server id, interrupted", e); } }