public class DefaultAsyncSemaphore extends Object implements AsyncSemaphore
| Constructor and Description |
|---|
DefaultAsyncSemaphore(long totalPermits,
boolean fair) |
| Modifier and Type | Method and Description |
|---|---|
Promise<T> |
acquire(long permits) |
long |
availablePermits() |
protected net.tascalate.concurrent.locks.DefaultAsyncSemaphore.SemaphorePromise |
createPromise(long permits) |
protected Long |
createPromisePayload(long permits) |
long |
drainPermits()
Acquires all permits that are immediately available.
|
int |
getQueueLength() |
void |
release(long permits)
Releases the given number of permits to the semaphore.
|
String |
toString() |
boolean |
tryAcquire(long permits)
Attempts to acquire the given number of permits from the semaphore, returning a boolean
indicating whether all of the permits were immediately available and have been exclusively
acquired.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitacquire, acquire, availablePermits, create, getQueueLength, release, tryAcquirepublic DefaultAsyncSemaphore(long totalPermits,
boolean fair)
public long drainPermits()
AsyncSemaphore
After this call -- provided there are no intermediate releases -- any
attempt to acquire will queue and any tryAcquire will fail.
drainPermits in interface AsyncSemaphorepublic boolean tryAcquire(long permits)
AsyncSemaphoreImplementations may define precise behavior of this method with respect to competing acquisitions, e.g. whether permits may be acquired while other acquisitions are waiting. This interface only requires that this method will succeed when the given permits are available and there are no other acquisitions queued.
tryAcquire in interface AsyncSemaphorepermits - A non-negative number of permits to acquire from the semaphorepublic void release(long permits)
AsyncSemaphoreIf there are unfulfilled acquires pending, this method will release permits to the waiting acquisitions based on the implementation's release and acquire policies. Consequently, this method may complete a number of waiting stages and execute the corresponding observers.
release in interface AsyncSemaphorepermits - A non-negative number of permits to release to the semaphoreprotected Long createPromisePayload(long permits)
protected net.tascalate.concurrent.locks.DefaultAsyncSemaphore.SemaphorePromise createPromise(long permits)
public long availablePermits()
public int getQueueLength()
public Promise<T> acquire(long permits)
Copyright © 2021. All rights reserved.