public class FlushConsolidationHandler
extends io.netty.channel.ChannelDuplexHandler
ChannelDuplexHandler
which consolidate ChannelOutboundInvoker.flush()
operations (which also
includes ChannelOutboundInvoker.writeAndFlush(Object)
and
ChannelOutboundInvoker.writeAndFlush(Object, ChannelPromise)
).
Flush operations are general speaking expensive as these may trigger a syscall on the transport level. Thus it is in most cases (where write latency can be traded with throughput) a good idea to try to minimize flush operations as much as possible.
When flush(ChannelHandlerContext)
is called it will only pass it on to the next
ChannelOutboundHandler
in the ChannelPipeline
if no read loop is currently ongoing
as it will pick up any pending flushes when channelReadComplete(ChannelHandlerContext)
is trigged.
If explicitFlushAfterFlushes
is reached the flush will also be forwarded as well.
If the Channel
becomes non-writable it will also try to execute any pending flush operations.
The FlushConsolidationHandler
should be put as first ChannelHandler
in the
ChannelPipeline
to have the best effect.
Constructor and Description |
---|
FlushConsolidationHandler()
Create new instance which explicit flush after 256 pending flush operations latest.
|
FlushConsolidationHandler(int explicitFlushAfterFlushes)
Create new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Object msg) |
void |
channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) |
void |
close(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
disconnect(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Throwable cause) |
void |
flush(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
bind, connect, deregister, read, write
channelActive, channelInactive, channelRegistered, channelUnregistered, userEventTriggered
public FlushConsolidationHandler()
public FlushConsolidationHandler(int explicitFlushAfterFlushes)
explicitFlushAfterFlushes
- the number of flushes after which an explicit flush will be done.public void flush(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
flush
in interface io.netty.channel.ChannelOutboundHandler
flush
in class io.netty.channel.ChannelDuplexHandler
java.lang.Exception
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
channelReadComplete
in interface io.netty.channel.ChannelInboundHandler
channelReadComplete
in class io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
channelRead
in interface io.netty.channel.ChannelInboundHandler
channelRead
in class io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public void disconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws java.lang.Exception
disconnect
in interface io.netty.channel.ChannelOutboundHandler
disconnect
in class io.netty.channel.ChannelDuplexHandler
java.lang.Exception
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws java.lang.Exception
close
in interface io.netty.channel.ChannelOutboundHandler
close
in class io.netty.channel.ChannelDuplexHandler
java.lang.Exception
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
channelWritabilityChanged
in interface io.netty.channel.ChannelInboundHandler
channelWritabilityChanged
in class io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
java.lang.Exception