public class FlushConsolidationHandler extends 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.
ChannelHandler.Sharable| Constructor and Description |
|---|
FlushConsolidationHandler()
Create new instance which explicit flush after 256 pending flush operations latest.
|
FlushConsolidationHandler(int explicitFlushAfterFlushes)
Create new instance.
|
bind, connect, deregister, read, writechannelActive, channelInactive, channelRegistered, channelUnregistered, userEventTriggeredhandlerAdded, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerAddedpublic FlushConsolidationHandler()
public FlushConsolidationHandler(int explicitFlushAfterFlushes)
explicitFlushAfterFlushes - the number of flushes after which an explicit flush will be done.public void flush(ChannelHandlerContext ctx) throws Exception
ChannelDuplexHandlerChannelHandlerContext.flush() to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.flush in interface ChannelOutboundHandlerflush in class ChannelDuplexHandlerctx - the ChannelHandlerContext for which the flush operation is madeException - thrown if an error accourpublic void channelReadComplete(ChannelHandlerContext ctx) throws Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireChannelReadComplete() to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelReadComplete in interface ChannelInboundHandlerchannelReadComplete in class ChannelInboundHandlerAdapterExceptionpublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelRead in interface ChannelInboundHandlerchannelRead in class ChannelInboundHandlerAdapterExceptionpublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireExceptionCaught(Throwable) to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.exceptionCaught in interface ChannelHandlerexceptionCaught in interface ChannelInboundHandlerexceptionCaught in class ChannelInboundHandlerAdapterExceptionpublic void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
ChannelDuplexHandlerChannelOutboundInvoker.disconnect(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.disconnect in interface ChannelOutboundHandlerdisconnect in class ChannelDuplexHandlerctx - the ChannelHandlerContext for which the disconnect operation is madepromise - the ChannelPromise to notify once the operation completesException - thrown if an error accourpublic void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
ChannelDuplexHandlerChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.close in interface ChannelOutboundHandlerclose in class ChannelDuplexHandlerctx - the ChannelHandlerContext for which the close operation is madepromise - the ChannelPromise to notify once the operation completesException - thrown if an error accourpublic void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireChannelWritabilityChanged() to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelWritabilityChanged in interface ChannelInboundHandlerchannelWritabilityChanged in class ChannelInboundHandlerAdapterExceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerRemoved in interface ChannelHandlerhandlerRemoved in class ChannelHandlerAdapterExceptionCopyright © 2008–2016 The Netty Project. All rights reserved.