public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler
GlobalTrafficShapingHandler) or per session
bandwidth (see ChannelTrafficShapingHandler), as traffic shaping.
It allows you to implement an almost real time monitoring of the bandwidth using
the monitors from TrafficCounter that will call back every checkInterval
the method doAccounting of this handler.ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
protected long |
checkInterval
Delay between two performance snapshots
|
static long |
DEFAULT_CHECK_INTERVAL
Default delay between two checks: 1s
|
protected TrafficCounter |
trafficCounter
Traffic Counter
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractTrafficShapingHandler()
Constructor using NO LIMIT and default Check Interval
|
protected |
AbstractTrafficShapingHandler(long checkInterval)
Constructor using NO LIMIT
|
protected |
AbstractTrafficShapingHandler(long writeLimit,
long readLimit)
Constructor using default Check Interval
|
protected |
AbstractTrafficShapingHandler(long writeLimit,
long readLimit,
long checkInterval) |
| Modifier and Type | Method and Description |
|---|---|
void |
channelRead(ChannelHandlerContext ctx,
Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline. |
void |
configure(long newCheckInterval)
Change the check interval.
|
void |
configure(long newWriteLimit,
long newReadLimit)
Change the underlying limitations.
|
void |
configure(long newWriteLimit,
long newReadLimit,
long newCheckInterval)
Change the underlying limitations and check interval.
|
protected void |
doAccounting(TrafficCounter counter)
Called each time the accounting is computed from the TrafficCounters.
|
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
read(ChannelHandlerContext ctx)
Calls
ChannelOutboundInvoker.read() to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
String |
toString() |
TrafficCounter |
trafficCounter() |
void |
write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
bind, close, connect, deregister, disconnect, flushchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredexceptionCaught, handlerAddedclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitexceptionCaught, handlerAddedpublic static final long DEFAULT_CHECK_INTERVAL
protected TrafficCounter trafficCounter
protected long checkInterval
protected AbstractTrafficShapingHandler(long writeLimit,
long readLimit,
long checkInterval)
writeLimit - 0 or a limit in bytes/sreadLimit - 0 or a limit in bytes/scheckInterval - The delay between two computations of performances for
channels or 0 if no stats are to be computedprotected AbstractTrafficShapingHandler(long writeLimit,
long readLimit)
writeLimit - 0 or a limit in bytes/sreadLimit - 0 or a limit in bytes/sprotected AbstractTrafficShapingHandler()
protected AbstractTrafficShapingHandler(long checkInterval)
checkInterval - The delay between two computations of performances for
channels or 0 if no stats are to be computedpublic void configure(long newWriteLimit,
long newReadLimit,
long newCheckInterval)
newWriteLimit - The new write limit (in bytes)newReadLimit - The new read limit (in bytes)newCheckInterval - The new check interval (in milliseconds)public void configure(long newWriteLimit,
long newReadLimit)
newWriteLimit - The new write limit (in bytes)newReadLimit - The new read limit (in bytes)public void configure(long newCheckInterval)
newCheckInterval - The new check interval (in milliseconds)protected void doAccounting(TrafficCounter counter)
counter - the TrafficCounter that computes its performancepublic 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 read(ChannelHandlerContext ctx)
ChannelDuplexHandlerChannelOutboundInvoker.read() to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.read in interface ChannelOutboundHandlerread in class ChannelDuplexHandlerpublic void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
ChannelDuplexHandlerChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.write in interface ChannelOutboundHandlerwrite in class ChannelDuplexHandlerctx - the ChannelHandlerContext for which the write operation is mademsg - the message to writepromise - the ChannelPromise to notify once the operation completesException - thrown if an error accourpublic TrafficCounter trafficCounter()
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerRemoved in interface ChannelHandlerhandlerRemoved in class ChannelHandlerAdapterExceptionCopyright © 2008–2013 The Netty Project. All rights reserved.