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 |
---|---|
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.
|
void |
read(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.read() to forward
to the next ChannelOutboundHandler in the ChannelPipeline . |
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, flush
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
exceptionCaught, handlerAdded, handlerRemoved
public 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
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
in interface ChannelInboundHandler
channelRead
in class ChannelInboundHandlerAdapter
Exception
public void read(ChannelHandlerContext ctx)
ChannelDuplexHandler
ChannelHandlerContext.read()
to forward
to the next ChannelOutboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.read
in interface ChannelOutboundHandler
read
in class ChannelDuplexHandler
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
ChannelDuplexHandler
ChannelHandlerContext.write(Object, ChannelPromise)
to forward
to the next ChannelOutboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.write
in interface ChannelOutboundHandler
write
in class ChannelDuplexHandler
ctx
- 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()
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–2013 The Netty Project. All rights reserved.