io.netty.channel.group.ChannelGroupFutureListener Java Examples
The following examples show how to use
io.netty.channel.group.ChannelGroupFutureListener.
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 |
@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 |
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: ProxyFrontendHandler.java From NettyReverseProxy with Apache License 2.0 | 5 votes |
/** * 在这里接收客户端的消息 在客户端和代理服务器建立连接时,也获得了代理服务器和目标服务器的通道outbound, * 通过outbound写入消息到目标服务器 * * @param ctx * @param msg * @throws Exception */ @Override public void channelRead0(final ChannelHandlerContext ctx, byte[] msg) throws Exception { log.info("客户端消息"); allChannels.writeAndFlush(msg).addListener(new ChannelGroupFutureListener() { @Override public void operationComplete(ChannelGroupFuture future) throws Exception { //防止出现发送不成功造成的永久不读取消息的错误. ctx.channel().read(); } }); }
Example #4
Source File: NettyDebugServer.java From ffwd with Apache License 2.0 | 5 votes |
public AsyncFuture<Void> stop() { final Channel server = this.server.getAndSet(null); if (server == null) { throw new IllegalStateException("server not started"); } final ResolvableFuture<Void> serverClose = async.future(); server.close().addListener((ChannelFutureListener) f -> { if (!f.isSuccess()) { serverClose.fail(f.cause()); return; } serverClose.resolve(null); }); final ResolvableFuture<Void> channelGroupClose = async.future(); connected.close().addListener((ChannelGroupFutureListener) f -> { if (!f.isSuccess()) { channelGroupClose.fail(f.cause()); return; } channelGroupClose.resolve(null); }); return async.collectAndDiscard( ImmutableList.<AsyncFuture<Void>>of(serverClose, channelGroupClose)); }