AbstractTrafficShapingHandler is for global
and per channel traffic shaping, that is to say a global limitation of the bandwidth, whatever
the number of opened channels and a per channel limitation of the bandwidth.channel.isWritable() and
channelWritabilityChanged(ctx) to handle writability, or through
future.addListener(future -> ...) on the future returned by
ctx.write().release() once this handler is not needed anymore to release all internal resources.
This will not shutdown the EventExecutor as it may be shared, so you need to do this by your own.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private volatile float | |
| pack-priv final ConcurrentMap | channelQueues
All queues per channel |
| private final AtomicLong | cumulativeReadBytes
Maximum cumulative read bytes for one channel among all (as long as channels stay the same) |
| private final AtomicLong | cumulativeWrittenBytes
Maximum cumulative writing bytes for one channel among all (as long as channels stay the same) |
| private static final float | |
| private static final float | |
| private static final float | |
| private static final InternalLogger | |
| private static final float | |
| private volatile float | |
| pack-priv volatile long | maxGlobalWriteSize
Max size in the list before proposing to stop writing new objects from next handlers for all channel (global) |
| private final AtomicLong | queuesSize
Global queues size |
| private volatile long | readChannelLimit
Limit in B/s to apply to read |
| private volatile boolean | |
| private volatile float | |
| private volatile long | writeChannelLimit
Limit in B/s to apply to write |
| private volatile boolean |
| Access | Constructor and Description |
|---|---|
| public | GlobalChannelTrafficShapingHandler(EventExecutorGroup
the executor, long EventExecutorGroup to use for the TrafficCounter.0 or a limit in bytes/s writeGlobalLimit, long 0 or a limit in bytes/s readGlobalLimit, long 0 or a limit in bytes/s writeChannelLimit, long 0 or a limit in bytes/s readChannelLimit, 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. maxTime)Create a new instance. |
| public | GlobalChannelTrafficShapingHandler(EventExecutorGroup
the executor, long EventExecutorGroup to use for the TrafficCounter.0 or a limit in bytes/s writeGlobalLimit, long 0 or a limit in bytes/s readGlobalLimit, long 0 or a limit in bytes/s writeChannelLimit, long 0 or a limit in bytes/s readChannelLimit, long The delay between two computations of performances for
channels or 0 if no stats are to be computed. checkInterval)Create a new instance. |
| public | GlobalChannelTrafficShapingHandler(EventExecutorGroup
the executor, long EventExecutorGroup to use for the TrafficCounter.0 or a limit in bytes/s writeGlobalLimit, long 0 or a limit in bytes/s readGlobalLimit, long 0 or a limit in bytes/s writeChannelLimit, long 0 or a limit in bytes/s readChannelLimit)Create a new instance. |
| public | GlobalChannelTrafficShapingHandler(EventExecutorGroup
the executor, long EventExecutorGroup to use for the TrafficCounter.The delay between two computations of performances for
channels or 0 if no stats are to be computed. checkInterval)Create a new instance. |
| public | GlobalChannelTrafficShapingHandler(EventExecutorGroup
the executor)EventExecutorGroup to use for the TrafficCounter.Create a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| public float | |
| public void | channelRead(final ChannelHandlerContext ctx, final Object msg)
Overrides io. Overrides default io. Channel has read a message from the peer.
|
| public Collection | Returns: the list of TrafficCounters that exists at the time of the call.To allow for instance doAccounting to use the TrafficCounter per channel. |
| protected long | checkWaitReadTime(final ChannelHandlerContext ctx, long
the wait delay computed in ms wait, final long the relative now time in ms now)Overrides io. |
| private long | |
| private void | |
| public void | |
| pack-priv void | |
| protected void | doAccounting(TrafficCounter
the TrafficCounter that computes its performance counter)Overrides io. |
| public long | |
| private GlobalChannelTrafficShapingHandler. | |
| public long | |
| public long | |
| public void | handlerAdded(ChannelHandlerContext ctx)
Overrides default io. ChannelHandler was added to the actual context and it's ready to handle events.
|
| public void | handlerRemoved(ChannelHandlerContext ctx)
Overrides io. Overrides default io. ChannelHandler was removed from the actual context and it doesn't handle events
anymore.
|
| protected void | informReadOperation(final ChannelHandlerContext ctx, final long
the relative now time in ms now)Overrides io. |
| public boolean | isSharable()
Overrides default io. true if this handler is sharable and thus can be added
to more than one ChannelPipeline.
|
| public float | |
| protected long | |
| protected long | |
| public long | |
| public final void | |
| private void | sendAllValid(final ChannelHandlerContext ctx, final GlobalChannelTrafficShapingHandler.
|
| public void | setMaxDeviation(float
the maximum deviation to allow during computation of average, default deviation
being 0.1, so +/-10% of the desired bandwidth. Maximum being 0.4. maxDeviation, float the factor set as +x% to the too fast client (minimal value being 0, meaning no
slow down factor), default being 40% (0.4). slowDownFactor, float the factor set as -x% to the too slow client (maximal value being 0, meaning no
acceleration factor), default being -10% (-0.1). accelerationFactor)
|
| public void | setMaxGlobalWriteSize(long
the maximum Global Write Size allowed in the buffer
globally for all channels before write suspended is set. maxGlobalWriteSize)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 | |
| public void | |
| public float | |
| protected void | submitWrite(final ChannelHandlerContext ctx, final Object msg, final long size, final long writedelay, final long now, final Promise<Void> promise)
Implements abstract io. |
| public String | toString()
Overrides io. |
| protected int | |
| public Future | write(final ChannelHandlerContext
the ctx, final Object ChannelHandlerContext for which the write operation is madethe message to write msg)Overrides io. Overrides default io. |
| accelerationFactor | back to summary |
|---|---|
| private volatile float accelerationFactor | |
| channelQueues | back to summary |
|---|---|
| pack-priv final ConcurrentMap<Integer, GlobalChannelTrafficShapingHandler. All queues per channel | |
| cumulativeReadBytes | back to summary |
|---|---|
| private final AtomicLong cumulativeReadBytes Maximum cumulative read bytes for one channel among all (as long as channels stay the same) | |
| cumulativeWrittenBytes | back to summary |
|---|---|
| private final AtomicLong cumulativeWrittenBytes Maximum cumulative writing bytes for one channel among all (as long as channels stay the same) | |
| DEFAULT_ACCELERATION | back to summary |
|---|---|
| private static final float DEFAULT_ACCELERATION | |
| DEFAULT_DEVIATION | back to summary |
|---|---|
| private static final float DEFAULT_DEVIATION | |
| DEFAULT_SLOWDOWN | back to summary |
|---|---|
| private static final float DEFAULT_SLOWDOWN | |
| logger | back to summary |
|---|---|
| private static final InternalLogger logger Hides io. | |
| MAX_DEVIATION | back to summary |
|---|---|
| private static final float MAX_DEVIATION | |
| maxDeviation | back to summary |
|---|---|
| private volatile float maxDeviation | |
| maxGlobalWriteSize | back to summary |
|---|---|
| pack-priv volatile long maxGlobalWriteSize Max size in the list before proposing to stop writing new objects from next handlers for all channel (global) | |
| queuesSize | back to summary |
|---|---|
| private final AtomicLong queuesSize Global queues size | |
| readChannelLimit | back to summary |
|---|---|
| private volatile long readChannelLimit Limit in B/s to apply to read | |
| readDeviationActive | back to summary |
|---|---|
| private volatile boolean readDeviationActive | |
| slowDownFactor | back to summary |
|---|---|
| private volatile float slowDownFactor | |
| writeChannelLimit | back to summary |
|---|---|
| private volatile long writeChannelLimit Limit in B/s to apply to write | |
| writeDeviationActive | back to summary |
|---|---|
| private volatile boolean writeDeviationActive | |
| GlobalChannelTrafficShapingHandler | back to summary |
|---|---|
| public GlobalChannelTrafficShapingHandler(EventExecutorGroup executor, long writeGlobalLimit, long readGlobalLimit, long writeChannelLimit, long readChannelLimit, long checkInterval, long maxTime) Create a new instance.
| |
| GlobalChannelTrafficShapingHandler | back to summary |
|---|---|
| public GlobalChannelTrafficShapingHandler(EventExecutorGroup executor, long writeGlobalLimit, long readGlobalLimit, long writeChannelLimit, long readChannelLimit, long checkInterval) Create a new instance.
| |
| GlobalChannelTrafficShapingHandler | back to summary |
|---|---|
| public GlobalChannelTrafficShapingHandler(EventExecutorGroup executor, long writeGlobalLimit, long readGlobalLimit, long writeChannelLimit, long readChannelLimit) Create a new instance.
| |
| GlobalChannelTrafficShapingHandler | back to summary |
|---|---|
| public GlobalChannelTrafficShapingHandler(EventExecutorGroup executor, long checkInterval) Create a new instance.
| |
| GlobalChannelTrafficShapingHandler | back to summary |
|---|---|
| public GlobalChannelTrafficShapingHandler(EventExecutorGroup executor) Create a new instance.
| |
| accelerationFactor | back to summary |
|---|---|
public float accelerationFactor()
| |
| channelRead | back to summary |
|---|---|
| public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception Overrides io. Overrides default io. Doc from io. Invoked when the current
| |
| channelTrafficCounters | back to summary |
|---|---|
| public Collection To allow for instance doAccounting to use the TrafficCounter per channel.
| |
| checkWaitReadTime | back to summary |
|---|---|
| protected long checkWaitReadTime(final ChannelHandlerContext ctx, long wait, final long now) Overrides io. Doc from io. Method overridden in GTSH to take into account specific timer for the channel.
| |
| computeBalancedWait | back to summary |
|---|---|
| private long computeBalancedWait(float maxLocal, float maxGlobal, long wait) | |
| computeDeviationCumulativeBytes | back to summary |
|---|---|
| private void computeDeviationCumulativeBytes() | |
| configureChannel | back to summary |
|---|---|
public void configureChannel(long newWriteLimit, long newReadLimit)
| |
| createGlobalTrafficCounter | back to summary |
|---|---|
| pack-priv void createGlobalTrafficCounter(EventExecutorGroup executor) Create the global TrafficCounter | |
| doAccounting | back to summary |
|---|---|
| protected void doAccounting(TrafficCounter counter) Overrides io. Doc from io. Called each time the accounting is computed from the TrafficCounters. This method could be used for instance to implement almost real time accounting.
| |
| getMaxGlobalWriteSize | back to summary |
|---|---|
public long getMaxGlobalWriteSize()
| |
| getOrSetPerChannel | back to summary |
|---|---|
| private GlobalChannelTrafficShapingHandler. | |
| getReadChannelLimit | back to summary |
|---|---|
public long getReadChannelLimit()
| |
| getWriteChannelLimit | back to summary |
|---|---|
public long getWriteChannelLimit()
| |
| handlerAdded | back to summary |
|---|---|
| public void handlerAdded(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. Gets called after the
| |
| handlerRemoved | back to summary |
|---|---|
| public void handlerRemoved(ChannelHandlerContext ctx) throws Exception Overrides io. Overrides default io. Doc from io. Gets called after the
| |
| informReadOperation | back to summary |
|---|---|
| protected void informReadOperation(final ChannelHandlerContext ctx, final long now) Overrides io. Doc from io. Method overridden in GTSH to take into account specific timer for the channel.
| |
| isSharable | back to summary |
|---|---|
| public boolean isSharable() Overrides default io. Doc from io. Returns
| |
| maxDeviation | back to summary |
|---|---|
public float maxDeviation()
| |
| maximumCumulativeReadBytes | back to summary |
|---|---|
| protected long maximumCumulativeReadBytes() | |
| maximumCumulativeWrittenBytes | back to summary |
|---|---|
| protected long maximumCumulativeWrittenBytes() | |
| queuesSize | back to summary |
|---|---|
public long queuesSize()
| |
| release | back to summary |
|---|---|
| public final void release() Release all internal resources of this instance. | |
| sendAllValid | back to summary |
|---|---|
| private void sendAllValid(final ChannelHandlerContext ctx, final GlobalChannelTrafficShapingHandler. | |
| setMaxDeviation | back to summary |
|---|---|
public void setMaxDeviation(float maxDeviation, float slowDownFactor, float accelerationFactor)
| |
| setMaxGlobalWriteSize | back to summary |
|---|---|
| public void setMaxGlobalWriteSize(long maxGlobalWriteSize) 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.
| |
| setReadChannelLimit | back to summary |
|---|---|
public void setReadChannelLimit(long readLimit)
| |
| setWriteChannelLimit | back to summary |
|---|---|
public void setWriteChannelLimit(long writeLimit)
| |
| slowDownFactor | back to summary |
|---|---|
public float slowDownFactor()
| |
| submitWrite | back to summary |
|---|---|
| protected void submitWrite(final ChannelHandlerContext ctx, final Object msg, final long size, final long writedelay, final long now, final Promise<Void> promise) Implements abstract io.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides io. Doc from java. Returns a string representation of the object. | |
| userDefinedWritabilityIndex | back to summary |
|---|---|
| protected int userDefinedWritabilityIndex() Overrides io.
| |
| write | back to summary |
|---|---|
| public Future Overrides io. Overrides default io. Doc from io. Called once a write operation is made. The write operation will write the messages through the
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv TrafficCounter | |
| pack-priv long | |
| pack-priv long | |
| pack-priv ArrayDeque | |
| pack-priv long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| channelTrafficCounter | back to summary |
|---|---|
| pack-priv TrafficCounter channelTrafficCounter | |
| lastReadTimestamp | back to summary |
|---|---|
| pack-priv long lastReadTimestamp | |
| lastWriteTimestamp | back to summary |
|---|---|
| pack-priv long lastWriteTimestamp | |
| messagesQueue | back to summary |
|---|---|
| pack-priv ArrayDeque<GlobalChannelTrafficShapingHandler. | |
| queueSize | back to summary |
|---|---|
| pack-priv long queueSize | |
| PerChannel | back to summary |
|---|---|
| pack-priv PerChannel() | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Promise | |
| pack-priv final long | |
| pack-priv final long | |
| pack-priv final Object |
| Access | Constructor and Description |
|---|---|
| private |
| promise | back to summary |
|---|---|
| pack-priv final Promise<Void> promise | |
| relativeTimeAction | back to summary |
|---|---|
| pack-priv final long relativeTimeAction | |
| size | back to summary |
|---|---|
| pack-priv final long size | |
| toSend | back to summary |
|---|---|
| pack-priv final Object toSend | |
| ToSend | back to summary |
|---|---|
| private ToSend(final long delay, final Object toSend, final long size, final Promise<Void> promise) | |