Top Description Inners Fields Constructors Methods
io.netty.handler.traffic

public Class TrafficCounter

extends Object
Class Inheritance
Known Direct Subclasses
io.netty.handler.traffic.GlobalChannelTrafficCounter
Static Imports
io.netty.util.internal.ObjectUtil.checkNotNull, .ObjectUtil.checkNotNullWithIAE

Counts the number of read and written bytes for rate-limiting traffic.

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
TrafficCounter.TrafficMonitoringTask

Class to implement monitoring at fix delay

Field Summary

Modifier and TypeField and Description
pack-priv final AtomicLong
checkInterval

Delay between two captures

private final AtomicLong
cumulativeReadBytes

Long life read bytes

private final AtomicLong
cumulativeWrittenBytes

Long life written bytes

private final AtomicLong
currentReadBytes

Current read bytes

private final AtomicLong
currentWrittenBytes

Current written bytes

pack-priv final 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 volatile long
lastReadBytes

Last read bytes number during last check interval

private volatile long
lastReadingTime

Last reading time during last check interval

private long
lastReadThroughput

Last reading bandwidth

pack-priv final AtomicLong
lastTime

Last Time Check taken

private long
lastWriteThroughput

Last writing bandwidth

private volatile long
lastWritingTime

Last future writing time during last check interval

private volatile long
lastWrittenBytes

Last written bytes number during last check interval

private static final InternalLogger
pack-priv Runnable
monitor

Monitor created once in start()

pack-priv volatile boolean
monitorActive

Is Monitor active

pack-priv final String
name

Name of this Monitor

private long
readingTime

Last reading delay during current check interval

private long
realWriteThroughput

Real writing bandwidth

private final AtomicLong
realWrittenBytes

Real written bytes

pack-priv volatile ScheduledFuture<?>
scheduledFuture

used in stop() to cancel the timer

pack-priv final AbstractTrafficShapingHandler
trafficShapingHandler

The associated TrafficShapingHandler

private long
writingTime

Last writing time during current check interval

Constructor Summary

AccessConstructor and Description
public
TrafficCounter(ScheduledExecutorService
the underlying executor service for scheduling checks, might be null when used from GlobalChannelTrafficCounter.
executor
,
String
the name given to this monitor.
name
,
long
the checkInterval in millisecond between two computations.
checkInterval
)

Constructor with the AbstractTrafficShapingHandler that hosts it, the ScheduledExecutorService to use, its name, the checkInterval between two computations in milliseconds.

public
TrafficCounter(AbstractTrafficShapingHandler
the associated AbstractTrafficShapingHandler.
trafficShapingHandler
,
ScheduledExecutorService
the underlying executor service for scheduling checks, might be null when used from GlobalChannelTrafficCounter.
executor
,
String
the name given to this monitor.
name
,
long
the checkInterval in millisecond between two computations.
checkInterval
)

Constructor with the AbstractTrafficShapingHandler that hosts it, the Timer to use, its name, the checkInterval between two computations in millisecond.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
bytesRealWriteFlowControl(long
the size in bytes to write
write
)

Computes counters for Real Write.

pack-priv void
bytesRecvFlowControl(long
the size in bytes to read
recv
)

Computes counters for Read.

pack-priv void
bytesWriteFlowControl(long
the size in bytes to write
write
)

Computes counters for Write.

public long

Returns:

the current checkInterval between two computations of traffic counter in millisecond.
checkInterval
()

public void
configure(long
The new check interval (in milliseconds)
newCheckInterval
)

Change checkInterval between two computations in millisecond.

public long

Returns:

the cumulativeReadBytes
cumulativeReadBytes
()

public long

Returns:

the cumulativeWrittenBytes
cumulativeWrittenBytes
()

public long

Returns:

the current number of bytes read since the last checkInterval.
currentReadBytes
()

public long

Returns:

the current number of bytes written since the last check Interval.
currentWrittenBytes
()

public long

Returns:

the realWriteThroughput
getRealWriteThroughput
()

public AtomicLong

Returns:

the realWrittenBytes
getRealWrittenBytes
()

private void
init(long checkInterval)

public long

Returns:

the lastCumulativeTime in millisecond as of System.currentTimeMillis() when the cumulative counters were reset to 0.
lastCumulativeTime
()

public long

Returns:

the number of bytes read during the last check Interval.
lastReadBytes
()

public long

Returns:

the Read Throughput in bytes/s computes in the last check interval.
lastReadThroughput
()

public long

Returns:

the Time in millisecond of the last check as of System.currentTimeMillis().
lastTime
()

public long

Returns:

the Write Throughput in bytes/s computes in the last check interval.
lastWriteThroughput
()

public long

Returns:

the number of bytes written during the last check Interval.
lastWrittenBytes
()

public static long

Returns:

the time in ms using nanoTime, so not real EPOCH time but elapsed time in ms.
milliSecondFromNano
()

public String

Returns:

the name of this TrafficCounter.
name
()

public long

