AsyncNamedLock<T>
public class FairAsyncNamedLock<T> extends Object implements AsyncNamedLock<T>
AsyncNamedLock
interface which enforces fair ordering in lock
acquisition.
null
values are not permitted for use as names.
Constructor | Description |
---|---|
FairAsyncNamedLock() |
Modifier and Type | Method | Description |
---|---|---|
CompletionStage<AsyncLock.LockToken> |
acquireLock(T name) |
Acquires the lock associated with the given name.
|
Optional<AsyncLock.LockToken> |
tryLock(T name) |
Attempts to immediately acquire the lock associated with the given name, returning a populated
Optional if the lock is not currently held. |
create, createFair
public CompletionStage<AsyncLock.LockToken> acquireLock(T name)
AsyncNamedLock
The AsyncLock.LockToken
held by the returned stage is used to release the lock after it
has been acquired and the lock-protected action has completed.
acquireLock
in interface AsyncNamedLock<T>
name
- to acquire exclusive access forCompletionStage
which will complete with a AsyncLock.LockToken
when
the lock associated with name
has been exclusively acquiredpublic Optional<AsyncLock.LockToken> tryLock(T name)
AsyncNamedLock
Optional
if the lock is not currently held.
The AsyncLock.LockToken
held by the returned Optional is used to release the lock after
it has been acquired and the lock-protected action has completed.
tryLock
in interface AsyncNamedLock<T>
name
- to acquire exclusive access forOptional
holding a AsyncLock.LockToken
if the lock associated with
name
is not held; otherwise an empty OptionalCopyright © 2018. All rights reserved.