OpenNMS API 1.2.9

## org.opennms.core.concurrent
Class QuantumSemaphore

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

public final class QuantumSemaphore
extends java.lang.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.

Implementation: A Java implementation of Brian's C++ class

Author:
  Sowmya , OpenNMS

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

### m_lQuantum

    private final long m_lQuantum

  The reset quantum in milliseconds.

### m_lMaxValue

    private final long m_lMaxValue

  The actual value that the semaphore is reset to after each elasped quantum.

### m_lCurValue

    private long m_lCurValue

  The current value of the semaphore.

### m_lastReset

    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

### QuantumSemaphore

    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.

Throws:
  `java.lang.UnsupportedOperationException` - Always Thrown.

### 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

### timeSinceReset

    private long timeSinceReset()

  Returns the number of milliseconds since the last reset of the object.

### reset

    private void reset()

  Resets the value of the semaphore.

### acquire

    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.

  Returns:
    True if the semaphore is acquired, false otherwise.
  Throws:
    `java.lang.InterruptedException`

### getMaxValue

    public long getMaxValue()

  Returns the maximum value of the QuantumSemaphore.

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.