Package org.jboss.netty.handler.traffic
Class TrafficCounter
- java.lang.Object
-
- org.jboss.netty.handler.traffic.TrafficCounter
-
- Direct Known Subclasses:
GlobalChannelTrafficCounter
public class TrafficCounter extends java.lang.Object
TrafficCounter is associated with
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 theAbstractTrafficShapingHandler
.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TrafficCounter.TrafficMonitoringTask
Class to implement monitoring at fix delay
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.atomic.AtomicLong
checkInterval
Delay between two capturesprivate java.util.concurrent.atomic.AtomicLong
cumulativeReadBytes
Long life read bytesprivate java.util.concurrent.atomic.AtomicLong
cumulativeWrittenBytes
Long life written bytesprivate java.util.concurrent.atomic.AtomicLong
currentReadBytes
Current read bytesprivate java.util.concurrent.atomic.AtomicLong
currentWrittenBytes
Current written bytesprivate long
lastCumulativeTime
Last Time where cumulative bytes where reset to zero: this time is a real EPOC time (informative only)private long
lastReadBytes
Last read bytes number during last check intervalprivate long
lastReadingTime
Last reading time during last check intervalprivate long
lastReadThroughput
Last reading bandwidth(package private) java.util.concurrent.atomic.AtomicLong
lastTime
Last Time Check takenprivate long
lastWriteThroughput
Last writing bandwidthprivate long
lastWritingTime
Last future writing time during last check intervalprivate long
lastWrittenBytes
Last written bytes number during last check intervalprivate static InternalLogger
logger
(package private) boolean
monitorActive
Is Monitor active(package private) java.lang.String
name
Name of this Monitorprivate long
readingTime
Last reading delay during current check intervalprivate long
realWriteThroughput
Real writing bandwidthprivate java.util.concurrent.atomic.AtomicLong
realWrittenBytes
Real written bytes(package private) Timeout
timeout
used in stop() to cancel the timer(package private) Timer
timer
One Timer for all Counter(package private) TimerTask
timerTask
Monitor created once in start()(package private) AbstractTrafficShapingHandler
trafficShapingHandler
The associated TrafficShapingHandlerprivate long
writingTime
Last writing time during current check interval
-
Constructor Summary
Constructors Constructor Description TrafficCounter(AbstractTrafficShapingHandler trafficShapingHandler, Timer timer, java.lang.String name, long checkInterval)
Constructor with theAbstractTrafficShapingHandler
that hosts it, the Timer to use, its name, the checkInterval between two computations in millisecond.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description (package private) void
bytesRealWriteFlowControl(long write)
Computes counters for Real Write.(package private) void
bytesRecvFlowControl(long recv)
Computes counters for Read.(package private) void
bytesWriteFlowControl(long write)
Computes counters for Write.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()
java.lang.String
getName()
long
getRealWriteThroughput()
java.util.concurrent.atomic.AtomicLong
getRealWrittenBytes()
static long
milliSecondFromNano()
long
readTimeToWait(long size, long limitTraffic, long maxTime)
Deprecated.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.(package private) void
resetAccounting(long newLastTime)
Reset the accounting on Read and Write.void
resetCumulativeTime()
Reset both read and written cumulative bytes counters and the associated absolute time from System.currentTimeMillis().void
start()
Start the monitoring process.void
stop()
Stop the monitoring process.java.lang.String
toString()
String informationlong
writeTimeToWait(long size, long limitTraffic, long maxTime)
Deprecated.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.
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
currentWrittenBytes
private final java.util.concurrent.atomic.AtomicLong currentWrittenBytes
Current written bytes
-
currentReadBytes
private final java.util.concurrent.atomic.AtomicLong currentReadBytes
Current read bytes
-
writingTime
private long writingTime
Last writing time during current check interval
-
readingTime
private long readingTime
Last reading delay during current check interval
-
cumulativeWrittenBytes
private final java.util.concurrent.atomic.AtomicLong cumulativeWrittenBytes
Long life written bytes
-
cumulativeReadBytes
private final java.util.concurrent.atomic.AtomicLong cumulativeReadBytes
Long life read bytes
-
lastCumulativeTime
private long lastCumulativeTime
Last Time where cumulative bytes where reset to zero: this time is a real EPOC time (informative only)
-
lastWriteThroughput
private long lastWriteThroughput
Last writing bandwidth
-
lastReadThroughput
private long lastReadThroughput
Last reading bandwidth
-
lastTime
final java.util.concurrent.atomic.AtomicLong lastTime
Last Time Check taken
-
lastWrittenBytes
private volatile long lastWrittenBytes
Last written bytes number during last check interval
-
lastReadBytes
private volatile long lastReadBytes
Last read bytes number during last check interval
-
lastWritingTime
private volatile long lastWritingTime
Last future writing time during last check interval
-
lastReadingTime
private volatile long lastReadingTime
Last reading time during last check interval
-
realWrittenBytes
private final java.util.concurrent.atomic.AtomicLong realWrittenBytes
Real written bytes
-
realWriteThroughput
private long realWriteThroughput
Real writing bandwidth
-
checkInterval
final java.util.concurrent.atomic.AtomicLong checkInterval
Delay between two captures
-
name
final java.lang.String name
Name of this Monitor
-
trafficShapingHandler
final AbstractTrafficShapingHandler trafficShapingHandler
The associated TrafficShapingHandler
-
timer
final Timer timer
One Timer for all Counter
-
timerTask
TimerTask timerTask
Monitor created once in start()
-
timeout
volatile Timeout timeout
used in stop() to cancel the timer
-
monitorActive
volatile boolean monitorActive
Is Monitor active
-
-
Constructor Detail
-
TrafficCounter
public TrafficCounter(AbstractTrafficShapingHandler trafficShapingHandler, Timer timer, java.lang.String name, long checkInterval)
Constructor with theAbstractTrafficShapingHandler
that 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 Detail
-
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.
-
resetAccounting
void resetAccounting(long newLastTime)
Reset the accounting on Read and Write.
-
configure
public void configure(long newcheckInterval)
Change checkInterval between two computations in millisecond.
-
bytesRecvFlowControl
void bytesRecvFlowControl(long recv)
Computes counters for Read.- Parameters:
recv
- the size in bytes to read
-
bytesWriteFlowControl
void bytesWriteFlowControl(long write)
Computes counters for Write.- Parameters:
write
- the size in bytes to write
-
bytesRealWriteFlowControl
void bytesRealWriteFlowControl(long write)
Computes counters for Real Write.- Parameters:
write
- the size in bytes to write
-
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
public java.util.concurrent.atomic.AtomicLong 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 public long readTimeToWait(long size, long limitTraffic, long maxTime)
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 public long writeTimeToWait(long size, long limitTraffic, long maxTime)
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
public java.lang.String getName()
- Returns:
- the name
-
toString
public java.lang.String toString()
String information- Overrides:
toString
in classjava.lang.Object
-
-