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 ChannelHandler
s 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 an 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 |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
void |
read(io.netty.channel.ChannelHandlerContext ctx) |
bind, close, connect, deregister, disconnect, flush, write
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
public FlowControlHandler()
public FlowControlHandler(boolean releaseMessages)
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerAdded
in interface io.netty.channel.ChannelHandler
handlerAdded
in class io.netty.channel.ChannelHandlerAdapter
Exception
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
Exception
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelInactive
in interface io.netty.channel.ChannelInboundHandler
channelInactive
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void read(io.netty.channel.ChannelHandlerContext ctx) throws Exception
read
in interface io.netty.channel.ChannelOutboundHandler
read
in class io.netty.channel.ChannelDuplexHandler
Exception
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
channelRead
in interface io.netty.channel.ChannelInboundHandler
channelRead
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelReadComplete
in interface io.netty.channel.ChannelInboundHandler
channelReadComplete
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
Copyright © 2008–2023 The Netty Project. All rights reserved.