- java.lang.Object
-
- io.netty5.handler.flush.FlushConsolidationHandler
-
- All Implemented Interfaces:
io.netty5.channel.ChannelHandler
public class FlushConsolidationHandler extends Object implements io.netty5.channel.ChannelHandler
ChannelHandlerwhich consolidatesChannel.flush()/ChannelHandlerContext.flush()operations (which also includesChannel.writeAndFlush(Object)andChannelOutboundInvoker.writeAndFlush(Object).Flush operations are generally 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.
If a read loop is currently ongoing,
ChannelHandler.flush(ChannelHandlerContext)will not be passed on to the nextChannelHandlerin theChannelPipeline, as it will pick up any pending flushes whenchannelReadComplete(ChannelHandlerContext)is triggered. If no read loop is ongoing, the behavior depends on theconsolidateWhenNoReadInProgressconstructor argument:- if
false, flushes are passed on to the next handler directly; - if
true, the invocation of the next handler is submitted as a separate task on the event loop. Under high throughput, this gives the opportunity to process other flushes before the task gets executed, thus batching multiple flushes into one.
explicitFlushAfterFlushesis reached the flush will be forwarded as well (whether while in a read loop, or while batching outside of a read loop).If the
Channelbecomes non-writable it will also try to execute any pending flush operations.The
FlushConsolidationHandlershould be put as firstChannelHandlerin theChannelPipelineto have the best effect.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHESThe default number of flushes after which a flush will be forwarded to downstream handlers (whether while in a read loop, or while batching outside of a read loop).
-
Constructor Summary
Constructors Constructor Description FlushConsolidationHandler()Create new instance which explicit flush after 256 pending flush operations at the latest.FlushConsolidationHandler(int explicitFlushAfterFlushes)Create new instance which doesn't consolidate flushes when no read is in progress.FlushConsolidationHandler(int explicitFlushAfterFlushes, boolean consolidateWhenNoReadInProgress)Create new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchannelExceptionCaught(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause)voidchannelRead(io.netty5.channel.ChannelHandlerContext ctx, Object msg)voidchannelReadComplete(io.netty5.channel.ChannelHandlerContext ctx)voidchannelWritabilityChanged(io.netty5.channel.ChannelHandlerContext ctx)io.netty5.util.concurrent.Future<Void>close(io.netty5.channel.ChannelHandlerContext ctx)io.netty5.util.concurrent.Future<Void>disconnect(io.netty5.channel.ChannelHandlerContext ctx)voidflush(io.netty5.channel.ChannelHandlerContext ctx)voidhandlerAdded(io.netty5.channel.ChannelHandlerContext ctx)voidhandlerRemoved(io.netty5.channel.ChannelHandlerContext ctx)
-
-
-
Field Detail
-
DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES
public static final int DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES
The default number of flushes after which a flush will be forwarded to downstream handlers (whether while in a read loop, or while batching outside of a read loop).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FlushConsolidationHandler
public FlushConsolidationHandler()
Create new instance which explicit flush after 256 pending flush operations at the latest.
-
FlushConsolidationHandler
public FlushConsolidationHandler(int explicitFlushAfterFlushes)
Create new instance which doesn't consolidate flushes when no read is in progress.- Parameters:
explicitFlushAfterFlushes- the number of flushes after which an explicit flush will be done.
-
FlushConsolidationHandler
public FlushConsolidationHandler(int explicitFlushAfterFlushes, boolean consolidateWhenNoReadInProgress)Create new instance.- Parameters:
explicitFlushAfterFlushes- the number of flushes after which an explicit flush will be done.consolidateWhenNoReadInProgress- whether to consolidate flushes even when no read loop is currently ongoing.
-
-
Method Detail
-
handlerAdded
public void handlerAdded(io.netty5.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerAddedin interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
flush
public void flush(io.netty5.channel.ChannelHandlerContext ctx)
- Specified by:
flushin interfaceio.netty5.channel.ChannelHandler
-
channelReadComplete
public void channelReadComplete(io.netty5.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelReadCompletein interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
channelRead
public void channelRead(io.netty5.channel.ChannelHandlerContext ctx, Object msg) throws Exception- Specified by:
channelReadin interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
channelExceptionCaught
public void channelExceptionCaught(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception- Specified by:
channelExceptionCaughtin interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
disconnect
public io.netty5.util.concurrent.Future<Void> disconnect(io.netty5.channel.ChannelHandlerContext ctx)
- Specified by:
disconnectin interfaceio.netty5.channel.ChannelHandler
-
close
public io.netty5.util.concurrent.Future<Void> close(io.netty5.channel.ChannelHandlerContext ctx)
- Specified by:
closein interfaceio.netty5.channel.ChannelHandler
-
channelWritabilityChanged
public void channelWritabilityChanged(io.netty5.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelWritabilityChangedin interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
-