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
|
static long |
DEFAULT_MAX_TIME
Default max delay in case of traffic shaping
(during which no communication will occur).
|
protected long |
maxTime
Max delay in wait
|
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) |
protected |
AbstractTrafficShapingHandler(long writeLimit,
long readLimit,
long checkInterval,
long maxTime) |
| Modifier and Type | Method and Description |
|---|---|
protected long |
calculateSize(Object msg)
Calculate the size of the given
Object. |
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.
|
long |
getCheckInterval() |
long |
getMaxTimeWait() |
long |
getReadLimit() |
long |
getWriteLimit() |
protected static boolean |
isHandlerActive(ChannelHandlerContext ctx) |
void |
read(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.read() to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
void |
setCheckInterval(long checkInterval) |
void |
setMaxTimeWait(long maxTime) |
void |
setReadLimit(long readLimit) |
void |
setWriteLimit(long writeLimit) |
protected abstract void |
submitWrite(ChannelHandlerContext ctx,
Object msg,
long delay,
ChannelPromise promise) |
String |
toString() |
TrafficCounter |
trafficCounter() |
void |
write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise)
Calls
ChannelHandlerContext.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
bind, close, connect, deregister, disconnect, flushchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredhandlerAdded, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitexceptionCaught, handlerAdded, handlerRemovedpublic static final long DEFAULT_CHECK_INTERVAL
public static final long DEFAULT_MAX_TIME
protected TrafficCounter trafficCounter
protected long maxTime
protected long checkInterval
protected AbstractTrafficShapingHandler(long writeLimit,
long readLimit,
long checkInterval,
long maxTime)
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 computedmaxTime - The maximum delay to wait in case of traffic excessprotected 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)public long getWriteLimit()
public void setWriteLimit(long writeLimit)
writeLimit - the writeLimit to setpublic long getReadLimit()
public void setReadLimit(long readLimit)
readLimit - the readLimit to setpublic long getCheckInterval()
public void setCheckInterval(long checkInterval)
checkInterval - the checkInterval to setpublic void setMaxTimeWait(long maxTime)
maxTime - Max delay in wait, shall be less than TIME OUT in related protocolpublic long getMaxTimeWait()
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 ChannelInboundHandlerAdapterExceptionprotected static boolean isHandlerActive(ChannelHandlerContext ctx)
public void read(ChannelHandlerContext ctx)
ChannelDuplexHandlerChannelHandlerContext.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
ChannelDuplexHandlerChannelHandlerContext.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 accourprotected abstract void submitWrite(ChannelHandlerContext ctx, Object msg, long delay, ChannelPromise promise)
public TrafficCounter trafficCounter()
protected long calculateSize(Object msg)
Object.
This implementation supports ByteBuf and ByteBufHolder. Sub-classes may override this.msg - the msg for which the size should be calculated-1 if unknown.Copyright © 2008–2014 The Netty Project. All rights reserved.