AbstractTrafficShapingHandler allows to limit the global bandwidth
(see 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.
If you want for any particular reasons to stop the monitoring (accounting) or to change the read/write limit or the check interval, several methods allow that for you:
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | AbstractTrafficShapingHandler.ReopenReadTimerTask
Class to implement setReadable at fix time |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int | CHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX
Default value for Channel UserDefinedWritability index |
| protected volatile long | checkInterval
Delay between two performance snapshots |
| public static final long | DEFAULT_CHECK_INTERVAL
Default delay between two checks: 1s |
| pack-priv static final long | DEFAULT_MAX_SIZE
Default max size to not exceed in buffer (write only). |
| public static final long | DEFAULT_MAX_TIME
Default max delay in case of traffic shaping (during which no communication will occur). |
| pack-priv static final int | GLOBAL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX
Default value for Global UserDefinedWritability index |
| pack-priv static final int | GLOBALCHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX
Default value for GlobalChannel UserDefinedWritability index |
| private static final InternalLogger | |
| protected volatile long | maxTime
Max delay in wait |
| pack-priv volatile long | maxWriteDelay
Max time to delay before proposing to stop writing new objects from next handlers |
| pack-priv volatile long | maxWriteSize
Max size in the list before proposing to stop writing new objects from next handlers |
| pack-priv static final long | MINIMAL_WAIT
Default minimal time to wait: 10ms |
| pack-priv static final AttributeKey | |
| private volatile long | readLimit
Limit in B/s to apply to read |
| pack-priv static final AttributeKey | |
| protected TrafficCounter | trafficCounter
Traffic Counter |
| pack-priv final int | userDefinedWritabilityIndex
Rank in UserDefinedWritability (1 for Channel, 2 for Global TrafficShapingHandler). |
| private volatile long | writeLimit
Limit in B/s to apply to write |
| Access | Constructor and Description |
|---|---|
| protected | AbstractTrafficShapingHandler(long
0 or a limit in bytes/s writeLimit, long 0 or a limit in bytes/s readLimit, long The delay between two computations of performances for
channels or 0 if no stats are to be computed. checkInterval, long The maximum delay to wait in case of traffic excess.
Must be positive. maxTime)
|
| protected | AbstractTrafficShapingHandler(long
0 or a limit in bytes/s writeLimit, long 0 or a limit in bytes/s readLimit, long The delay between two computations of performances for
channels or 0 if no stats are to be computed. checkInterval)Constructor using default max time as delay allowed value of 15000 ms. |
| protected | AbstractTrafficShapingHandler(long
0 or a limit in bytes/s writeLimit, long 0 or a limit in bytes/s readLimit)Constructor using default Check Interval value of 1000 ms and default max time as delay allowed value of 15000 ms. |
| protected | AbstractTrafficShapingHandler()
Constructor using NO LIMIT, default Check Interval value of 1000 ms and default max time as delay allowed value of 15000 ms. |
| protected | AbstractTrafficShapingHandler(long
The delay between two computations of performances for
channels or 0 if no stats are to be computed. checkInterval)Constructor using NO LIMIT and default max time as delay allowed value of 15000 ms. |
| Modifier and Type | Method and Description |
|---|---|
| protected long | Returns: size the size of the msg or-1 if unknown.the msg for which the size should be calculated. msg)Calculate the size of the given |
| public void | channelRead(final ChannelHandlerContext ctx, final Object msg)
Overrides io. Implements io. ChannelHandlerContext#fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
|
| public void | channelRegistered(ChannelHandlerContext ctx)
Overrides io. Implements io. ChannelHandlerContext#fireChannelRegistered() to forward
to the next ChannelInboundHandler in the ChannelPipeline.
|
| pack-priv long | Returns: the wait to use according to the contextthe wait delay computed in ms wait, final long the relative now time in ms now)Method overridden in GTSH to take into account specific timer for the channel. |
| pack-priv void | checkWriteSuspend(ChannelHandlerContext ctx, long
the computed delay delay, long the current queueSize queueSize)Check the writability according to delay and size for the channel. |
| public void | configure(long
The new write limit (in bytes) newWriteLimit, long The new read limit (in bytes) newReadLimit, long The new check interval (in milliseconds) newCheckInterval)Change the underlying limitations and check interval. |
| public void | configure(long
The new write limit (in bytes) newWriteLimit, long The new read limit (in bytes) newReadLimit)Change the underlying limitations. |
| public void | |
| protected void | doAccounting(TrafficCounter
the TrafficCounter that computes its performance counter)Called each time the accounting is computed from the TrafficCounters. |
| public long | |
| public long | |
| public long | |
| public long | |
| public long | |
| public long | |
| public void | handlerRemoved(ChannelHandlerContext ctx)
Overrides io. Implements io. ChannelHandler was removed from the actual context and it doesn't handle events
anymore.
|
| pack-priv void | informReadOperation(final ChannelHandlerContext ctx, final long
the relative now time in ms now)Method overridden in GTSH to take into account specific timer for the channel. |
| protected static boolean | |
| public void | read(ChannelHandlerContext ctx)
Overrides io. Implements io. ChannelHandlerContext#read() to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
|
| pack-priv void | |
| pack-priv void | |
| public void | setCheckInterval(long
the interval in ms between each step check to set, default value being 1000 ms. checkInterval)
|
| public void | setMaxTimeWait(long
Max delay in wait, shall be less than TIME OUT in related protocol.
Must be positive. maxTime)Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. |
| public void | setMaxWriteDelay(long
the maximum Write Delay in ms in the buffer allowed before write suspension is set.
Must be positive. maxWriteDelay)Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. |
| public void | setMaxWriteSize(long
the maximum Write Size allowed in the buffer
per channel before write suspended is set,
default being 4194304 bytes. maxWriteSize)Note that this limit is a best effort on memory limitation to prevent Out Of Memory Exception. |
| public void | setReadLimit(long
the readLimit to set readLimit)Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. |
| pack-priv void | |
| pack-priv void | |
| public void | setWriteLimit(long
the writeLimit to set writeLimit)Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. |
| protected void | submitWrite(final ChannelHandlerContext ctx, final Object msg, final long delay, final ChannelPromise promise)
Deprecated
|
| pack-priv abstract void | submitWrite(ChannelHandlerContext ctx, Object msg, long size, long delay, long now, ChannelPromise promise)
|
| public String | |
| public TrafficCounter | |
| protected int | Returns: the index to be used by the TrafficShapingHandler to manage the user defined writability. For Channel TSH it is defined as 1, for Global TSH it is defined as 2, for GlobalChannel TSH it is defined as 3.
|
| public void | write(final ChannelHandlerContext
the ctx, final Object ChannelHandlerContext for which the write operation is madethe message to write msg, final ChannelPromise the promise)ChannelPromise to notify once the operation completesOverrides io. Implements io. ChannelHandlerContext#write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
|
| CHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX | back to summary |
|---|---|
| pack-priv static final int CHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX Default value for Channel UserDefinedWritability index | |
| checkInterval | back to summary |
|---|---|
| protected volatile long checkInterval Delay between two performance snapshots | |
| DEFAULT_CHECK_INTERVAL | back to summary |
|---|---|
| public static final long DEFAULT_CHECK_INTERVAL Default delay between two checks: 1s | |
| DEFAULT_MAX_SIZE | back to summary |
|---|---|
| pack-priv static final long DEFAULT_MAX_SIZE Default max size to not exceed in buffer (write only). | |
| DEFAULT_MAX_TIME | back to summary |
|---|---|
| public static final long DEFAULT_MAX_TIME Default max delay in case of traffic shaping (during which no communication will occur). Shall be less than TIMEOUT. Here half of "standard" 30s | |
| GLOBAL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX | back to summary |
|---|---|
| pack-priv static final int GLOBAL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX Default value for Global UserDefinedWritability index | |
| GLOBALCHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX | back to summary |
|---|---|
| pack-priv static final int GLOBALCHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX Default value for GlobalChannel UserDefinedWritability index | |
| logger | back to summary |
|---|---|
| private static final InternalLogger logger | |
| maxTime | back to summary |
|---|---|
| protected volatile long maxTime Max delay in wait | |
| maxWriteDelay | back to summary |
|---|---|
| pack-priv volatile long maxWriteDelay Max time to delay before proposing to stop writing new objects from next handlers | |
| maxWriteSize | back to summary |
|---|---|
| pack-priv volatile long maxWriteSize Max size in the list before proposing to stop writing new objects from next handlers | |
| MINIMAL_WAIT | back to summary |
|---|---|
| pack-priv static final long MINIMAL_WAIT Default minimal time to wait: 10ms | |
| READ_SUSPENDED | back to summary |
|---|---|
| pack-priv static final AttributeKey<Boolean> READ_SUSPENDED | |
| readLimit | back to summary |
|---|---|
| private volatile long readLimit Limit in B/s to apply to read | |
| REOPEN_TASK | back to summary |
|---|---|
| pack-priv static final AttributeKey<Runnable> REOPEN_TASK | |
| trafficCounter | back to summary |
|---|---|
| protected TrafficCounter trafficCounter Traffic Counter | |
| userDefinedWritabilityIndex | back to summary |
|---|---|
| pack-priv final int userDefinedWritabilityIndex Rank in UserDefinedWritability (1 for Channel, 2 for Global TrafficShapingHandler). Set in final constructor. Must be between 1 and 31 | |
| writeLimit | back to summary |
|---|---|
| private volatile long writeLimit Limit in B/s to apply to write | |
| AbstractTrafficShapingHandler | back to summary |
|---|---|
protected AbstractTrafficShapingHandler(long writeLimit, long readLimit, long checkInterval, long maxTime)
| |
| AbstractTrafficShapingHandler | back to summary |
|---|---|
| protected AbstractTrafficShapingHandler(long writeLimit, long readLimit, long checkInterval) Constructor using default max time as delay allowed value of 15000 ms.
| |
| AbstractTrafficShapingHandler | back to summary |
|---|---|
| protected AbstractTrafficShapingHandler(long writeLimit, long readLimit) Constructor using default Check Interval value of 1000 ms and default max time as delay allowed value of 15000 ms.
| |
| AbstractTrafficShapingHandler | back to summary |
|---|---|
| protected AbstractTrafficShapingHandler() Constructor using NO LIMIT, default Check Interval value of 1000 ms and default max time as delay allowed value of 15000 ms. | |
| AbstractTrafficShapingHandler | back to summary |
|---|---|
| protected AbstractTrafficShapingHandler(long checkInterval) Constructor using NO LIMIT and default max time as delay allowed value of 15000 ms.
| |
| calculateSize | back to summary |
|---|---|
| protected long calculateSize(Object msg) Calculate the size of the given
| |
| channelRead | back to summary |
|---|---|
| public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| channelRegistered | back to summary |
|---|---|
| public void channelRegistered(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| checkWaitReadTime | back to summary |
|---|---|
| pack-priv long checkWaitReadTime(final ChannelHandlerContext ctx, long wait, final long now) Method overridden in GTSH to take into account specific timer for the channel.
| |
| checkWriteSuspend | back to summary |
|---|---|
| pack-priv void checkWriteSuspend(ChannelHandlerContext ctx, long delay, long queueSize) Check the writability according to delay and size for the channel. Set if necessary setUserDefinedWritability status.
| |
| configure | back to summary |
|---|---|
| public void configure(long newWriteLimit, long newReadLimit, long newCheckInterval) Change the underlying limitations and check interval. Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
| |
| configure | back to summary |
|---|---|
| public void configure(long newWriteLimit, long newReadLimit) Change the underlying limitations. Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
| |
| configure | back to summary |
|---|---|
| public void configure(long newCheckInterval) Change the check interval.
| |
| doAccounting | back to summary |
|---|---|
| protected void doAccounting(TrafficCounter counter) Called each time the accounting is computed from the TrafficCounters. This method could be used for instance to implement almost real time accounting.
| |
| getCheckInterval | back to summary |
|---|---|
public long getCheckInterval()
| |
| getMaxTimeWait | back to summary |
|---|---|
public long getMaxTimeWait()
| |
| getMaxWriteDelay | back to summary |
|---|---|
public long getMaxWriteDelay()
| |
| getMaxWriteSize | back to summary |
|---|---|
public long getMaxWriteSize()
| |
| getReadLimit | back to summary |
|---|---|
public long getReadLimit()
| |
| getWriteLimit | back to summary |
|---|---|
public long getWriteLimit()
| |
| handlerRemoved | back to summary |
|---|---|
| public void handlerRemoved(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Gets called after the
| |
| informReadOperation | back to summary |
|---|---|
| pack-priv void informReadOperation(final ChannelHandlerContext ctx, final long now) Method overridden in GTSH to take into account specific timer for the channel.
| |
| isHandlerActive | back to summary |
|---|---|
| protected static boolean isHandlerActive(ChannelHandlerContext ctx) | |
| read | back to summary |
|---|---|
| public void read(ChannelHandlerContext ctx) Overrides io. Implements io. Doc from io. Calls
| |
| releaseReadSuspended | back to summary |
|---|---|
| pack-priv void releaseReadSuspended(ChannelHandlerContext ctx) Release the Read suspension | |
| releaseWriteSuspended | back to summary |
|---|---|
| pack-priv void releaseWriteSuspended(ChannelHandlerContext ctx) Explicitly release the Write suspended status. | |
| setCheckInterval | back to summary |
|---|---|
public void setCheckInterval(long checkInterval)
| |
| setMaxTimeWait | back to summary |
|---|---|
| public void setMaxTimeWait(long maxTime) Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
| |
| setMaxWriteDelay | back to summary |
|---|---|
| public void setMaxWriteDelay(long maxWriteDelay) Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
| |
| setMaxWriteSize | back to summary |
|---|---|
| public void setMaxWriteSize(long maxWriteSize) Note that this limit is a best effort on memory limitation to prevent Out Of Memory Exception. To ensure it works, the handler generating the write should use one of the way provided by Netty to handle the capacity: - the - the
| |
| setReadLimit | back to summary |
|---|---|
| public void setReadLimit(long readLimit) Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
| |
| setTrafficCounter | back to summary |
|---|---|
pack-priv void setTrafficCounter(TrafficCounter newTrafficCounter)
| |
| setUserDefinedWritability | back to summary |
|---|---|
| pack-priv void setUserDefinedWritability(ChannelHandlerContext ctx, boolean writable) | |
| setWriteLimit | back to summary |
|---|---|
| public void setWriteLimit(long writeLimit) Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics. So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
| |
| submitWrite | back to summary |
|---|---|
| protected void submitWrite(final ChannelHandlerContext ctx, final Object msg, final long delay, final ChannelPromise promise)
Deprecated
| |
| submitWrite | back to summary |
|---|---|
| pack-priv abstract void submitWrite(ChannelHandlerContext ctx, Object msg, long size, long delay, long now, ChannelPromise promise) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| trafficCounter | back to summary |
|---|---|
public TrafficCounter trafficCounter()
| |
| userDefinedWritabilityIndex | back to summary |
|---|---|
protected int userDefinedWritabilityIndex()
| |
| write | back to summary |
|---|---|
| public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final ChannelHandlerContext |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| ctx | back to summary |
|---|---|
| pack-priv final ChannelHandlerContext ctx | |
| ReopenReadTimerTask | back to summary |
|---|---|
| pack-priv ReopenReadTimerTask(ChannelHandlerContext ctx) | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |