org.jboss.netty.handler.traffic
Class ChannelTrafficShapingHandler
java.lang.Object
org.jboss.netty.channel.SimpleChannelHandler
org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler
org.jboss.netty.handler.traffic.ChannelTrafficShapingHandler
- All Implemented Interfaces:
- org.jboss.netty.channel.ChannelDownstreamHandler, org.jboss.netty.channel.ChannelHandler, org.jboss.netty.channel.ChannelUpstreamHandler, org.jboss.netty.util.ExternalResourceReleasable
public class ChannelTrafficShapingHandler
- extends AbstractTrafficShapingHandler
This implementation of the AbstractTrafficShapingHandler
is for channel
traffic shaping, that is to say a per channel limitation of the bandwidth.
The general use should be as follow:
- Add in your pipeline a new ChannelTrafficShapingHandler, before a recommended
ExecutionHandler
(like
OrderedMemoryAwareThreadPoolExecutor
or MemoryAwareThreadPoolExecutor
).
ChannelTrafficShapingHandler myHandler = new ChannelTrafficShapingHandler(timer);
timer could be created using HashedWheelTimer
pipeline.addLast("CHANNEL_TRAFFIC_SHAPING", myHandler);
Note that this handler has a Pipeline Coverage of "one" which means a new handler must be created
for each new channel as the counter cannot be shared among all channels. For instance, if you have a
ChannelPipelineFactory
, you should create a new ChannelTrafficShapingHandler in this
ChannelPipelineFactory
each time getPipeline() method is called.
Other arguments can be passed like write or read limitation (in bytes/s where 0 means no limitation)
or the check interval (in millisecond) that represents the delay between two computations of the
bandwidth and so the call back of the doAccounting method (0 means no accounting at all).
A value of 0 means no accounting for checkInterval. If you need traffic shaping but no such accounting,
it is recommended to set a positive value, even if it is high since the precision of the
Traffic Shaping depends on the period where the traffic is computed. The highest the interval,
the less precise the traffic shaping will be. It is suggested as higher value something close
to 5 or 10 minutes.
- When you shutdown your application, release all the external resources (except the timer internal itself)
by calling:
myHandler.releaseExternalResources();
- Author:
- The Netty Project (netty-dev@lists.jboss.org), Frederic Bregier
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler |
org.jboss.netty.channel.ChannelHandler.Sharable |
Constructor Summary |
ChannelTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
org.jboss.netty.util.Timer timer)
|
ChannelTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
org.jboss.netty.util.Timer timer,
long checkInterval)
|
ChannelTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
org.jboss.netty.util.Timer timer,
long writeLimit,
long readLimit)
|
ChannelTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
org.jboss.netty.util.Timer timer,
long writeLimit,
long readLimit,
long checkInterval)
|
ChannelTrafficShapingHandler(org.jboss.netty.util.Timer timer)
|
ChannelTrafficShapingHandler(org.jboss.netty.util.Timer timer,
long checkInterval)
|
ChannelTrafficShapingHandler(org.jboss.netty.util.Timer timer,
long writeLimit,
long readLimit)
|
ChannelTrafficShapingHandler(org.jboss.netty.util.Timer timer,
long writeLimit,
long readLimit,
long checkInterval)
|
Method Summary |
void |
channelClosed(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelStateEvent e)
|
void |
channelConnected(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelStateEvent e)
|
Methods inherited from class org.jboss.netty.channel.SimpleChannelHandler |
bindRequested, channelBound, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, exceptionCaught, handleUpstream, setInterestOpsRequested, unbindRequested, writeComplete |
ChannelTrafficShapingHandler
public ChannelTrafficShapingHandler(org.jboss.netty.util.Timer timer,
long writeLimit,
long readLimit,
long checkInterval)
- Parameters:
timer
- writeLimit
- readLimit
- checkInterval
-
ChannelTrafficShapingHandler
public ChannelTrafficShapingHandler(org.jboss.netty.util.Timer timer,
long writeLimit,
long readLimit)
- Parameters:
timer
- writeLimit
- readLimit
-
ChannelTrafficShapingHandler
public ChannelTrafficShapingHandler(org.jboss.netty.util.Timer timer,
long checkInterval)
- Parameters:
timer
- checkInterval
-
ChannelTrafficShapingHandler
public ChannelTrafficShapingHandler(org.jboss.netty.util.Timer timer)
- Parameters:
timer
-
ChannelTrafficShapingHandler
public ChannelTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
org.jboss.netty.util.Timer timer,
long writeLimit,
long readLimit,
long checkInterval)
- Parameters:
objectSizeEstimator
- timer
- writeLimit
- readLimit
- checkInterval
-
ChannelTrafficShapingHandler
public ChannelTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
org.jboss.netty.util.Timer timer,
long writeLimit,
long readLimit)
- Parameters:
objectSizeEstimator
- timer
- writeLimit
- readLimit
-
ChannelTrafficShapingHandler
public ChannelTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
org.jboss.netty.util.Timer timer,
long checkInterval)
- Parameters:
objectSizeEstimator
- timer
- checkInterval
-
ChannelTrafficShapingHandler
public ChannelTrafficShapingHandler(org.jboss.netty.util.ObjectSizeEstimator objectSizeEstimator,
org.jboss.netty.util.Timer timer)
- Parameters:
objectSizeEstimator
- timer
-
channelClosed
public void channelClosed(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelStateEvent e)
throws Exception
- Overrides:
channelClosed
in class org.jboss.netty.channel.SimpleChannelHandler
- Throws:
Exception
channelConnected
public void channelConnected(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelStateEvent e)
throws Exception
- Overrides:
channelConnected
in class org.jboss.netty.channel.SimpleChannelHandler
- Throws:
Exception
Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.