Returns:

the current time to wait (in ms) if needed for Read operation.
readTimeToWait
(final long
the recv size
size
,
final long
the traffic limit in bytes per second.
limitTraffic
,
final long
the max time in ms to wait in case of excess of traffic.
maxTime
)

Deprecated
Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.
public long

Returns:

the current time to wait (in ms) if needed for Read operation.
readTimeToWait
(final long
the recv size
size
,
final long
the traffic limit in bytes per second
limitTraffic
,
final long
the max time in ms to wait in case of excess of traffic.
maxTime
,
final long
the current time
now
)

Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.

pack-priv synchronized void
resetAccounting(long
the milliseconds unix timestamp that we should be considered up-to-date for.
newLastTime
)

Reset the accounting on Read and Write.

public void
resetCumulativeTime()

Reset both read and written cumulative bytes counters and the associated absolute time from System.currentTimeMillis().

public synchronized void
start()

Start the monitoring process.

public synchronized void
stop()

Stop the monitoring process.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public long

Returns:

the current time to wait (in ms) if needed for Write operation.
writeTimeToWait
(final long
the write size
size
,
final long
the traffic limit in bytes per second.
limitTraffic
,
final long
the max time in ms to wait in case of excess of traffic.
maxTime
)

Deprecated
Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.
public long

Returns:

the current time to wait (in ms) if needed for Write operation.
writeTimeToWait
(final long
the write size
size
,
final long
the traffic limit in bytes per second.
limitTraffic
,
final long
the max time in ms to wait in case of excess of traffic.
maxTime
,
final long
the current time
now
)

Returns the time to wait (if any) for the given length message, using the given limitTraffic and the max wait time.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

checkIntervalback to summary
pack-priv final AtomicLong checkInterval

Delay between two captures

cumulativeReadBytesback to summary
private final AtomicLong cumulativeReadBytes

Long life read bytes

cumulativeWrittenBytesback to summary
private final AtomicLong cumulativeWrittenBytes

Long life written bytes

currentReadBytesback to summary
private final AtomicLong currentReadBytes

Current read bytes

currentWrittenBytesback to summary
private final AtomicLong currentWrittenBytes

Current written bytes

executorback to summary
pack-priv final ScheduledExecutorService executor

Executor that will run the monitor

lastCumulativeTimeback to summary
private long lastCumulativeTime

Last Time where cumulative bytes where reset to zero: this time is a real EPOC time (informative only)

lastReadBytesback to summary
private volatile long lastReadBytes

Last read bytes number during last check interval

lastReadingTimeback to summary
private volatile long lastReadingTime

Last reading time during last check interval

lastReadThroughputback to summary
private long lastReadThroughput

Last reading bandwidth

lastTimeback to summary
pack-priv final AtomicLong lastTime

Last Time Check taken

lastWriteThroughputback to summary
private long lastWriteThroughput

Last writing bandwidth

lastWritingTimeback to summary
private volatile long lastWritingTime

Last future writing time during last check interval

lastWrittenBytesback to summary
private volatile long lastWrittenBytes

Last written bytes number during last check interval

loggerback to summary
private static final InternalLogger logger
monitorback to summary
pack-priv Runnable monitor

Monitor created once in start()

monitorActiveback to summary
pack-priv volatile boolean monitorActive

Is Monitor active

nameback to summary
pack-priv final String name

Name of this Monitor

readingTimeback to summary
private long readingTime

Last reading delay during current check interval

realWriteThroughputback to summary
private long realWriteThroughput

Real writing bandwidth

realWrittenBytesback to summary
private final AtomicLong realWrittenBytes

Real written bytes

scheduledFutureback to summary
pack-priv volatile ScheduledFuture<?> scheduledFuture

used in stop() to cancel the timer

trafficShapingHandlerback to summary
pack-priv final AbstractTrafficShapingHandler trafficShapingHandler

The associated TrafficShapingHandler

writingTimeback to summary
private long writingTime

Last writing time during current check interval

Constructor Detail

TrafficCounterback to summary
public TrafficCounter(ScheduledExecutorService executor, String name, long checkInterval)

Constructor with the AbstractTrafficShapingHandler that hosts it, the ScheduledExecutorService to use, its name, the checkInterval between two computations in milliseconds.

Parameters
executor:ScheduledExecutorService

the underlying executor service for scheduling checks, might be null when used from GlobalChannelTrafficCounter.

name:String

the name given to this monitor.

checkInterval:long

the checkInterval in millisecond between two computations.

