org.jboss.netty.handler.traffic

## Class GlobalTrafficShapingHandler

- java.lang.Object
- - org.jboss.netty.channel.SimpleChannelHandler
  - - org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler
    - - org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler

- All Implemented Interfaces:
    ChannelDownstreamHandler, ChannelHandler, ChannelUpstreamHandler, ExternalResourceReleasable

      @ChannelHandler.Sharable
      public class GlobalTrafficShapingHandler
      extends AbstractTrafficShapingHandler

  This implementation of the `AbstractTrafficShapingHandler` is for global traffic shaping, that is to say a global limitation of the bandwidth, whatever the number of opened channels.
  The general use should be as follow:
  - Create your unique GlobalTrafficShapingHandler like:
    `GlobalTrafficShapingHandler myHandler = new GlobalTrafficShapingHandler(timer);`
    timer could be created using `HashedWheelTimer`
    `pipeline.addLast("GLOBAL_TRAFFIC_SHAPING", myHandler);`
    Note that this handler has a Pipeline Coverage of "all" which means only one such handler must be created and shared among all channels as the counter must be shared among all channels.
    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.
  - Add it in your pipeline, before a recommended `ExecutionHandler` (like `OrderedMemoryAwareThreadPoolExecutor` or `MemoryAwareThreadPoolExecutor`).
    `pipeline.addLast("GLOBAL_TRAFFIC_SHAPING", myHandler);`
  - When you shutdown your application, release all the external resources (except the timer internal itself) by calling:
    `myHandler.releaseExternalResources();`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler

      `ChannelHandler.Sharable`

  - ### Field Summary

    - ### Fields inherited from class org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler

      `checkInterval, DEFAULT_CHECK_INTERVAL, timer, trafficCounter`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator, Timer timer)`
    `GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator, Timer timer, long checkInterval)`
    `GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator, Timer timer, long writeLimit, long readLimit)`
    `GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator, Timer timer, long writeLimit, long readLimit, long checkInterval)`
    `GlobalTrafficShapingHandler(Timer timer)`
    `GlobalTrafficShapingHandler(Timer timer, long checkInterval)`
    `GlobalTrafficShapingHandler(Timer timer, long writeLimit, long readLimit)`
    `GlobalTrafficShapingHandler(Timer timer, long writeLimit, long readLimit, long checkInterval)`

  - ### Method Summary

    - ### Methods inherited from class org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler

      `configure, configure, configure, doAccounting, getTrafficCounter, handleDownstream, messageReceived, releaseExternalResources, toString, writeRequested`

    - ### Methods inherited from class org.jboss.netty.channel.SimpleChannelHandler

      `bindRequested, channelBound, channelClosed, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, exceptionCaught, handleUpstream, setInterestOpsRequested, unbindRequested, writeComplete`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### GlobalTrafficShapingHandler

          public GlobalTrafficShapingHandler(Timer timer,
                                     long writeLimit,
                                     long readLimit,
                                     long checkInterval)

    - #### GlobalTrafficShapingHandler

          public GlobalTrafficShapingHandler(Timer timer,
                                     long writeLimit,
                                     long readLimit)

    - #### GlobalTrafficShapingHandler

          public GlobalTrafficShapingHandler(Timer timer,
                                     long checkInterval)

    - #### GlobalTrafficShapingHandler

          public GlobalTrafficShapingHandler(Timer timer)

    - #### GlobalTrafficShapingHandler

          public GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
                                     Timer timer,
                                     long writeLimit,
                                     long readLimit,
                                     long checkInterval)

    - #### GlobalTrafficShapingHandler

          public GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
                                     Timer timer,
                                     long writeLimit,
                                     long readLimit)

    - #### GlobalTrafficShapingHandler

          public GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
                                     Timer timer,
                                     long checkInterval)

    - #### GlobalTrafficShapingHandler

          public GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
                                     Timer timer)

Copyright © 2008-2012 The Netty Project. All Rights Reserved.