@ChannelHandler.Sharable public class GlobalChannelTrafficShapingHandler extends AbstractTrafficShapingHandler
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(new GenericFutureListener())
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.ChannelHandler.Sharable, ChannelHandler.Skip
checkInterval, DEFAULT_CHECK_INTERVAL, DEFAULT_MAX_TIME, maxTime, trafficCounter
Constructor and Description |
---|
GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor)
Create a new instance.
|
GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor,
long checkInterval)
Create a new instance.
|
GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor,
long writeGlobalLimit,
long readGlobalLimit,
long writeChannelLimit,
long readChannelLimit)
Create a new instance.
|
GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor,
long writeGlobalLimit,
long readGlobalLimit,
long writeChannelLimit,
long readChannelLimit,
long checkInterval)
Create a new instance.
|
GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor,
long writeGlobalLimit,
long readGlobalLimit,
long writeChannelLimit,
long readChannelLimit,
long checkInterval,
long maxTime)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
float |
accelerationFactor() |
void |
channelRead(ChannelHandlerContext ctx,
Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelHandler in the ChannelPipeline . |
Collection<TrafficCounter> |
channelTrafficCounters()
To allow for instance doAccounting to use the TrafficCounter per channel.
|
protected long |
checkWaitReadTime(ChannelHandlerContext ctx,
long wait,
long now)
Method overridden in GTSH to take into account specific timer for the channel.
|
void |
configureChannel(long newWriteLimit,
long newReadLimit) |
protected void |
doAccounting(TrafficCounter counter)
Called each time the accounting is computed from the TrafficCounters.
|
long |
getMaxGlobalWriteSize() |
long |
getReadChannelLimit() |
long |
getWriteChannelLimit() |
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
protected void |
informReadOperation(ChannelHandlerContext ctx,
long now)
Method overridden in GTSH to take into account specific timer for the channel.
|
float |
maxDeviation() |
protected long |
maximumCumulativeReadBytes() |
protected long |
maximumCumulativeWrittenBytes() |
long |
queuesSize() |
void |
release()
Release all internal resources of this instance.
|
void |
setMaxDeviation(float maxDeviation,
float slowDownFactor,
float accelerationFactor) |
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.
|
void |
setReadChannelLimit(long readLimit) |
void |
setWriteChannelLimit(long writeLimit) |
float |
slowDownFactor() |
protected void |
submitWrite(ChannelHandlerContext ctx,
Object msg,
long size,
long writedelay,
long now,
ChannelPromise promise) |
String |
toString() |
void |
write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise)
Calls
ChannelHandlerContext.write(Object) to forward
to the next ChannelHandler in the ChannelPipeline . |
calculateSize, channelRegistered, configure, configure, configure, getCheckInterval, getMaxTimeWait, getMaxWriteDelay, getMaxWriteSize, getReadLimit, getWriteLimit, isHandlerActive, read, setCheckInterval, setMaxTimeWait, setMaxWriteDelay, setMaxWriteSize, setReadLimit, setWriteLimit, submitWrite, trafficCounter
bind, channelActive, channelInactive, channelReadComplete, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, isSharable, userEventTriggered
public GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor, long writeGlobalLimit, long readGlobalLimit, long writeChannelLimit, long readChannelLimit, long checkInterval, long maxTime)
executor
- the ScheduledExecutorService
to use for the TrafficCounter
.writeGlobalLimit
- 0 or a limit in bytes/sreadGlobalLimit
- 0 or a limit in bytes/swriteChannelLimit
- 0 or a limit in bytes/sreadChannelLimit
- 0 or a limit in bytes/scheckInterval
- The delay between two computations of performances for
channels or 0 if no stats are to be computed.maxTime
- The maximum delay to wait in case of traffic excess.public GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor, long writeGlobalLimit, long readGlobalLimit, long writeChannelLimit, long readChannelLimit, long checkInterval)
executor
- the ScheduledExecutorService
to use for the TrafficCounter
.writeGlobalLimit
- 0 or a limit in bytes/sreadGlobalLimit
- 0 or a limit in bytes/swriteChannelLimit
- 0 or a limit in bytes/sreadChannelLimit
- 0 or a limit in bytes/scheckInterval
- The delay between two computations of performances for
channels or 0 if no stats are to be computed.public GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor, long writeGlobalLimit, long readGlobalLimit, long writeChannelLimit, long readChannelLimit)
executor
- the ScheduledExecutorService
to use for the TrafficCounter
.writeGlobalLimit
- 0 or a limit in bytes/sreadGlobalLimit
- 0 or a limit in bytes/swriteChannelLimit
- 0 or a limit in bytes/sreadChannelLimit
- 0 or a limit in bytes/spublic GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor, long checkInterval)
executor
- the ScheduledExecutorService
to use for the TrafficCounter
.checkInterval
- The delay between two computations of performances for
channels or 0 if no stats are to be computed.public GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor)
executor
- the ScheduledExecutorService
to use for the TrafficCounter
.public float maxDeviation()
public float accelerationFactor()
public float slowDownFactor()
public void setMaxDeviation(float maxDeviation, float slowDownFactor, float accelerationFactor)
maxDeviation
- the maximum deviation to allow during computation of average, default deviation
being 0.1, so +/-10% of the desired bandwidth. Maximum being 0.4.slowDownFactor
- the factor set as +x% to the too fast client (minimal value being 0, meaning no
slow down factor), default being 40% (0.4).accelerationFactor
- the factor set as -x% to the too slow client (maximal value being 0, meaning no
acceleration factor), default being -10% (-0.1).protected void doAccounting(TrafficCounter counter)
AbstractTrafficShapingHandler
doAccounting
in class AbstractTrafficShapingHandler
counter
- the TrafficCounter that computes its performancepublic long getMaxGlobalWriteSize()
public void setMaxGlobalWriteSize(long maxGlobalWriteSize)
maxGlobalWriteSize
- the maximum Global Write Size allowed in the buffer
globally for all channels before write suspended is set.public long queuesSize()
public void configureChannel(long newWriteLimit, long newReadLimit)
newWriteLimit
- Channel write limitnewReadLimit
- Channel read limitpublic long getWriteChannelLimit()
public void setWriteChannelLimit(long writeLimit)
writeLimit
- Channel write limitpublic long getReadChannelLimit()
public void setReadChannelLimit(long readLimit)
readLimit
- Channel read limitpublic final void release()
public void handlerAdded(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
handlerAdded
in interface ChannelHandler
handlerAdded
in class ChannelHandlerAdapter
Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
handlerRemoved
in interface ChannelHandler
handlerRemoved
in class ChannelHandlerAdapter
Exception
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
ChannelHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
in interface ChannelHandler
channelRead
in class AbstractTrafficShapingHandler
Exception
protected long checkWaitReadTime(ChannelHandlerContext ctx, long wait, long now)
AbstractTrafficShapingHandler
wait
- the wait delay computed in msnow
- the relative now time in msprotected void informReadOperation(ChannelHandlerContext ctx, long now)
AbstractTrafficShapingHandler
now
- the relative now time in msprotected long maximumCumulativeWrittenBytes()
protected long maximumCumulativeReadBytes()
public Collection<TrafficCounter> channelTrafficCounters()
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
ChannelHandlerAdapter
ChannelHandlerContext.write(Object)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.write
in interface ChannelHandler
write
in class AbstractTrafficShapingHandler
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 accourprotected void submitWrite(ChannelHandlerContext ctx, Object msg, long size, long writedelay, long now, ChannelPromise promise)
public String toString()
toString
in class AbstractTrafficShapingHandler
Copyright © 2008–2015 The Netty Project. All rights reserved.