|
OpenNMS API 1.2.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opennms.core.concurrent.QuantumSemaphore
QuantumSemaphore class is similar to a semaphore, but slightly different. The class provides for a way to acquire a resource, but not to release one. The idea is that the value of the semaphore is reset each quantum to it's maximum value.
Implementation: A Java implementation of Brian's C++ class
Field Summary | |
private long |
m_lastReset
The number of TimeTicks when the semaphore was last reset. |
private long |
m_lCurValue
The current value of the semaphore. |
private long |
m_lMaxValue
The actual value that the semaphore is reset to after each elasped quantum. |
private long |
m_lQuantum
The reset quantum in milliseconds. |
Constructor Summary | |
private |
QuantumSemaphore()
The default constructor for the object always throws an UnsupportedOperationException. |
|
QuantumSemaphore(long maxValue,
long quantum)
Constructs a new QuantumSempahore object with the specified maximum value and time quantum. |
Method Summary | |
boolean |
acquire()
Returns a true value if the semaphore is successfully acquired by the application. |
long |
getMaxValue()
Returns the maximum value of the QuantumSemaphore. |
private void |
reset()
Resets the value of the semaphore. |
private long |
timeSinceReset()
Returns the number of milliseconds since the last reset of the object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private final long m_lQuantum
The reset quantum in milliseconds.
private final long m_lMaxValue
The actual value that the semaphore is reset to after each elasped quantum.
private long m_lCurValue
The current value of the semaphore.
private long m_lastReset
The number of TimeTicks when the semaphore was last reset. If the difference between the current time and this value exceed the time quantium then the semaphore should be reset.
Constructor Detail |
private QuantumSemaphore() throws java.lang.UnsupportedOperationException
The default constructor for the object always throws an UnsupportedOperationException. This is done since the maximum value and time quantium must be set in the constructor. Use of the default constructor would create an object that is non-functional, thus it's creation is denied.
java.lang.UnsupportedOperationException
- Always Thrown.public QuantumSemaphore(long maxValue, long quantum)
Constructs a new QuantumSempahore object with the specified maximum value and time quantum. The object's values cannot be change once the object is created.
maxValue
- The maximum value of the semaphorequantum
- The time quantum between resets, in milliseconds.Method Detail |
private long timeSinceReset()
Returns the number of milliseconds since the last reset of the object.
private void reset()
Resets the value of the semaphore.
public boolean acquire() throws java.lang.InterruptedException
Returns a true value if the semaphore is successfully acquired by the application. A false value is returned if the acquisition does not work.
java.lang.InterruptedException
public long getMaxValue()
Returns the maximum value of the QuantumSemaphore.
|
OpenNMS API 1.2.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |