public interface ClusteredLock
lock()
will be :
ClusteredLock lock = clm.get("lock");
lock.lock()
.thenRun(() ->
try {
// manipulate protected state
} finally {
return lock.unlock();
}
)
A typical usage idiom for tryLock()
will be :
lock.tryLock()
.thenCompose(result -> {
if (result) {
try {
// manipulate protected state
} finally {
return lock.unlock();
}
} else {
// Do something else
}
});
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Boolean> |
isLocked()
Returns a
CompletableFuture holding true when the lock is locked and false when the lock is released. |
CompletableFuture<Boolean> |
isLockedByMe()
Returns a
CompletableFuture holding true when the lock is owned by the caller and
false when the lock is owned by someone else or it's released. |
CompletableFuture<Void> |
lock()
Acquires the lock.
|
CompletableFuture<Boolean> |
tryLock()
Acquires the lock only if it is free at the time of invocation.
|
CompletableFuture<Boolean> |
tryLock(long time,
TimeUnit unit)
If the lock is available this method returns immediately with the
CompletableFuture holding the value true . |
CompletableFuture<Void> |
unlock()
Releases the lock.
|
CompletableFuture<Void> lock()
CompletableFuture
waits until the lock has been acquired.
Currently, there is no maximum time specified for a lock request to fail, so this could cause thread starvation.CompletableFuture
when the lock is acquiredClusteredLockException
- when the lock does not existCompletableFuture<Boolean> tryLock()
CompletableFuture
holding the value true
.
If the lock is not available then this method will return immediately with the CompletableFuture
holding the value false
.CompletableFuture(true)
if the lock was acquired and CompletableFuture(false)
otherwiseClusteredLockException
- when the lock does not existCompletableFuture<Boolean> tryLock(long time, TimeUnit unit)
CompletableFuture
holding the value true
.
If the lock is not available then the CompletableFuture
waits until :
CompletableFuture
will complete with the value true
.
If the specified waiting time elapses then the CompletableFuture
will complete with the value false
.
If the time is less than or equal to zero, the method will not wait at all.time,
- the maximum time to wait for the lockunit,
- the time unit of the time
argumentCompletableFuture(true)
if the lock was acquired and CompletableFuture(false)
if the waiting time elapsed before the lock was acquiredClusteredLockException
- when the lock does not existCompletableFuture<Void> unlock()
CompletableFuture
when the lock is releasedClusteredLockException
- when the lock does not existCompletableFuture<Boolean> isLocked()
CompletableFuture
holding true
when the lock is locked and false
when the lock is released.CompletableFuture
holding a Boolean
ClusteredLockException
- when the lock does not existCompletableFuture<Boolean> isLockedByMe()
CompletableFuture
holding true
when the lock is owned by the caller and
false
when the lock is owned by someone else or it's released.CompletableFuture
holding a Boolean
ClusteredLockException
- when the lock does not existCopyright © 2021 JBoss by Red Hat. All rights reserved.