T
- the type of named objects used to identify locksFairAsyncNamedLock
public interface AsyncNamedLock<T>
object equality
.
Implementations will specify whether their lock acquisition is fair or not; this interface does not define this requirement.
Note that implementations will generally employ an underlying Map
; as such, the
same precautions must be taken regarding mutability of keys (names). Name objects should not
change from the time of acquisition to the time of release, with respect to their
equality
and hash code
semantics. The
release methods of the returned AsyncLock.LockToken
may throw a
ConcurrentModificationException
if such a modification is detected.
Modifier and Type | Method | Description |
---|---|---|
CompletionStage<AsyncLock.LockToken> |
acquireLock(T name) |
Acquires the lock associated with the given name.
|
static <T> AsyncNamedLock<T> |
create() |
Creates an
AsyncNamedLock |
static <T> AsyncNamedLock<T> |
createFair() |
Creates a fair
AsyncNamedLock |
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. |
CompletionStage<AsyncLock.LockToken> acquireLock(T name)
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.
name
- to acquire exclusive access forCompletionStage
which will complete with a AsyncLock.LockToken
when
the lock associated with name
has been exclusively acquiredOptional<AsyncLock.LockToken> tryLock(T name)
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.
name
- to acquire exclusive access forOptional
holding a AsyncLock.LockToken
if the lock associated with
name
is not held; otherwise an empty Optionalstatic <T> AsyncNamedLock<T> create()
AsyncNamedLock
The returned lock is only guaranteed to meet the requirements of AsyncNamedLock
; in
particular, no guarantee of fairness is provided.
AsyncNamedLock
static <T> AsyncNamedLock<T> createFair()
AsyncNamedLock
AsyncNamedLock
with a fair implementationCopyright © 2018. All rights reserved.