org.jboss.netty.handler.traffic
Class TrafficCounter

java.lang.Object
  extended by org.jboss.netty.handler.traffic.TrafficCounter

public class TrafficCounter
extends Object

TrafficCounter is associated with AbstractTrafficShapingHandler.

A TrafficCounter has for goal to count the traffic in order to enable to limit the traffic or not, globally or per channel. It compute statistics on read and written bytes at the specified interval and call back the AbstractTrafficShapingHandler doAccounting method at every specified interval. If this interval is set to 0, therefore no accounting will be done and only statistics will be computed at each receive or write operations.

Version:
$Rev: 1225 $, $Date: 2012-05-20 10:48:53 +0200 (dim., 20 mai 2012) $
Author:
The Netty Project (netty-dev@lists.jboss.org), Frederic Bregier

Constructor Summary
TrafficCounter(AbstractTrafficShapingHandler trafficShapingHandler, org.jboss.netty.util.Timer timer, String name, long checkInterval)
          Constructor with the AbstractTrafficShapingHandler that hosts it, the Timer to use, its name, the checkInterval between two computations in millisecond
 
Method Summary
 void configure(long newcheckInterval)
          Change checkInterval between two computations in millisecond
 long getCheckInterval()
           
 long getCumulativeReadBytes()
           
 long getCumulativeWrittenBytes()
           
 long getCurrentReadBytes()
           
 long getCurrentWrittenBytes()
           
 long getLastCumulativeTime()
           
 long getLastReadBytes()
           
 long getLastReadThroughput()
           
 long getLastTime()
           
 long getLastWriteThroughput()
           
 long getLastWrittenBytes()
           
 String getName()
           
 void resetCumulativeTime()
          Reset both read and written cumulative bytes counters and the associated time.
 void start()
          Start the monitoring process
 void stop()
          Stop the monitoring process
 String toString()
          String information
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TrafficCounter

public TrafficCounter(AbstractTrafficShapingHandler trafficShapingHandler,
                      org.jboss.netty.util.Timer timer,
                      String name,
                      long checkInterval)
Constructor with the AbstractTrafficShapingHandler that hosts it, the Timer to use, its name, the checkInterval between two computations in millisecond

Parameters:
trafficShapingHandler - the associated AbstractTrafficShapingHandler
timer - Could be a HashedWheelTimer
name - the name given to this monitor
checkInterval - the checkInterval in millisecond between two computations
Method Detail

start

public void start()
Start the monitoring process


stop

public void stop()
Stop the monitoring process


configure

public void configure(long newcheckInterval)
Change checkInterval between two computations in millisecond

Parameters:
newcheckInterval -

getCheckInterval

public long getCheckInterval()
Returns:
the current checkInterval between two computations of traffic counter in millisecond

getLastReadThroughput

public long getLastReadThroughput()
Returns:
the Read Throughput in bytes/s computes in the last check interval

getLastWriteThroughput

public long getLastWriteThroughput()
Returns:
the Write Throughput in bytes/s computes in the last check interval

getLastReadBytes

public long getLastReadBytes()
Returns:
the number of bytes read during the last check Interval

getLastWrittenBytes

public long getLastWrittenBytes()
Returns:
the number of bytes written during the last check Interval

getCurrentReadBytes

public long getCurrentReadBytes()
Returns:
the current number of bytes read since the last checkInterval

getCurrentWrittenBytes

public long getCurrentWrittenBytes()
Returns:
the current number of bytes written since the last check Interval

getLastTime

public long getLastTime()
Returns:
the Time in millisecond of the last check as of System.currentTimeMillis()

getCumulativeWrittenBytes

public long getCumulativeWrittenBytes()
Returns:
the cumulativeWrittenBytes

getCumulativeReadBytes

public long getCumulativeReadBytes()
Returns:
the cumulativeReadBytes

getLastCumulativeTime

public long getLastCumulativeTime()
Returns:
the lastCumulativeTime in millisecond as of System.currentTimeMillis() when the cumulative counters were reset to 0.

resetCumulativeTime

public void resetCumulativeTime()
Reset both read and written cumulative bytes counters and the associated time.


getName

public String getName()
Returns:
the name

toString

public String toString()
String information

Overrides:
toString in class Object


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.