private static void registerDone(ChannelFuture future) { // Handle any errors that occurred on the local thread while registering. Even though // failures can happen after this point, they will be handled by the channel by closing the // childChannel. if (!future.isSuccess()) { Channel childChannel = future.channel(); if (childChannel.isRegistered()) { childChannel.close(); } else { childChannel.unsafe().closeForcibly(); } } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { final Channel child = (Channel) msg; final int conn = numConnections.incrementAndGet(); if (conn > 0 && conn <= maxNumConnections) { childChannels.add(child); child.closeFuture().addListener(future -> { childChannels.remove(child); numConnections.decrementAndGet(); }); super.channelRead(ctx, msg); } else { numConnections.decrementAndGet(); // Set linger option to 0 so that the server doesn't get too many TIME_WAIT states. child.config().setOption(ChannelOption.SO_LINGER, 0); child.unsafe().closeForcibly(); numDroppedConnections.increment(); if (loggingScheduled.compareAndSet(false, true)) { ctx.executor().schedule(this::writeNumDroppedConnectionsLog, 1, TimeUnit.SECONDS); } } }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { promise.setSuccess(streamChannel); } else if (future.isCancelled()) { promise.cancel(false); } else { if (streamChannel.isRegistered()) { streamChannel.close(); } else { streamChannel.unsafe().closeForcibly(); } promise.setFailure(future.cause()); } } });
@Override final void onHttp2FrameStreamException(ChannelHandlerContext ctx, Http2FrameStreamException cause) { Http2FrameStream stream = cause.stream(); DefaultHttp2StreamChannel childChannel = ((Http2MultiplexCodecStream) stream).channel; try { childChannel.pipeline().fireExceptionCaught(cause.getCause()); } finally { childChannel.unsafe().closeForcibly(); } }
private static void forceClose(Channel child, Throwable t) { child.unsafe().closeForcibly(); logger.warn("Failed to register an accepted channel: {}", child, t); }
@Override final void onHttp2FrameStreamException(ChannelHandlerContext ctx, Http2FrameStreamException cause) { Http2FrameStream stream = cause.stream(); DefaultHttp2StreamChannel childChannel = ((Http2MultiplexCodecStream) stream).channel; try { childChannel.pipeline().fireExceptionCaught(cause.getCause()); } finally { childChannel.unsafe().closeForcibly(); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { SocketChannel childChannel = (SocketChannel) msg; childChannel.config().setSoLinger(0); childChannel.unsafe().closeForcibly(); } }).childHandler(new ChannelInboundHandlerAdapter());
void streamClosed() { streamClosedWithoutError = true; if (readInProgress) { // Just call closeForcibly() as this will take care of fireChannelInactive(). unsafe().closeForcibly(); } else { closePending = true; } }
@Override final void onHttp2FrameStreamException(ChannelHandlerContext ctx, Http2FrameStreamException cause) { Http2FrameStream stream = cause.stream(); DefaultHttp2StreamChannel childChannel = ((Http2MultiplexCodecStream) stream).channel; try { childChannel.pipeline().fireExceptionCaught(cause.getCause()); } finally { childChannel.unsafe().closeForcibly(); } }
private static void registerDone(ChannelFuture future) { // Handle any errors that occurred on the local thread while registering. Even though // failures can happen after this point, they will be handled by the channel by closing the // childChannel. if (!future.isSuccess()) { Channel childChannel = future.channel(); if (childChannel.isRegistered()) { childChannel.close(); } else { childChannel.unsafe().closeForcibly(); } } }
void streamClosed() { streamClosedWithoutError = true; if (readInProgress) { // Just call closeForcibly() as this will take care of fireChannelInactive(). unsafe().closeForcibly(); } else { closePending = true; } }
@Override final void onHttp2FrameStreamException(ChannelHandlerContext ctx, Http2FrameStreamException cause) { Http2FrameStream stream = cause.stream(); DefaultHttp2StreamChannel childChannel = ((Http2MultiplexCodecStream) stream).channel; try { childChannel.pipeline().fireExceptionCaught(cause.getCause()); } finally { childChannel.unsafe().closeForcibly(); } }
if (channel != null) { channel.unsafe().closeForcibly(); channel.close(); } else { channel.unsafe().closeForcibly();
public void open0(ChannelHandlerContext ctx, final Promise<Http2StreamChannel> promise) { assert ctx.executor().inEventLoop(); final Http2StreamChannel streamChannel = ((Http2MultiplexCodec) ctx.handler()).newOutboundStream(); try { init(streamChannel); } catch (Exception e) { streamChannel.unsafe().closeForcibly(); promise.setFailure(e); return; } ChannelFuture future = ctx.channel().eventLoop().register(streamChannel); future.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { promise.setSuccess(streamChannel); } else if (future.isCancelled()) { promise.cancel(false); } else { if (streamChannel.isRegistered()) { streamChannel.close(); } else { streamChannel.unsafe().closeForcibly(); } promise.setFailure(future.cause()); } } }); }
if (channel != null) { channel.unsafe().closeForcibly(); channel.close(); } else { channel.unsafe().closeForcibly();
private static void forceClose(Channel child, Throwable t) { child.unsafe().closeForcibly(); logger.warn("Failed to register an accepted channel: {}", child, t); }
@Override final void onHttp2FrameStreamException(ChannelHandlerContext ctx, Http2FrameStreamException cause) { Http2FrameStream stream = cause.stream(); DefaultHttp2StreamChannel childChannel = ((Http2MultiplexCodecStream) stream).channel; try { childChannel.pipeline().fireExceptionCaught(cause.getCause()); } finally { childChannel.unsafe().closeForcibly(); } }
if (channel != null) { channel.unsafe().closeForcibly(); channel.close(); } else { channel.unsafe().closeForcibly();
private static void forceClose(Channel child, Throwable t) { child.unsafe().closeForcibly(); logger.warn("Failed to register an accepted channel: {}", child, t); }
private static void forceClose(Channel child, Throwable t) { child.unsafe().closeForcibly(); logger.warn("Failed to register an accepted channel: {}", child, t); }