TrafficCounterback to summary
public TrafficCounter(AbstractTrafficShapingHandler trafficShapingHandler, ScheduledExecutorService executor, 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:AbstractTrafficShapingHandler

the associated AbstractTrafficShapingHandler.

executor:ScheduledExecutorService

the underlying executor service for scheduling checks, might be null when used from GlobalChannelTrafficCounter.

name:String

the name given to this monitor.

checkInterval:long

the checkInterval in millisecond between two computations.

Method Detail

bytesRealWriteFlowControlback to summary
pack-priv void bytesRealWriteFlowControl(long write)

Computes counters for Real Write.

Parameters
write:long

the size in bytes to write

bytesRecvFlowControlback to summary
pack-priv void bytesRecvFlowControl(long recv)

Computes counters for Read.

Parameters
recv:long

the size in bytes to read

bytesWriteFlowControlback to summary
pack-priv void bytesWriteFlowControl(long write)

Computes counters for Write.

Parameters
write:long

the size in bytes to write

checkIntervalback to summary
public long checkInterval()
Returns:long

the current checkInterval between two computations of traffic counter in millisecond.

configureback to summary
public void configure(long newCheckInterval)

Change checkInterval between two computations in millisecond.

Parameters
newCheckInterval:long

The new check interval (in milliseconds)

cumulativeReadBytesback to summary
public long cumulativeReadBytes()
Returns:long

the cumulativeReadBytes

cumulativeWrittenBytesback to summary
public long cumulativeWrittenBytes()
Returns:long

the cumulativeWrittenBytes

currentReadBytesback to summary
public long currentReadBytes()
Returns:long

the current number of bytes read since the last checkInterval.

currentWrittenBytesback to summary
public long currentWrittenBytes()
Returns:long

the current number of bytes written since the last check Interval.

getRealWriteThroughputback to summary
public long getRealWriteThroughput()
Returns:long

the realWriteThroughput

getRealWrittenBytesback to summary
public AtomicLong getRealWrittenBytes()
Returns:AtomicLong

the realWrittenBytes

initback to summary
private void init(long checkInterval)
lastCumulativeTimeback to summary
public long lastCumulativeTime()
Returns:long

the lastCumulativeTime in millisecond as of System.currentTimeMillis() when the cumulative counters were reset to 0.

lastReadBytesback to summary
public long lastReadBytes()
Returns:long

the number of bytes read during the last check Interval.

lastReadThroughputback to summary
public long lastReadThroughput()
Returns:long

the Read Throughput in bytes/s computes in the last check interval.

lastTimeback to summary
public long lastTime()
Returns:long

the Time in millisecond of the last check as of System.currentTimeMillis().

lastWriteThroughputback to summary
public long lastWriteThroughput()
Returns:long

the Write Throughput in bytes/s computes in the last check interval.

lastWrittenBytesback to summary
public long lastWrittenBytes()
Returns:long

the number of bytes written during the last check Interval.

milliSecondFromNanoback to summary
public static long milliSecondFromNano()
Returns:long

the time in ms using nanoTime, so not real EPOCH time but elapsed time in ms.

nameback to summary
public String name()
Returns:String

the name of this TrafficCounter.

readTimeToWaitback to summary
public long readTimeToWait(final long size, final long limitTraffic, final 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:long

the recv size

limitTraffic:long

the traffic limit in bytes per second.

maxTime:long

the max time in ms to wait in case of excess of traffic.

Returns:long

the current time to wait (in ms) if needed for Read operation.

Annotations
@Deprecated
readTimeToWaitback to summary
public long readTimeToWait(final long size, final long limitTraffic, final long maxTime, final 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:long

the recv size

limitTraffic:long

the traffic limit in bytes per second

maxTime:long

the max time in ms to wait in case of excess of traffic.

now:long

the current time

Returns:long

the current time to wait (in ms) if needed for Read operation.

resetAccountingback to summary
pack-priv synchronized void resetAccounting(long newLastTime)

Reset the accounting on Read and Write.

Parameters
newLastTime:long

the milliseconds unix timestamp that we should be considered up-to-date for.

resetCumulativeTimeback to summary
public void resetCumulativeTime()

Reset both read and written cumulative bytes counters and the associated absolute time from System.currentTimeMillis().

startback to summary
public synchronized void start()

Start the monitoring process.

stopback to summary
public synchronized void stop()

Stop the monitoring process.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
writeTimeToWaitback to summary
public long writeTimeToWait(final long size, final long limitTraffic, final 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:long

the write size

limitTraffic:long

the traffic limit in bytes per second.

maxTime:long

the max time in ms to wait in case of excess of traffic.

Returns:long

the current time to wait (in ms) if needed for Write operation.

Annotations
@Deprecated
writeTimeToWaitback to summary
public long writeTimeToWait(final long size, final long limitTraffic, final long maxTime, final 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:long

the write size

limitTraffic:long

the traffic limit in bytes per second.

maxTime:long

the max time in ms to wait in case of excess of traffic.

now:long

the current time

Returns:long

the current time to wait (in ms) if needed for Write operation.

io.netty.handler.traffic back to summary

private final Class TrafficCounter.TrafficMonitoringTask

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • io.netty.handler.traffic.TrafficCounter.TrafficMonitoringTask
All Implemented Interfaces
java.lang.Runnable

Class to implement monitoring at fix delay

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

TrafficMonitoringTaskback to summary
private TrafficMonitoringTask()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override