org.apache.qpid.junit.extensions
Class BaseThrottle

java.lang.Object
  extended by org.apache.qpid.junit.extensions.BaseThrottle
All Implemented Interfaces:
Throttle
Direct Known Subclasses:
BatchedThrottle, SleepThrottle

public abstract class BaseThrottle
extends Object
implements Throttle

Provides a base implementation of the non-waiting throttle checking method, using the system nano timer.

CRC Card
Responsibilities Collaborations
Check against a throttle speed without waiting.


Field Summary
protected  long cycleTimeNanos
          Holds the length of a single cycle in nano seconds.
(package private)  boolean firstCall
          Flag used to detect the first call to the Throttle.throttle() method.
(package private)  boolean firstCheckCall
          Flag used to detect the first call to the checkThrottle() method.
 
Constructor Summary
BaseThrottle()
           
 
Method Summary
 boolean checkThrottle()
          Checks but does not enforce the throttle rate.
 void setRate(float hertz)
          Specifies the throttling rate in operations per second.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.qpid.junit.extensions.Throttle
throttle
 

Field Detail

cycleTimeNanos

protected long cycleTimeNanos
Holds the length of a single cycle in nano seconds.


firstCheckCall

boolean firstCheckCall
Flag used to detect the first call to the checkThrottle() method.


firstCall

boolean firstCall
Flag used to detect the first call to the Throttle.throttle() method. Zero or negative start time cannot be relied on to detect this as System.nanoTime can return zero or negative values.

Constructor Detail

BaseThrottle

public BaseThrottle()
Method Detail

setRate

public void setRate(float hertz)
Specifies the throttling rate in operations per second. This must be called with with a value, the inverse of which is a measurement in nano seconds, such that the number of nano seconds do not overflow a long integer. The value must also be larger than zero.

Specified by:
setRate in interface Throttle
Parameters:
hertz - The throttling rate in cycles per second.

checkThrottle

public boolean checkThrottle()
Checks but does not enforce the throttle rate. When this method is called, it checks if a length of time greater than that equal to the inverse of the throttling rate has passed since it was last called and returned true

Specified by:
checkThrottle in interface Throttle
Returns:
true if a length of time greater than that equal to the inverse of the throttling rate has passed since this method was last called and returned true, false otherwise. The very first time this method is called on a throttle, it returns true as the base case to the above self-referential definition.


Licensed to the Apache Software Foundation