public interface Lock
| Modifier and Type | Method and Description |
|---|---|
static <T> LockedMono.LockedMonoBuilder<T> |
begin(Mono<T> mono)
Transforming a
Mono into LockedMono.LockedMonoBuilder for uses with its fluent API |
boolean |
isLocked()
Checks whether this lock is locked (or has reached the max lock holders)
|
Mono<Void> |
lock()
Deprecated.
Use
withLock(Supplier) to handle cancelling signals
Usage:
The underlying implementation should automatically queue the
Do not use |
<T> Mono<T> |
lockOnNext(Mono<T> mono)
Deprecated.
Use
withLock(Supplier) to handle cancelling signals
Usage:
The underlying implementation should automatically queue the When the lock becomes available, the value will be automatically propagated downstream. |
LockHandle |
tryLock()
Immediately requests to hold the lock.
|
Mono<Void> |
tryLock(Duration duration)
Deprecated.
Use
withLock(Supplier) to handle cancelling signals |
void |
unlock()
Unlocks
|
<T> Mono<T> |
unlockOnEmpty(Mono<T> mono)
Deprecated.
Use
withLock(Supplier) to handle cancelling signals
Usage:
Using |
<T> Mono<T> |
unlockOnError(Mono<T> mono)
Deprecated.
Use
withLock(Supplier) to handle cancelling signals
Usage:
Using |
<T> Mono<T> |
unlockOnNext(Mono<T> mono)
Deprecated.
Use
withLock(Supplier) to handle cancelling signals
Usage:
Using |
<T> Mono<T> |
unlockOnTerminate(Mono<T> mono)
Deprecated.
Use
withLock(Supplier) to handle cancelling signals
Usage:
Using |
<T> Flux<T> |
withLock(Supplier<Publisher<T>> scoped)
Automatically acquires the lock, executes the function and unlocks.
|
static <T> LockedMono.LockedMonoBuilder<T> begin(Mono<T> mono)
Mono into LockedMono.LockedMonoBuilder for uses with its fluent APIT - the input mono data typemono - the Mono to get transformedLockedMono.LockedMonoBuilderLockHandle tryLock()
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 withLock(Supplier) to save yourself from
the boilerplate, which internally uses Flux.using(Callable, Function, Consumer)
to LockHandle.cancel() or unlock() accordingly.
@Deprecated Mono<Void> tryLock(Duration duration)
withLock(Supplier) to handle cancelling signalsTimeoutException downstream after
certain duration.duration - the time to wait for lockMono that emits success when the lock is acquired@Deprecated Mono<Void> lock()
withLock(Supplier) to handle cancelling signals
Usage:
Lock lock = new ReactiveLock(); /* Or other locks */
mono
.flatMap(t -> lock.lock().thenReturn(t))
/* Some processing */
.transform(lock::unlockOnNext)
.block();
The underlying implementation should automatically queue the Mono up
if the lock is not available.
Do not use Mono.timeout(Duration) or Mono.timeout(Publisher),
which are not handled at all. Use tryLock(Duration) or tryLock() instead
if you want timeouts.
Mono that emits success only after acquiring the lockMono that emits success when the lock is acquired<T> Flux<T> withLock(Supplier<Publisher<T>> scoped)
It handles all cases including when the Flux completes without error (empty or not),
fails with errors, or gets cancelled middle way.
boolean isLocked()
You should not rely on the result of this due to possible concurrent operations.
@Deprecated <T> Mono<T> lockOnNext(Mono<T> mono)
withLock(Supplier) to handle cancelling signals
Usage:
Lock lock = new ReactiveLock(); /* Or other locks */
mono
.transform(lock::lockOnNext)
/* Some processing */
.transform(lock::unlockOnNext)
.block();
The underlying implementation should automatically queue the Mono up
if the lock is not available.
When the lock becomes available, the value will be automatically propagated downstream.
void unlock()
Usage:
Lock lock = new ReactiveLock(); /* Or other locks */
mono
.transform(lock::lockOnNext)
.flatMap(item -> {
/* Some processing */
lock.unlock();
return Mono.just(item);
})
.block();
@Deprecated <T> Mono<T> unlockOnTerminate(Mono<T> mono)
withLock(Supplier) to handle cancelling signals
Usage:
Lock lock = new ReactiveLock(); /* Or other locks */
mono
.transform(lock::lockOnNext)
/* Some processing */
.transform(lock::unlockOnTerminate)
.block();
Using Mono.doOnTerminate(Runnable) to ensure the execution order and handling of
all cases, including an empty Mono, a successful Mono with a
emitted value or Monos with an error.
Mono.doOnTerminate(Runnable) before propagating@Deprecated <T> Mono<T> unlockOnNext(Mono<T> mono)
withLock(Supplier) to handle cancelling signals
Usage:
Lock lock = new ReactiveLock(); /* Or other locks */
mono
.transform(lock::lockOnNext)
/* Some processing */
.transform(lock::unlockOnNext)
.block();
Using Mono.doOnNext(Consumer) to ensure the execution order and handling of
a successful Mono with a emitted value.
Mono.doOnNext(Consumer) before propagating@Deprecated <T> Mono<T> unlockOnEmpty(Mono<T> mono)
withLock(Supplier) to handle cancelling signals
Usage:
Lock lock = new ReactiveLock(); /* Or other locks */
mono
.transform(lock::lockOnNext)
/* Some processing */
.transform(lock::unlockOnEmpty)
.block();
Using Mono.switchIfEmpty(Mono) to ensure the execution order and handling of
an empty Mono.
Mono.switchIfEmpty(Mono)@Deprecated <T> Mono<T> unlockOnError(Mono<T> mono)
withLock(Supplier) to handle cancelling signals
Usage:
Lock lock = new ReactiveLock(); /* Or other locks */
mono
.transform(lock::lockOnNext)
/* Some processing */
.transform(lock::unlockOnError)
.block();
Using Mono.doOnError(Consumer) to ensure the execution order and handling of
Monos with an error.
Mono.doOnError(Consumer) before propagating