public abstract class AbstractTrafficShapingHandler
extends org.jboss.netty.channel.SimpleChannelHandler
implements org.jboss.netty.util.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.| 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 Executor |
executor
Executor to associated to any TrafficCounter
|
protected TrafficCounter |
trafficCounter
Traffic Counter
|
| Constructor and Description |
|---|
AbstractTrafficShapingHandler(Executor executor)
Constructor using default
ObjectSizeEstimator and using NO LIMIT and default Check Interval |
AbstractTrafficShapingHandler(Executor executor,
long checkInterval)
Constructor using default
ObjectSizeEstimator and using NO LIMIT |
AbstractTrafficShapingHandler(Executor executor,
long writeLimit,
long readLimit)
Constructor using default
ObjectSizeEstimator and using default Check Interval |
AbstractTrafficShapingHandler(Executor executor,
long writeLimit,
long readLimit,
long checkInterval)
Constructor using default
ObjectSizeEstimator |
AbstractTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
Executor executor)
Constructor using the specified ObjectSizeEstimator and using NO LIMIT and default Check Interval
|
AbstractTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
Executor executor,
long checkInterval)
Constructor using the specified ObjectSizeEstimator and using NO LIMIT
|
AbstractTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
Executor executor,
long writeLimit,
long readLimit)
Constructor using the specified ObjectSizeEstimator and using default Check Interval
|
AbstractTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
Executor executor,
long writeLimit,
long readLimit,
long checkInterval)
Constructor using the specified 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(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelEvent e) |
boolean |
hasLimit() |
void |
messageReceived(org.jboss.netty.channel.ChannelHandlerContext arg0,
org.jboss.netty.channel.MessageEvent arg1) |
void |
releaseExternalResources() |
String |
toString() |
void |
writeRequested(org.jboss.netty.channel.ChannelHandlerContext arg0,
org.jboss.netty.channel.MessageEvent arg1) |
bindRequested, channelBound, channelClosed, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, exceptionCaught, handleUpstream, setInterestOpsRequested, unbindRequested, writeCompletepublic static final long DEFAULT_CHECK_INTERVAL
protected TrafficCounter trafficCounter
protected Executor executor
protected long checkInterval
public AbstractTrafficShapingHandler(Executor executor, long writeLimit, long readLimit, long checkInterval)
ObjectSizeEstimatorexecutor - created for instance like Executors.newCachedThreadPoolwriteLimit - 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 computedpublic AbstractTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
Executor executor,
long writeLimit,
long readLimit,
long checkInterval)
objectSizeEstimator - the ObjectSizeEstimator that will be used to compute
the size of the messageexecutor - created for instance like Executors.newCachedThreadPoolwriteLimit - 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 computedpublic AbstractTrafficShapingHandler(Executor executor, long writeLimit, long readLimit)
ObjectSizeEstimator and using default Check Intervalexecutor - created for instance like Executors.newCachedThreadPoolwriteLimit - 0 or a limit in bytes/sreadLimit - 0 or a limit in bytes/spublic AbstractTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
Executor executor,
long writeLimit,
long readLimit)
objectSizeEstimator - the ObjectSizeEstimator that will be used to compute
the size of the messageexecutor - created for instance like Executors.newCachedThreadPoolwriteLimit - 0 or a limit in bytes/sreadLimit - 0 or a limit in bytes/spublic AbstractTrafficShapingHandler(Executor executor)
ObjectSizeEstimator and using NO LIMIT and default Check Intervalexecutor - created for instance like Executors.newCachedThreadPoolpublic AbstractTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
Executor executor)
objectSizeEstimator - the ObjectSizeEstimator that will be used to compute
the size of the messageexecutor - created for instance like Executors.newCachedThreadPoolpublic AbstractTrafficShapingHandler(Executor executor, long checkInterval)
ObjectSizeEstimator and using NO LIMITexecutor - created for instance like Executors.newCachedThreadPoolcheckInterval - The delay between two computations of performances for
channels or 0 if no stats are to be computedpublic AbstractTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
Executor executor,
long checkInterval)
objectSizeEstimator - the ObjectSizeEstimator that will be used to compute
the size of the messageexecutor - created for instance like Executors.newCachedThreadPoolcheckInterval - 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 - newReadLimit - newCheckInterval - public void configure(long newWriteLimit,
long newReadLimit)
newWriteLimit - newReadLimit - public void configure(long newCheckInterval)
newCheckInterval - protected void doAccounting(TrafficCounter counter)
counter - the TrafficCounter that computes its performancepublic void messageReceived(org.jboss.netty.channel.ChannelHandlerContext arg0,
org.jboss.netty.channel.MessageEvent arg1)
throws Exception
messageReceived in class org.jboss.netty.channel.SimpleChannelHandlerExceptionpublic void writeRequested(org.jboss.netty.channel.ChannelHandlerContext arg0,
org.jboss.netty.channel.MessageEvent arg1)
throws Exception
writeRequested in class org.jboss.netty.channel.SimpleChannelHandlerExceptionpublic void handleDownstream(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelEvent e)
throws Exception
handleDownstream in interface org.jboss.netty.channel.ChannelDownstreamHandlerhandleDownstream in class org.jboss.netty.channel.SimpleChannelHandlerExceptionpublic TrafficCounter getTrafficCounter()
public void releaseExternalResources()
releaseExternalResources in interface org.jboss.netty.util.ExternalResourceReleasablepublic boolean hasLimit()
Copyright © 2011. All Rights Reserved.