public class TrafficCounter
extends java.lang.Object
It computes the statistics for both inbound and outbound traffic periodically at the given
checkInterval
, and calls the AbstractTrafficShapingHandler.doAccounting(TrafficCounter)
method back.
If the checkInterval
is 0
, no accounting will be done and statistics will only be computed at each
receive or write operation.
Modifier and Type | Class and Description |
---|---|
private class |
TrafficCounter.TrafficMonitoringTask
Class to implement monitoring at fix delay
|
Modifier and Type | Field and Description |
---|---|
(package private) java.util.concurrent.atomic.AtomicLong |
checkInterval
Delay between two captures
|
private java.util.concurrent.atomic.AtomicLong |
cumulativeReadBytes
Long life read bytes
|
private java.util.concurrent.atomic.AtomicLong |
cumulativeWrittenBytes
Long life written bytes
|
private java.util.concurrent.atomic.AtomicLong |
currentReadBytes
Current read bytes
|
private java.util.concurrent.atomic.AtomicLong |
currentWrittenBytes
Current written bytes
|
(package private) java.util.concurrent.ScheduledExecutorService |
executor
Executor that will run the monitor
|
private 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 interval
|
private long |
lastReadingTime
Last reading time during last check interval
|
private long |
lastReadThroughput
Last reading bandwidth
|
(package private) java.util.concurrent.atomic.AtomicLong |
lastTime
Last Time Check taken
|
private long |
lastWriteThroughput
Last writing bandwidth
|
private long |
lastWritingTime
Last future writing time during last check interval
|
private long |
lastWrittenBytes
Last written bytes number during last check interval
|
private static InternalLogger |
logger |
(package private) java.lang.Runnable |
monitor
Monitor created once in start()
|
(package private) boolean |
monitorActive
Is Monitor active
|
(package private) java.lang.String |
name
Name of this Monitor
|
private long |
readingTime
Last reading delay during current check interval
|
private long |
realWriteThroughput
Real writing bandwidth
|
private java.util.concurrent.atomic.AtomicLong |
realWrittenBytes
Real written bytes
|
(package private) java.util.concurrent.ScheduledFuture<?> |
scheduledFuture
used in stop() to cancel the timer
|
(package private) AbstractTrafficShapingHandler |
trafficShapingHandler
The associated TrafficShapingHandler
|
private long |
writingTime
Last writing time during current check interval
|
Constructor and Description |
---|
TrafficCounter(AbstractTrafficShapingHandler trafficShapingHandler,
java.util.concurrent.ScheduledExecutorService executor,
java.lang.String name,
long checkInterval)
Constructor with the
AbstractTrafficShapingHandler that hosts it, the Timer to use, its
name, the checkInterval between two computations in millisecond. |
TrafficCounter(java.util.concurrent.ScheduledExecutorService executor,
java.lang.String name,
long checkInterval)
Constructor with the
AbstractTrafficShapingHandler that hosts it, the ScheduledExecutorService
to use, its name, the checkInterval between two computations in milliseconds. |
Modifier and Type | Method and 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.
|
long |
checkInterval() |
void |
configure(long newcheckInterval)
Change checkInterval between two computations in millisecond.
|
long |
cumulativeReadBytes() |
long |
cumulativeWrittenBytes() |
long |
currentReadBytes() |
long |
currentWrittenBytes() |
long |
getRealWriteThroughput() |
java.util.concurrent.atomic.AtomicLong |
getRealWrittenBytes() |
private void |
init(long checkInterval) |
long |
lastCumulativeTime() |
long |
lastReadBytes() |
long |
lastReadThroughput() |
long |
lastTime() |
long |
lastWriteThroughput() |
long |
lastWrittenBytes() |
static long |
milliSecondFromNano() |
java.lang.String |
name() |
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() |
long |
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.
|
private static final InternalLogger logger
private final java.util.concurrent.atomic.AtomicLong currentWrittenBytes
private final java.util.concurrent.atomic.AtomicLong currentReadBytes
private long writingTime
private long readingTime
private final java.util.concurrent.atomic.AtomicLong cumulativeWrittenBytes
private final java.util.concurrent.atomic.AtomicLong cumulativeReadBytes
private long lastCumulativeTime
private long lastWriteThroughput
private long lastReadThroughput
final java.util.concurrent.atomic.AtomicLong lastTime
private volatile long lastWrittenBytes
private volatile long lastReadBytes
private volatile long lastWritingTime
private volatile long lastReadingTime
private final java.util.concurrent.atomic.AtomicLong realWrittenBytes
private long realWriteThroughput
final java.util.concurrent.atomic.AtomicLong checkInterval
final java.lang.String name
final AbstractTrafficShapingHandler trafficShapingHandler
final java.util.concurrent.ScheduledExecutorService executor
java.lang.Runnable monitor
volatile java.util.concurrent.ScheduledFuture<?> scheduledFuture
volatile boolean monitorActive
public TrafficCounter(java.util.concurrent.ScheduledExecutorService executor, java.lang.String name, long checkInterval)
AbstractTrafficShapingHandler
that hosts it, the ScheduledExecutorService
to use, its name, the checkInterval between two computations in milliseconds.executor
- the underlying executor service for scheduling checks, might be null when used
from GlobalChannelTrafficCounter
.name
- the name given to this monitor.checkInterval
- the checkInterval in millisecond between two computations.public TrafficCounter(AbstractTrafficShapingHandler trafficShapingHandler, java.util.concurrent.ScheduledExecutorService executor, java.lang.String name, long checkInterval)
AbstractTrafficShapingHandler
that hosts it, the Timer to use, its
name, the checkInterval between two computations in millisecond.trafficShapingHandler
- the associated AbstractTrafficShapingHandler.executor
- the underlying executor service for scheduling checks, might be null when used
from GlobalChannelTrafficCounter
.name
- the name given to this monitor.checkInterval
- the checkInterval in millisecond between two computations.public static long milliSecondFromNano()
public void start()
public void stop()
void resetAccounting(long newLastTime)
newLastTime
- the milliseconds unix timestamp that we should be considered up-to-date for.private void init(long checkInterval)
public void configure(long newcheckInterval)
newcheckInterval
- The new check interval (in milliseconds)void bytesRecvFlowControl(long recv)
recv
- the size in bytes to readvoid bytesWriteFlowControl(long write)
write
- the size in bytes to writevoid bytesRealWriteFlowControl(long write)
write
- the size in bytes to writepublic long checkInterval()
public long lastReadThroughput()
public long lastWriteThroughput()
public long lastReadBytes()
public long lastWrittenBytes()
public long currentReadBytes()
public long currentWrittenBytes()
public long lastTime()
public long cumulativeWrittenBytes()
public long cumulativeReadBytes()
public long lastCumulativeTime()
public java.util.concurrent.atomic.AtomicLong getRealWrittenBytes()
public long getRealWriteThroughput()
public void resetCumulativeTime()
public java.lang.String name()
@Deprecated public long readTimeToWait(long size, long limitTraffic, long maxTime)
size
- the recv sizelimitTraffic
- the traffic limit in bytes per second.maxTime
- the max time in ms to wait in case of excess of traffic.public long readTimeToWait(long size, long limitTraffic, long maxTime, long now)
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@Deprecated public long writeTimeToWait(long size, long limitTraffic, long maxTime)
size
- the write sizelimitTraffic
- the traffic limit in bytes per second.maxTime
- the max time in ms to wait in case of excess of traffic.public long writeTimeToWait(long size, long limitTraffic, long maxTime, long now)
size
- the write sizelimitTraffic
- the traffic limit in bytes per second.maxTime
- the max time in ms to wait in case of excess of traffic.now
- the current timepublic java.lang.String toString()
toString
in class java.lang.Object