private Promise<Void> toPromise(Stream<TcpConnection<Message<P>, Message<P>>> stream) { final Deferred<Void, Promise<Void>> deferred = Promises.<Void>defer().get(); stream.consume( SingleUseConsumer.once( new Consumer<TcpConnection<Message<P>, Message<P>>>() { @Override public void accept(TcpConnection<Message<P>, Message<P>> conn) { deferred.accept((Void) null); } })); stream.when( Throwable.class, SingleUseConsumer.once( new Consumer<Throwable>() { @Override public void accept(Throwable throwable) { deferred.accept(throwable); } })); return deferred.compose(); }
@Override public Promise<Void> shutdown() { final Deferred<Void, Promise<Void>> d = Promises.defer(env, getReactor().getDispatcher()); Reactors.schedule( new Consumer<Void>() { @SuppressWarnings({"rawtypes", "unchecked"}) @Override public void accept(Void v) { final AtomicInteger groupsToShutdown = new AtomicInteger(2); GenericFutureListener listener = new GenericFutureListener() { @Override public void operationComplete(Future future) throws Exception { if (groupsToShutdown.decrementAndGet() == 0) { notifyShutdown(); d.accept((Void) null); } } }; selectorGroup.shutdownGracefully().addListener(listener); ioGroup.shutdownGracefully().addListener(listener); } }, null, getReactor()); return d.compose(); }
public Promise<Boolean> close() { Deferred<Boolean, Promise<Boolean>> d = Promises.defer(env, reactor.getDispatcher()); close(d); return d.compose(); }