O
- the type of the value that will be made availablepublic final class MonoProcessor<O> extends Mono<O> implements Processor<O,O>, CoreSubscriber<O>, Disposable, Subscription, Scannable, LongSupplier
MonoProcessor
is a Mono
extension that implements stateful semantics. Multi-subscribe is allowed.
Once a MonoProcessor
has been resolved, newer subscribers will benefit from the cached result.
Disposable.Composite, Disposable.Swap
Scannable.Attr<T>
Modifier and Type | Method and Description |
---|---|
O |
block()
Block the calling thread indefinitely, waiting for the completion of this
MonoProcessor . |
O |
block(Duration timeout)
Block the calling thread for the specified time, waiting for the completion of this
MonoProcessor . |
void |
cancel() |
static <T> MonoProcessor<T> |
create()
Create a
MonoProcessor that will eagerly request 1 on onSubscribe(Subscription) , cache and emit
the eventual result for 1 or N subscribers. |
static <T> MonoProcessor<T> |
create(WaitStrategy waitStrategy)
Create a
MonoProcessor that will eagerly request 1 on onSubscribe(Subscription) , cache and emit
the eventual result for 1 or N subscribers. |
Context |
currentContext()
Request a
Context from dependent components which can include downstream
operators during subscribing or a terminal Subscriber . |
void |
dispose()
Cancel or dispose the underlying task or resource.
|
long |
downstreamCount()
Return the number of active
Subscriber or -1 if untracked. |
long |
getAsLong()
Deprecated.
Should not use (to be removed in 3.2)
|
Throwable |
getError()
Return the produced
Throwable error if any or null |
boolean |
hasDownstreams()
Return true if any
Subscriber is actively subscribed |
Stream<? extends Scannable> |
inners()
Return a
Stream of referenced inners (flatmap, multicast etc) |
boolean |
isCancelled()
Indicates whether this
MonoProcessor has been interrupted via cancellation. |
boolean |
isDisposed()
Optionally return true when the resource or task is disposed.
|
boolean |
isError()
Indicates whether this
MonoProcessor has been completed with an error. |
boolean |
isSuccess()
Indicates whether this
MonoProcessor has been successfully completed a value. |
boolean |
isTerminated()
Indicates whether this
MonoProcessor has been terminated by the
source producer with a success or an error. |
void |
onComplete() |
void |
onError(Throwable cause) |
void |
onNext(O value) |
void |
onSubscribe(Subscription subscription)
Implementors should initialize any state used by
Subscriber.onNext(Object) before
calling Subscription.request(long) . |
O |
peek()
Returns the value that completed this
MonoProcessor . |
void |
request(long n) |
Object |
scanUnsafe(Scannable.Attr key)
This method is used internally by components to define their key-value mappings
in a single place.
|
void |
subscribe(CoreSubscriber<? super O> actual)
An internal
Publisher.subscribe(Subscriber) that will bypass
Hooks.onLastOperator(Function) pointcut. |
and, as, blockOptional, blockOptional, cache, cache, cancelOn, cast, checkpoint, checkpoint, checkpoint, compose, concatWith, create, defaultIfEmpty, defer, delay, delay, delayElement, delayElement, delaySubscription, delaySubscription, delaySubscription, delayUntil, dematerialize, doAfterSuccessOrError, doAfterTerminate, doFinally, doOnCancel, doOnEach, doOnError, doOnError, doOnError, doOnNext, doOnRequest, doOnSubscribe, doOnSuccess, doOnSuccessOrError, doOnTerminate, elapsed, elapsed, empty, error, expand, expand, expandDeep, expandDeep, filter, filterWhen, first, first, flatMap, flatMapIterable, flatMapMany, flatMapMany, flux, from, fromCallable, fromCompletionStage, fromDirect, fromFuture, fromRunnable, fromSupplier, handle, hasElement, hide, ignoreElement, ignoreElements, just, justOrEmpty, justOrEmpty, log, log, log, log, log, log, map, materialize, mergeWith, name, never, ofType, onAssembly, onErrorMap, onErrorMap, onErrorMap, onErrorResume, onErrorResume, onErrorResume, onErrorReturn, onErrorReturn, onErrorReturn, onLastAssembly, onTerminateDetach, or, publish, publishOn, repeat, repeat, repeat, repeat, repeatWhen, repeatWhenEmpty, repeatWhenEmpty, retry, retry, retry, retry, retryWhen, sequenceEqual, sequenceEqual, sequenceEqual, single, subscribe, subscribe, subscribe, subscribe, subscribe, subscribe, subscribeOn, subscriberContext, subscriberContext, subscriberContext, subscribeWith, switchIfEmpty, tag, take, take, takeUntilOther, then, then, thenEmpty, thenMany, thenReturn, timeout, timeout, timeout, timeout, timeout, timeout, timestamp, timestamp, toFuture, toProcessor, toString, transform, using, using, when, when, whenDelayError, whenDelayError, zip, zip, zip, zip, zip, zip, zip, zip, zipDelayError, zipDelayError, zipDelayError, zipDelayError, zipDelayError, zipDelayError, zipDelayError, zipWhen, zipWhen, zipWith, zipWith
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
actuals, from, isScanAvailable, name, operatorName, parents, scan, scanOrDefault, tags
public static <T> MonoProcessor<T> create()
MonoProcessor
that will eagerly request 1 on onSubscribe(Subscription)
, cache and emit
the eventual result for 1 or N subscribers.T
- type of the expected valueMonoProcessor
.public static <T> MonoProcessor<T> create(WaitStrategy waitStrategy)
MonoProcessor
that will eagerly request 1 on onSubscribe(Subscription)
, cache and emit
the eventual result for 1 or N subscribers.T
- type of the expected valuewaitStrategy
- a WaitStrategy
for blocking block()
strategyMonoProcessor
.public final void cancel()
cancel
in interface Subscription
public void dispose()
Disposable
Implementations are required to make this method idempotent.
dispose
in interface Disposable
@Nullable public O block()
MonoProcessor
. If the
MonoProcessor
is completed with an error a RuntimeException that wraps the error is thrown.@Nullable public O block(Duration timeout)
MonoProcessor
. If the
MonoProcessor
is completed with an error a RuntimeException that wraps the error is thrown.public long getAsLong()
getAsLong
in interface LongSupplier
@Nullable public final Throwable getError()
Throwable
error if any or nullThrowable
error if any or nullpublic boolean isCancelled()
MonoProcessor
has been interrupted via cancellation.true
if this MonoProcessor
is cancelled, false
otherwise.public final boolean isError()
MonoProcessor
has been completed with an error.true
if this MonoProcessor
was completed with an error, false
otherwise.public final boolean isSuccess()
MonoProcessor
has been successfully completed a value.true
if this MonoProcessor
is successful, false
otherwise.public final boolean isTerminated()
MonoProcessor
has been terminated by the
source producer with a success or an error.true
if this MonoProcessor
is successful, false
otherwise.public boolean isDisposed()
Disposable
Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.
isDisposed
in interface Disposable
public final void onComplete()
onComplete
in interface Subscriber<O>
public final void onError(Throwable cause)
onError
in interface Subscriber<O>
public final void onNext(@Nullable O value)
onNext
in interface Subscriber<O>
public final void onSubscribe(Subscription subscription)
CoreSubscriber
Subscriber.onNext(Object)
before
calling Subscription.request(long)
. Should further onNext
related
state modification occur, thread-safety will be required.
Note that an invalid request <= 0
will not produce an onError and
will simply be ignored or reported through a debug-enabled
Logger
.
onSubscribe
in interface Subscriber<O>
onSubscribe
in interface CoreSubscriber<O>
public Stream<? extends Scannable> inners()
Scannable
Stream
of referenced inners (flatmap, multicast etc)@Nullable public O peek()
MonoProcessor
. Returns null
if the MonoProcessor
has not been completed. If the
MonoProcessor
is completed with an error a RuntimeException that wraps the error is thrown.MonoProcessor
, or null
if it has not been completedRuntimeException
- if the MonoProcessor
was completed with an errorpublic final void request(long n)
request
in interface Subscription
public void subscribe(CoreSubscriber<? super O> actual)
Mono
Publisher.subscribe(Subscriber)
that will bypass
Hooks.onLastOperator(Function)
pointcut.
In addition to behave as expected by Publisher.subscribe(Subscriber)
in a controlled manner, it supports direct subscribe-time Context
passing.
subscribe
in class Mono<O>
actual
- the Subscriber
interested into the published sequencePublisher.subscribe(Subscriber)
public Context currentContext()
CoreSubscriber
Context
from dependent components which can include downstream
operators during subscribing or a terminal Subscriber
.currentContext
in interface CoreSubscriber<O>
Context.empty()
@Nullable public Object scanUnsafe(Scannable.Attr key)
Scannable
Scannable.Attr
key,
implementors should take care to return values of the correct type, and return
null if no specific value is available.
For public consumption of attributes, prefer using Scannable.scan(Attr)
, which will
return a typed value and fall back to the key's default if the component didn't
define any mapping.
scanUnsafe
in interface Scannable
key
- a Scannable.Attr
to resolve for the component.public final long downstreamCount()
Subscriber
or -1 if untracked.Subscriber
or -1 if untrackedpublic final boolean hasDownstreams()
Subscriber
is actively subscribedSubscriber
is actively subscribed