| Constructor and Description |
|---|
ReactiveRWLock() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isLocked()
Checks whether this lock is locked (or has reached the max lock holders)
|
boolean |
isRLocked()
Checks whether this lock is reader-locked (or has reached the max lock holders)
|
Mono<Void> |
lock()
Get a
Mono that emits success only after acquiring the lock |
<T> Mono<T> |
lockOnNext(Mono<T> mono)
Try to acquire the lock on the next element before propagating
|
Mono<Void> |
rLock()
See
AbstractLock.lock() for details. |
<T> Mono<T> |
rLockOnNext(Mono<T> mono)
Tries to acquire the reader lock on the next element before propagating
|
void |
rUnlock()
See
Lock.unlock() for details. |
<T> Mono<T> |
rUnlockOnEmpty(Mono<T> mono)
See
AbstractLock.unlockOnEmpty(Mono) for details. |
<T> Mono<T> |
rUnlockOnError(Mono<T> mono)
See
AbstractLock.unlockOnError(Mono) for details. |
<T> Mono<T> |
rUnlockOnNext(Mono<T> mono)
See
AbstractLock.unlockOnNext(Mono) for details. |
<T> Mono<T> |
rUnlockOnTerminate(Mono<T> mono)
See
AbstractLock.unlockOnTerminate(Mono) for details. |
LockHandle |
tryLock()
Immediately requests to hold the lock.
|
Mono<Void> |
tryLock(Duration duration)
Tries to acquire the lock, or stop and propagate a
TimeoutException downstream after
certain duration. |
LockHandle |
tryRLock()
The reader lock equivalent to
Lock.tryLock() |
Mono<Void> |
tryRLock(Duration duration)
Tries to acquire the reader-lock, or stop and propagate a
TimeoutException
downstream after certain duration. |
void |
unlock()
Unlocks
|
<T> Mono<T> |
unlockOnEmpty(Mono<T> mono)
Release the lock with
Mono.switchIfEmpty(Mono) |
<T> Mono<T> |
unlockOnError(Mono<T> mono)
Release the lock with
Mono.doOnError(Consumer) before propagating |
<T> Mono<T> |
unlockOnNext(Mono<T> mono)
Release the lock with
Mono.doOnNext(Consumer) before propagating |
<T> Mono<T> |
unlockOnTerminate(Mono<T> mono)
Release the lock with
Mono.doOnTerminate(Runnable) before propagating |
<T> Flux<T> |
withLock(Supplier<Publisher<T>> scoped)
Automatically acquires the lock, executes the function and unlocks.
|
<T> Flux<T> |
withRLock(Supplier<Publisher<T>> scoped)
The reader lock version of
Lock.withLock(Supplier). |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbegin, lock, lockOnNext, tryLock, unlockOnEmpty, unlockOnError, unlockOnNext, unlockOnTerminate, withLockpublic LockHandle tryLock()
Lock
See LockHandle. Subscribe to LockHandle.mono() to get informed
when the lock becomes available.
To properly unlock, you are suggested to handle all cases including completing
without error, failing with errors or the whole Mono or Flux getting
cancelled. You might want to use Lock.withLock(Supplier) to save yourself from
the boilerplate, which internally uses Flux.using(Callable, Function, Consumer)
to LockHandle.cancel() or Lock.unlock() accordingly.
public LockHandle tryRLock()
RWLockLock.tryLock()
See LockHandle and Lock.tryLock()
public void unlock()
LockUsage:
Lock lock = new ReactiveLock(); /* Or other locks */
mono
.transform(lock::lockOnNext)
.flatMap(item -> {
/* Some processing */
lock.unlock();
return Mono.just(item);
})
.block();
public void rUnlock()
RWLockLock.unlock() for details.public boolean isLocked()
LockYou should not rely on the result of this due to possible concurrent operations.
public boolean isRLocked()
RWLockYou should not rely on the result of this due to possible concurrent operations.
public Mono<Void> tryRLock(Duration duration)
RWLockTimeoutException
downstream after certain duration.public <T> Flux<T> withRLock(Supplier<Publisher<T>> scoped)
RWLockLock.withLock(Supplier).public Mono<Void> rLock()
RWLockAbstractLock.lock() for details.public <T> Mono<T> rLockOnNext(Mono<T> mono)
RWLockrLockOnNext in interface RWLockT - the generic type of Monomono - the Mono, of which the next value will require locking to propagateMonopublic <T> Mono<T> rUnlockOnEmpty(Mono<T> mono)
RWLockAbstractLock.unlockOnEmpty(Mono) for details.rUnlockOnEmpty in interface RWLockT - the generic type of Monomono - the Mono, of which the next signal, when Mono is empty, will require unlocking to propagateMonopublic <T> Mono<T> rUnlockOnNext(Mono<T> mono)
RWLockAbstractLock.unlockOnNext(Mono) for details.rUnlockOnNext in interface RWLockT - the generic type of Monomono - the Mono, of which the next value will require unlocking to propagateMonopublic <T> Mono<T> rUnlockOnTerminate(Mono<T> mono)
RWLockAbstractLock.unlockOnTerminate(Mono) for details.rUnlockOnTerminate in interface RWLockT - the generic type of Monomono - the Mono, of which the termination signal will require unlocking to propagateMonopublic <T> Mono<T> rUnlockOnError(Mono<T> mono)
RWLockAbstractLock.unlockOnError(Mono) for details.rUnlockOnError in interface RWLockT - the generic type of Monomono - the Mono, of which the next error will require unlocking to propagateMonopublic Mono<Void> tryLock(Duration duration)
LockTimeoutException downstream after
certain duration.public Mono<Void> lock()
LockMono that emits success only after acquiring the lockpublic <T> Flux<T> withLock(Supplier<Publisher<T>> scoped)
Lock
It handles all cases including when the Flux completes without error (empty or not),
fails with errors, or gets cancelled middle way.
public <T> Mono<T> lockOnNext(Mono<T> mono)
LocklockOnNext in interface LockT - the generic type of Monomono - the Mono, of which the next value will require locking to propagateMonopublic <T> Mono<T> unlockOnTerminate(Mono<T> mono)
LockMono.doOnTerminate(Runnable) before propagatingunlockOnTerminate in interface LockT - the generic type of Monomono - the Mono, of which the termination signal will require unlocking to propagateMonopublic <T> Mono<T> unlockOnNext(Mono<T> mono)
LockMono.doOnNext(Consumer) before propagatingunlockOnNext in interface LockT - the generic type of Monomono - the Mono, of which the next value will require unlocking to propagateMonopublic <T> Mono<T> unlockOnEmpty(Mono<T> mono)
LockMono.switchIfEmpty(Mono)unlockOnEmpty in interface LockT - the generic type of Monomono - the Mono, of which the signal, when Mono is empty, will require unlocking to propagateMonopublic <T> Mono<T> unlockOnError(Mono<T> mono)
LockMono.doOnError(Consumer) before propagatingunlockOnError in interface LockT - the generic type of Monomono - the Mono, of which the next error will require unlocking to propagateMono