org.opennms.core.concurrent
Class QuantumSemaphore

java.lang.Object
  extended by org.opennms.core.concurrent.QuantumSemaphore

public final class QuantumSemaphore
extends Object

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.

Author:
Sowmya

Constructor Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuantumSemaphore

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.

Parameters:
maxValue - The maximum value of the semaphore
quantum - The time quantum between resets, in milliseconds.
Method Detail

acquire

public boolean acquire()
                throws 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.

Returns:
True if the semaphore is acquired, false otherwise.
Throws:
InterruptedException - if any.

getMaxValue

public long getMaxValue()

Returns the maximum value of the QuantumSemaphore.

Returns:
a long.


Copyright © 2011. All Rights Reserved.