public class SinkOneSerialized<T> extends Object
Scannable.Attr<T>
OPERATOR_NAME_UNRELATED_WORDS_PATTERN
Constructor and Description |
---|
SinkOneSerialized(Sinks.One<T> sinkOne,
reactor.core.publisher.ContextHolder contextHolder) |
Modifier and Type | Method and Description |
---|---|
Mono<T> |
asMono()
Return a
Mono view of this sink. |
Context |
currentContext()
Request a
Context from dependent components which can include downstream
operators during subscribing or a terminal Subscriber . |
Context |
currentContext()
Request a
Context from dependent components which can include downstream
operators during subscribing or a terminal Subscriber . |
int |
currentSubscriberCount()
Get how many
Subscribers are currently subscribed to the sink. |
default void |
emitEmpty(Sinks.EmitFailureHandler failureHandler)
A simplified attempt at completing via the
Sinks.Empty.tryEmitEmpty() API, generating an
onComplete signal. |
default void |
emitError(Throwable error,
Sinks.EmitFailureHandler failureHandler)
A simplified attempt at failing the sequence via the
Sinks.Empty.tryEmitError(Throwable) API, generating an
onError signal. |
default void |
emitValue(T value,
Sinks.EmitFailureHandler failureHandler)
A simplified attempt at emitting a non-null element via the
Sinks.One.tryEmitValue(Object) API, generating an
onNext signal immediately followed by an Subscriber.onComplete() signal. |
Stream<? extends Scannable> |
inners()
Return a
Stream of referenced inners (flatmap, multicast etc) |
Object |
scanUnsafe(Scannable.Attr key)
This method is used internally by components to define their key-value mappings
in a single place.
|
Sinks.EmitResult |
tryEmitEmpty()
Try to complete the
Mono without a value, generating only an onComplete signal. |
Sinks.EmitResult |
tryEmitError(Throwable t)
|
Sinks.EmitResult |
tryEmitValue(T t)
Try to complete the
Mono with an element, generating an onNext signal
immediately followed by an onComplete signal. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
asMono, currentSubscriberCount, tryEmitEmpty, tryEmitError
actuals, from, inners, isScanAvailable, name, parents, scan, scanOrDefault, scanUnsafe, stepName, steps, tags, tagsDeduplicated
public Sinks.EmitResult tryEmitValue(T t)
Sinks.One
Mono
with an element, generating an onNext
signal
immediately followed by an onComplete
signal. A null
value
will only trigger the onComplete. The result of the attempt is represented as an Sinks.EmitResult
,
which possibly indicates error cases.
See the list of failure Sinks.EmitResult
in #emitValue(Object, EmitFailureHandler)
javadoc for an
example of how each of these can be dealt with, to decide if the emit API would be a good enough fit instead.
Might throw an unchecked exception as a last resort (eg. in case of a fatal error downstream which cannot be propagated to any asynchronous handler, a bubbling exception, ...).
t
- the value to emit and complete with, or null
to only trigger an onCompleteSinks.EmitResult
, which should be checked to distinguish different possible failuresSinks.One.emitValue(Object, Sinks.EmitFailureHandler)
,
Subscriber.onNext(Object)
,
Subscriber.onComplete()
public void emitValue(@Nullable T value, Sinks.EmitFailureHandler failureHandler)
Sinks.One
Sinks.One.tryEmitValue(Object)
API, generating an
onNext
signal immediately followed by an Subscriber.onComplete()
signal.
If the result of the attempt is not a success
, implementations SHOULD retry the
Sinks.One.tryEmitValue(Object)
call IF the provided Sinks.EmitFailureHandler
returns true
.
Otherwise, failures are dealt with in a predefined way that might depend on the actual sink implementation
(see below for the vanilla reactor-core behavior).
Generally, Sinks.One.tryEmitValue(Object)
is preferable since it allows a custom handling
of error cases, although this implies checking the returned Sinks.EmitResult
and correctly
acting on it. This API is intended as a good default for convenience.
When the Sinks.EmitResult
is not a success, vanilla reactor-core operators have the following behavior:
Sinks.EmitResult.FAIL_ZERO_SUBSCRIBER
: no particular handling. should ideally discard the value but at that
point there's no Subscriber
from which to get a contextual discard handler.
Sinks.EmitResult.FAIL_OVERFLOW
: discard the value (Operators.onDiscard(Object, Context)
)
then call Sinks.Empty.emitError(Throwable, Sinks.EmitFailureHandler)
with a Exceptions.failWithOverflow(String)
exception.
Sinks.EmitResult.FAIL_CANCELLED
: discard the value (Operators.onDiscard(Object, Context)
).
Sinks.EmitResult.FAIL_TERMINATED
: drop the value (Operators.onNextDropped(Object, Context)
).
Sinks.EmitResult.FAIL_NON_SERIALIZED
: throw an Sinks.EmissionException
mentioning RS spec rule 1.3.
Note that Sinks.unsafe()
never trigger this result. It would be possible for an Sinks.EmitFailureHandler
to busy-loop and optimistically wait for the contention to disappear to avoid this case for safe sinks...
Might throw an unchecked exception as a last resort (eg. in case of a fatal error downstream which cannot
be propagated to any asynchronous handler, a bubbling exception, a Sinks.EmitResult.FAIL_NON_SERIALIZED
as described above, ...).
emitValue
in interface Sinks.One<T>
value
- the value to emit and complete with, a null
is actually acceptable to only trigger an onCompletefailureHandler
- the failure handler that allows retrying failed Sinks.EmitResult
.Sinks.One.tryEmitValue(Object)
,
Subscriber.onNext(Object)
,
Subscriber.onComplete()
public void emitEmpty(Sinks.EmitFailureHandler failureHandler)
Sinks.Empty
Sinks.Empty.tryEmitEmpty()
API, generating an
onComplete
signal.
If the result of the attempt is not a success
, implementations SHOULD retry the
Sinks.Empty.tryEmitEmpty()
call IF the provided Sinks.EmitFailureHandler
returns true
.
Otherwise, failures are dealt with in a predefined way that might depend on the actual sink implementation
(see below for the vanilla reactor-core behavior).
Generally, Sinks.Empty.tryEmitEmpty()
is preferable since it allows a custom handling
of error cases, although this implies checking the returned Sinks.EmitResult
and correctly
acting on it. This API is intended as a good default for convenience.
When the Sinks.EmitResult
is not a success, vanilla reactor-core operators have the following behavior:
Sinks.EmitResult.FAIL_OVERFLOW
: irrelevant as onComplete is not driven by backpressure.
Sinks.EmitResult.FAIL_ZERO_SUBSCRIBER
: the completion can be ignored since nobody is listening.
Note that most vanilla reactor sinks never trigger this result for onComplete, replaying the
terminal signal to later subscribers instead (to the exception of Sinks.UnicastSpec.onBackpressureError()
).
Sinks.EmitResult.FAIL_CANCELLED
: the completion can be ignored since nobody is interested.
Sinks.EmitResult.FAIL_TERMINATED
: the extra completion is basically ignored since there was a previous
termination signal, but there is nothing interesting to log.
Sinks.EmitResult.FAIL_NON_SERIALIZED
: throw an Sinks.EmissionException
mentioning RS spec rule 1.3.
Note that Sinks.unsafe()
never trigger this result. It would be possible for an Sinks.EmitFailureHandler
to busy-loop and optimistically wait for the contention to disappear to avoid this case in safe sinks...
Might throw an unchecked exception as a last resort (eg. in case of a fatal error downstream which cannot
be propagated to any asynchronous handler, a bubbling exception, a Sinks.EmitResult.FAIL_NON_SERIALIZED
as described above, ...).
emitEmpty
in interface Sinks.Empty<T>
failureHandler
- the failure handler that allows retrying failed Sinks.EmitResult
.Sinks.Empty.tryEmitEmpty()
,
Subscriber.onComplete()
public void emitError(Throwable error, Sinks.EmitFailureHandler failureHandler)
Sinks.Empty
Sinks.Empty.tryEmitError(Throwable)
API, generating an
onError
signal.
If the result of the attempt is not a success
, implementations SHOULD retry the
Sinks.Empty.tryEmitError(Throwable)
call IF the provided Sinks.EmitFailureHandler
returns true
.
Otherwise, failures are dealt with in a predefined way that might depend on the actual sink implementation
(see below for the vanilla reactor-core behavior).
Generally, Sinks.Empty.tryEmitError(Throwable)
is preferable since it allows a custom handling
of error cases, although this implies checking the returned Sinks.EmitResult
and correctly
acting on it. This API is intended as a good default for convenience.
When the Sinks.EmitResult
is not a success, vanilla reactor-core operators have the following behavior:
Sinks.EmitResult.FAIL_OVERFLOW
: irrelevant as onError is not driven by backpressure.
Sinks.EmitResult.FAIL_ZERO_SUBSCRIBER
: the error is ignored since nobody is listening. Note that most vanilla reactor sinks
never trigger this result for onError, replaying the terminal signal to later subscribers instead
(to the exception of Sinks.UnicastSpec.onBackpressureError()
).
Sinks.EmitResult.FAIL_CANCELLED
: the error can be ignored since nobody is interested.
Sinks.EmitResult.FAIL_TERMINATED
: the error unexpectedly follows another terminal signal, so it is
dropped via Operators.onErrorDropped(Throwable, Context)
.
Sinks.EmitResult.FAIL_NON_SERIALIZED
: throw an Sinks.EmissionException
mentioning RS spec rule 1.3.
Note that Sinks.unsafe()
never trigger this result. It would be possible for an Sinks.EmitFailureHandler
to busy-loop and optimistically wait for the contention to disappear to avoid this case in safe sinks...
Might throw an unchecked exception as a last resort (eg. in case of a fatal error downstream which cannot
be propagated to any asynchronous handler, a bubbling exception, a Sinks.EmitResult.FAIL_NON_SERIALIZED
as described above, ...).
emitError
in interface Sinks.Empty<T>
error
- the exception to signal, not nullfailureHandler
- the failure handler that allows retrying failed Sinks.EmitResult
.Sinks.Empty.tryEmitError(Throwable)
,
Subscriber.onError(Throwable)
public Context currentContext()
Context
from dependent components which can include downstream
operators during subscribing or a terminal Subscriber
.public final Sinks.EmitResult tryEmitEmpty()
Sinks.Empty
Mono
without a value, generating only an onComplete
signal.
The result of the attempt is represented as an Sinks.EmitResult
, which possibly indicates error cases.
See the list of failure Sinks.EmitResult
in #emitEmpty(EmitFailureHandler)
javadoc for an
example of how each of these can be dealt with, to decide if the emit API would be a good enough fit instead.
Sinks.EmitResult
, which should be checked to distinguish different possible failuresSinks.Empty.emitEmpty(Sinks.EmitFailureHandler)
,
Subscriber.onComplete()
public final Sinks.EmitResult tryEmitError(Throwable t)
Sinks.Empty
Mono
, generating only an onError
signal.
The result of the attempt is represented as an Sinks.EmitResult
, which possibly indicates error cases.
See the list of failure Sinks.EmitResult
in #emitError(Throwable, EmitFailureHandler)
javadoc for an
example of how each of these can be dealt with, to decide if the emit API would be a good enough fit instead.
t
- the exception to signal, not nullSinks.EmitResult
, which should be checked to distinguish different possible failuresSinks.Empty.emitError(Throwable, Sinks.EmitFailureHandler)
,
Subscriber.onError(Throwable)
public int currentSubscriberCount()
Sinks.Empty
Subscribers
are currently subscribed to the sink.
This is a best effort peek at the sink state, and a subsequent attempt at emitting
to the sink might still return Sinks.EmitResult.FAIL_ZERO_SUBSCRIBER
where relevant.
Request (and lack thereof) isn't taken into account, all registered subscribers are counted.
public Mono<T> asMono()
Sinks.Empty
Mono
view of this sink. Every call returns the same instance.public Stream<? extends Scannable> inners()
Scannable
Stream
of referenced inners (flatmap, multicast etc)Stream
of referenced inners (flatmap, multicast etc)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.
key
- a Scannable.Attr
to resolve for the component.public Context currentContext()
Context
from dependent components which can include downstream
operators during subscribing or a terminal Subscriber
.