public abstract class AbstractTrafficShapingHandler
extends io.netty.channel.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.| 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(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
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(io.netty.channel.ChannelHandlerContext ctx) |
void |
read(io.netty.channel.ChannelHandlerContext ctx) |
void |
setCheckInterval(long checkInterval) |
void |
setMaxTimeWait(long maxTime) |
void |
setReadLimit(long readLimit) |
void |
setWriteLimit(long writeLimit) |
protected abstract void |
submitWrite(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
long delay,
io.netty.channel.ChannelPromise promise) |
String |
toString() |
TrafficCounter |
trafficCounter() |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise) |
bind, close, connect, deregister, disconnect, flushchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredhandlerAdded, handlerRemoved, isSharablepublic 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(io.netty.channel.ChannelHandlerContext ctx,
Object msg)
throws Exception
channelRead in interface io.netty.channel.ChannelInboundHandlerchannelRead in class io.netty.channel.ChannelInboundHandlerAdapterExceptionprotected static boolean isHandlerActive(io.netty.channel.ChannelHandlerContext ctx)
public void read(io.netty.channel.ChannelHandlerContext ctx)
read in interface io.netty.channel.ChannelOutboundHandlerread in class io.netty.channel.ChannelDuplexHandlerpublic void write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise)
throws Exception
write in interface io.netty.channel.ChannelOutboundHandlerwrite in class io.netty.channel.ChannelDuplexHandlerExceptionprotected abstract void submitWrite(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
long delay,
io.netty.channel.ChannelPromise promise)
public TrafficCounter trafficCounter()
Copyright © 2008–2014 The Netty Project. All rights reserved.