Java Code Examples for io.netty.channel.group.ChannelGroupFuture#addListener()

The following examples show how to use io.netty.channel.group.ChannelGroupFuture#addListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RpcServer.java    From TakinRPC with Apache License 2.0 6 votes vote down vote up
@Override
protected void doStop() {
    try {
        ChannelGroupFuture f = allChannels.close();
        f.addListener(new ChannelGroupFutureListener() {
            @Override
            public void operationComplete(ChannelGroupFuture future) throws Exception {
                if (future.isSuccess()) {
                    notifyStopped();
                } else {
                    notifyFailed(future.cause());
                }
            }
        });
    } catch (Throwable t) {
        notifyFailed(t);
        Throwables.propagate(t);
    }
}
 
Example 2
Source File: ChannelUtils.java    From simulacron with Apache License 2.0 5 votes vote down vote up
public static CompletableFuture<Void> completable(ChannelGroupFuture future) {
  CompletableFuture<Void> cf = new CompletableFuture<>();
  future.addListener(
      (ChannelGroupFutureListener)
          future1 -> {
            if (future1.isSuccess()) {
              cf.complete(null);
            } else {
              cf.completeExceptionally(future1.cause());
            }
          });
  return cf;
}
 
Example 3
Source File: RedisClient.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RFuture<Void> shutdownAsync() {
    RPromise<Void> result = new RedissonPromise<Void>();
    if (channels.isEmpty()) {
        shutdown(result);
        return result;
    }
    
    ChannelGroupFuture channelsFuture = channels.newCloseFuture();
    channelsFuture.addListener(new FutureListener<Void>() {
        @Override
        public void operationComplete(Future<Void> future) throws Exception {
            if (!future.isSuccess()) {
                result.tryFailure(future.cause());
                return;
            }
            
            shutdown(result);
        }
    });
    
    for (Channel channel : channels) {
        RedisConnection connection = RedisConnection.getFrom(channel);
        if (connection != null) {
            connection.closeAsync();
        }
    }
    
    return result;
}