public abstract class AbstractTrafficShapingHandler extends SimpleChannelHandler implements ExternalResourceReleasable
GlobalTrafficShapingHandler
) or per session
bandwidth (see ChannelTrafficShapingHandler
), as traffic shaping.
It allows too 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.ObjectSizeEstimator
can be passed at construction to specify what
is the size of the object to be read or write accordingly to the type of
object. If not specified, it will used the DefaultObjectSizeEstimator
implementation.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 Timer |
timer
Timer to associated to any TrafficCounter
|
protected TrafficCounter |
trafficCounter
Traffic Counter
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
Timer timer)
Constructor using the specified ObjectSizeEstimator and using NO LIMIT and default Check Interval
|
protected |
AbstractTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
Timer timer,
long checkInterval)
Constructor using the specified ObjectSizeEstimator and using NO LIMIT
|
protected |
AbstractTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
Timer timer,
long writeLimit,
long readLimit)
Constructor using the specified ObjectSizeEstimator and using default Check Interval
|
protected |
AbstractTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
Timer timer,
long writeLimit,
long readLimit,
long checkInterval)
Constructor using the specified ObjectSizeEstimator
|
protected |
AbstractTrafficShapingHandler(Timer timer)
Constructor using default
ObjectSizeEstimator and using NO LIMIT and default Check Interval |
protected |
AbstractTrafficShapingHandler(Timer timer,
long checkInterval)
Constructor using default
ObjectSizeEstimator and using NO LIMIT |
protected |
AbstractTrafficShapingHandler(Timer timer,
long writeLimit,
long readLimit)
Constructor using default
ObjectSizeEstimator and using default Check Interval |
protected |
AbstractTrafficShapingHandler(Timer timer,
long writeLimit,
long readLimit,
long checkInterval)
Constructor using default
ObjectSizeEstimator |
Modifier and Type | Method and Description |
---|---|
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.
|
TrafficCounter |
getTrafficCounter() |
void |
handleDownstream(ChannelHandlerContext ctx,
ChannelEvent e)
Handles the specified downstream event.
|
void |
messageReceived(ChannelHandlerContext ctx,
MessageEvent evt)
Invoked when a message object (e.g:
ChannelBuffer ) was received
from a remote peer. |
void |
releaseExternalResources()
Releases the external resources that this object depends on.
|
String |
toString() |
void |
writeRequested(ChannelHandlerContext ctx,
MessageEvent evt)
Invoked when
Channel.write(Object) is called. |
bindRequested, channelBound, channelClosed, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, exceptionCaught, handleUpstream, setInterestOpsRequested, unbindRequested, writeComplete
public static final long DEFAULT_CHECK_INTERVAL
protected TrafficCounter trafficCounter
protected Timer timer
protected long checkInterval
protected AbstractTrafficShapingHandler(Timer timer, long writeLimit, long readLimit, long checkInterval)
ObjectSizeEstimator
timer
- created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024)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(ObjectSizeEstimator objectSizeEstimator, Timer timer, long writeLimit, long readLimit, long checkInterval)
objectSizeEstimator
- the ObjectSizeEstimator
that will be used to compute
the size of the messagetimer
- created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024)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(Timer timer, long writeLimit, long readLimit)
ObjectSizeEstimator
and using default Check Intervaltimer
- created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024)writeLimit
- 0 or a limit in bytes/sreadLimit
- 0 or a limit in bytes/sprotected AbstractTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator, Timer timer, long writeLimit, long readLimit)
objectSizeEstimator
- the ObjectSizeEstimator
that will be used to compute
the size of the messagetimer
- created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024)writeLimit
- 0 or a limit in bytes/sreadLimit
- 0 or a limit in bytes/sprotected AbstractTrafficShapingHandler(Timer timer)
ObjectSizeEstimator
and using NO LIMIT and default Check Intervaltimer
- created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024)protected AbstractTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator, Timer timer)
objectSizeEstimator
- the ObjectSizeEstimator
that will be used to compute
the size of the messagetimer
- created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024)protected AbstractTrafficShapingHandler(Timer timer, long checkInterval)
ObjectSizeEstimator
and using NO LIMITtimer
- created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024)checkInterval
- The delay between two computations of performances for
channels or 0 if no stats are to be computedprotected AbstractTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator, Timer timer, long checkInterval)
objectSizeEstimator
- the ObjectSizeEstimator
that will be used to compute
the size of the messagetimer
- created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024)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)
public void configure(long newWriteLimit, long newReadLimit)
public void configure(long newCheckInterval)
protected void doAccounting(TrafficCounter counter)
counter
- the TrafficCounter that computes its performancepublic void messageReceived(ChannelHandlerContext ctx, MessageEvent evt) throws Exception
SimpleChannelHandler
ChannelBuffer
) was received
from a remote peer.messageReceived
in class SimpleChannelHandler
Exception
public void writeRequested(ChannelHandlerContext ctx, MessageEvent evt) throws Exception
SimpleChannelHandler
Channel.write(Object)
is called.writeRequested
in class SimpleChannelHandler
Exception
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception
SimpleChannelHandler
handleDownstream
in interface ChannelDownstreamHandler
handleDownstream
in class SimpleChannelHandler
ctx
- the context object for this handlere
- the downstream event to process or interceptException
public TrafficCounter getTrafficCounter()
public void releaseExternalResources()
ExternalResourceReleasable
releaseExternalResources
in interface ExternalResourceReleasable
Copyright © 2008-2014 The Netty Project. All Rights Reserved.