public class FlowControlHandler
extends io.netty.channel.ChannelDuplexHandler
FlowControlHandler ensures that only one message per read() is sent downstream.
Classes such as ByteToMessageDecoder or MessageToByteEncoder are free to emit as
many events as they like for any given input. A channel's auto reading configuration doesn't usually
apply in these scenarios. This is causing problems in downstream ChannelHandlers that would
like to hold subsequent events while they're processing one event. It's a common problem with the
HttpObjectDecoder that will very often fire a HttpRequest that is immediately followed
by a LastHttpContent event.
{@code
ChannelPipeline pipeline = ...;
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new FlowControlHandler());
pipeline.addLast(new MyExampleHandler());
class MyExampleHandler extends ChannelInboundHandlerAdapter {ChannelConfig.setAutoRead(boolean)| Constructor and Description |
|---|
FlowControlHandler() |
FlowControlHandler(boolean releaseMessages) |
| Modifier and Type | Method and Description |
|---|---|
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
void |
channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx) |
void |
read(io.netty.channel.ChannelHandlerContext ctx) |
bind, close, connect, deregister, disconnect, flush, writechannelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerRemoved, isSharablepublic FlowControlHandler()
public FlowControlHandler(boolean releaseMessages)
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerAdded in interface io.netty.channel.ChannelHandlerhandlerAdded in class io.netty.channel.ChannelHandlerAdapterExceptionpublic void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelInactive in interface io.netty.channel.ChannelInboundHandlerchannelInactive in class io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void read(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
read in interface io.netty.channel.ChannelOutboundHandlerread in class io.netty.channel.ChannelDuplexHandlerExceptionpublic void channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg)
throws Exception
channelRead in interface io.netty.channel.ChannelInboundHandlerchannelRead in class io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelReadComplete in interface io.netty.channel.ChannelInboundHandlerchannelReadComplete in class io.netty.channel.ChannelInboundHandlerAdapterExceptionCopyright © 2008–2019 The Netty Project. All rights reserved.