Refine search
- Common ways to obtain Channel
private void myMethod () {Channel c =
ChannelFuture future;future.channel()
ChannelHandlerContext ctx;ctx.channel()
ChannelHandlerContext ctx;ctx.channel().read()
- Smart code suggestions by Codota
}
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { if (ctx.channel().isActive() && ctx.channel().isRegistered()) { // channelActive() event has been fired already, which means this.channelActive() will // not be invoked. We have to initialize here instead. initialize(ctx); } else { // channelActive() event has not been fired yet. this.channelActive() will be invoked // and initialization will occur there. } }
private void protocolViolation(ChannelHandlerContext ctx, CorruptedFrameException ex) { state = State.CORRUPT; if (ctx.channel().isActive()) { Object closeMessage; if (receivedClosingHandshake) { closeMessage = Unpooled.EMPTY_BUFFER; } else { closeMessage = new CloseWebSocketFrame(1002, null); } ctx.writeAndFlush(closeMessage).addListener(ChannelFutureListener.CLOSE); } throw ex; }
@Override public void handlerAdded( ChannelHandlerContext ctx ) throws Exception { // Sometimes the connect event will have happened before adding, the channel will be active then if ( ctx.channel().isActive() ) { SslHandler sslHandler = createSslHandler( ctx, (InetSocketAddress) ctx.channel().remoteAddress() ); replaceSelfWith( sslHandler ); sslHandler.handlerAdded( ctx ); } }
private void failure(String message, Throwable cause, ChannelHandlerContext ctx, Object response) { if (shouldNotIgnoreException(cause)) { mockServerLogger.error(message, cause); } Channel channel = ctx.channel(); channel.writeAndFlush(response); if (channel.isActive()) { channel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } }
private void checkUTF8String(ChannelHandlerContext ctx, ByteBuf buffer) { try { if (utf8Validator == null) { utf8Validator = new Utf8Validator(); } utf8Validator.check(buffer); } catch (CorruptedFrameException ex) { if (ctx.channel().isActive()) { ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } } }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { if (ctx.channel().isActive() && ctx.channel().isRegistered()) { // channelActive() event has been fired already, which means this.channelActive() will // not be invoked. We have to initialize here instead. initialize(ctx); } else { // channelActive() event has not been fired yet. this.channelActive() will be invoked // and initialization will occur there. } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception { // handle the case of to big requests. if (e.getCause() instanceof TooLongFrameException) { DefaultHttpResponse response = new DefaultHttpResponse(HTTP_1_1, REQUEST_ENTITY_TOO_LARGE); ctx.write(response).addListener(ChannelFutureListener.CLOSE); } else { if (ctx.channel().isActive()) { // 连接已断开就不打印了 logger.warn("Exception caught by request handler", e); } ctx.close(); } } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception { // handle the case of to big requests. if (e.getCause() instanceof TooLongFrameException) { DefaultHttpResponse response = new DefaultHttpResponse(HTTP_1_1, REQUEST_ENTITY_TOO_LARGE); ctx.write(response).addListener(ChannelFutureListener.CLOSE); } else { if (ctx.channel().isActive()) { // 连接已断开就不打印了 logger.warn("Exception caught by request handler", e); } ctx.close(); } } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { int status = 500; final String errorMsg = "ClientResponseWriter caught exception in client connection pipeline: " + ChannelUtils.channelInfoForLogging(ctx.channel()); if (cause instanceof ZuulException) { final ZuulException ze = (ZuulException) cause; status = ze.getStatusCode(); LOG.error(errorMsg, cause); } else if (cause instanceof ReadTimeoutException) { LOG.error(errorMsg + ", Read timeout fired"); status = 504; } else { LOG.error(errorMsg, cause); } if (isHandlingRequest && !startedSendingResponseToClient && ctx.channel().isActive()) { final HttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(status)); ctx.writeAndFlush(httpResponse).addListener(ChannelFutureListener.CLOSE); startedSendingResponseToClient = true; } else { ctx.close(); } }