A {@code Semaphore} is a mechanism for allowing a limited number of parties to proceed at any given point in time.To facilitate this, conceptually, a Semaphore maintains a limited number of permits, which it grants to each party which calls {@link #acquire()} in sequence. Once a permit has been granted to a party, that party may proceed withits action, and when that action has finished, the party must return its permit via a call to {@link #release()}before another party may be granted that permit.
If no permits are available when a party makes its request, then it is either turned away (if the party calls {@link #tryAcquire()}) or made to wait via blocking (if the party calls {@link #acquire()}).
This implementation is conceptually similar to that of {@link java.util.concurrent.Semaphore}, but is distributed and fault-tolerant. If a party acquires a permit, and then subsequently fails, that permit is released back to the Semaphore, allowing another party to proceed.
Note that, due to the distributed nature of this semaphore, there are no guarantees that all semaphores in a cluster are required to see the same number of available permits. This makes it possible for a semaphore on Node A to allow, say, three parties access while the same semaphore on Node B allows 5 parties access. Instead, maintaining consistency as to the number of parties which are allowed through each semaphore is the responsibility of the calling code. @author Scott Fines @version 1.1 @see java.util.concurrent.Semaphore
|
|
|
|
|
|