Package org.jboss.netty.handler.traffic
Class TrafficCounter
java.lang.Object
org.jboss.netty.handler.traffic.TrafficCounter
- Direct Known Subclasses:
GlobalChannelTrafficCounter
TrafficCounter is associated with AbstractTrafficShapingHandler.
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.-
Constructor Summary
ConstructorsConstructorDescriptionTrafficCounter(AbstractTrafficShapingHandler trafficShapingHandler, Timer timer, String name, long checkInterval) Constructor with theAbstractTrafficShapingHandlerthat hosts it, the Timer to use, its name, the checkInterval between two computations in millisecond. -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigure(long newcheckInterval) Change checkInterval between two computations in millisecond.longlonglonglonglonglonglonglonglonglonglonggetName()longstatic longlongreadTimeToWait(long size, long limitTraffic, long maxTime) Deprecated.longreadTimeToWait(long size, long limitTraffic, long maxTime, long now) Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.voidReset both read and written cumulative bytes counters and the associated absolute time from System.currentTimeMillis().voidstart()Start the monitoring process.voidstop()Stop the monitoring process.toString()String informationlongwriteTimeToWait(long size, long limitTraffic, long maxTime) Deprecated.longwriteTimeToWait(long size, long limitTraffic, long maxTime, long now) Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.
-
Constructor Details
-
TrafficCounter
public TrafficCounter(AbstractTrafficShapingHandler trafficShapingHandler, Timer timer, String name, long checkInterval) Constructor with theAbstractTrafficShapingHandlerthat hosts it, the Timer to use, its name, the checkInterval between two computations in millisecond.- Parameters:
trafficShapingHandler- the associated AbstractTrafficShapingHandlertimer- Could be a HashedWheelTimer, might be null when used fromGlobalChannelTrafficCounter.name- the name given to this monitorcheckInterval- the checkInterval in millisecond between two computations.
-
-
Method Details
-
milliSecondFromNano
public static long milliSecondFromNano()- Returns:
- the time in ms using nanoTime, so not real EPOCH time but elapsed time in ms.
-
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. -
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.
-
getRealWrittenBytes
- Returns:
- the realWrittenBytes
-
getRealWriteThroughput
public long getRealWriteThroughput()- Returns:
- the realWriteThroughput
-
resetCumulativeTime
public void resetCumulativeTime()Reset both read and written cumulative bytes counters and the associated absolute time from System.currentTimeMillis(). -
readTimeToWait
Deprecated.Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.- Parameters:
size- the recv sizelimitTraffic- the traffic limit in bytes per secondmaxTime- the max time in ms to wait in case of excess of traffic.- Returns:
- the current time to wait (in ms) if needed for Read operation.
-
readTimeToWait
public long readTimeToWait(long size, long limitTraffic, long maxTime, long now) Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.- Parameters:
size- the recv sizelimitTraffic- the traffic limit in bytes per secondmaxTime- the max time in ms to wait in case of excess of traffic.now- the current time- Returns:
- the current time to wait (in ms) if needed for Read operation.
-
writeTimeToWait
Deprecated.Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.- Parameters:
size- the write sizelimitTraffic- the traffic limit in bytes per secondmaxTime- the max time in ms to wait in case of excess of traffic.- Returns:
- the current time to wait (in ms) if needed for Write operation.
-
writeTimeToWait
public long writeTimeToWait(long size, long limitTraffic, long maxTime, long now) Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.- Parameters:
size- the write sizelimitTraffic- the traffic limit in bytes per secondmaxTime- the max time in ms to wait in case of excess of traffic.now- the current time- Returns:
- the current time to wait (in ms) if needed for Write operation.
-
getName
- Returns:
- the name
-
toString
String information
-