Interface Sinks.Many<T>
- All Superinterfaces:
Scannable
- All Known Subinterfaces:
Sinks.ManyWithUpstream<T>
- All Known Implementing Classes:
EmitterProcessor,ReplayProcessor,UnicastProcessor
- Enclosing class:
- Sinks
Sinks with Flux semantics.
The sink can be exposed to consuming code as a Flux via its asFlux() view.
- Author:
- Simon Baslé, Stephane Maldini
-
Nested Class Summary
Nested classes/interfaces inherited from interface reactor.core.Scannable
Scannable.Attr<T> -
Field Summary
Fields inherited from interface reactor.core.Scannable
OPERATOR_NAME_UNRELATED_WORDS_PATTERN -
Method Summary
Modifier and TypeMethodDescriptionasFlux()Return aFluxview of this sink.intGet how manySubscribersare currently subscribed to the sink.voidemitComplete(Sinks.EmitFailureHandler failureHandler) A simplified attempt at completing via thetryEmitComplete()API, generating anonCompletesignal.voidemitError(Throwable error, Sinks.EmitFailureHandler failureHandler) A simplified attempt at failing the sequence via thetryEmitError(Throwable)API, generating anonErrorsignal.voidemitNext(T t, Sinks.EmitFailureHandler failureHandler) A simplified attempt at emitting a non-null element via thetryEmitNext(Object)API, generating anonNextsignal.Try to terminate the sequence successfully, generating anonCompletesignal.tryEmitError(Throwable error) Try to fail the sequence, generating anonErrorsignal.tryEmitNext(T t) Try emitting a non-null element, generating anonNextsignal.Methods inherited from interface reactor.core.Scannable
actuals, inners, isScanAvailable, name, parents, scan, scanOrDefault, scanUnsafe, stepName, steps, tags, tagsDeduplicated
-
Method Details
-
tryEmitNext
Try emitting a non-null element, generating anonNextsignal. The result of the attempt is represented as anSinks.EmitResult, which possibly indicates error cases.See the list of failure
Sinks.EmitResultinemitNext(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, ...).
- Parameters:
t- the value to emit, not null- Returns:
- an
Sinks.EmitResult, which should be checked to distinguish different possible failures - See Also:
-
tryEmitComplete
Sinks.EmitResult tryEmitComplete()Try to terminate the sequence successfully, generating anonCompletesignal. The result of the attempt is represented as anSinks.EmitResult, which possibly indicates error cases.See the list of failure
Sinks.EmitResultinemitComplete(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.- Returns:
- an
Sinks.EmitResult, which should be checked to distinguish different possible failures - See Also:
-
tryEmitError
Try to fail the sequence, generating anonErrorsignal. The result of the attempt is represented as anSinks.EmitResult, which possibly indicates error cases.See the list of failure
Sinks.EmitResultinemitError(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.- Parameters:
error- the exception to signal, not null- Returns:
- an
Sinks.EmitResult, which should be checked to distinguish different possible failures - See Also:
-
emitNext
A simplified attempt at emitting a non-null element via thetryEmitNext(Object)API, generating anonNextsignal. If the result of the attempt is not asuccess, implementations SHOULD retry thetryEmitNext(Object)call IF the providedSinks.EmitFailureHandlerreturnstrue. 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,
tryEmitNext(Object)is preferable since it allows a custom handling of error cases, although this implies checking the returnedSinks.EmitResultand correctly acting on it. This API is intended as a good default for convenience.When the
Sinks.EmitResultis 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 noSubscriberfrom which to get a contextual discard handler. -
Sinks.EmitResult.FAIL_OVERFLOW: discard the value (Operators.onDiscard(Object, Context)) then callemitError(Throwable, Sinks.EmitFailureHandler)with aExceptions.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 anSinks.EmissionExceptionmentioning RS spec rule 1.3. Note thatSinks.unsafe()never trigger this result. It would be possible for anSinks.EmitFailureHandlerto 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_SERIALIZEDas described above, ...).- Parameters:
t- the value to emit, not nullfailureHandler- the failure handler that allows retrying failedSinks.EmitResult.- Throws:
Sinks.EmissionException- on non-serialized access- See Also:
-
-
emitComplete
A simplified attempt at completing via thetryEmitComplete()API, generating anonCompletesignal. If the result of the attempt is not asuccess, implementations SHOULD retry thetryEmitComplete()call IF the providedSinks.EmitFailureHandlerreturnstrue. 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,
tryEmitComplete()is preferable since it allows a custom handling of error cases, although this implies checking the returnedSinks.EmitResultand correctly acting on it. This API is intended as a good default for convenience.When the
Sinks.EmitResultis 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 ofSinks.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 anSinks.EmissionExceptionmentioning RS spec rule 1.3. Note thatSinks.unsafe()never trigger this result. It would be possible for anSinks.EmitFailureHandlerto 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_SERIALIZEDas described above, ...).- Parameters:
failureHandler- the failure handler that allows retrying failedSinks.EmitResult.- Throws:
Sinks.EmissionException- on non-serialized access- See Also:
-
-
emitError
A simplified attempt at failing the sequence via thetryEmitError(Throwable)API, generating anonErrorsignal. If the result of the attempt is not asuccess, implementations SHOULD retry thetryEmitError(Throwable)call IF the providedSinks.EmitFailureHandlerreturnstrue. 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,
tryEmitError(Throwable)is preferable since it allows a custom handling of error cases, although this implies checking the returnedSinks.EmitResultand correctly acting on it. This API is intended as a good default for convenience.When the
Sinks.EmitResultis 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 ofSinks.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 viaOperators.onErrorDropped(Throwable, Context). -
Sinks.EmitResult.FAIL_NON_SERIALIZED: throw anSinks.EmissionExceptionmentioning RS spec rule 1.3. Note thatSinks.unsafe()never trigger this result. It would be possible for anSinks.EmitFailureHandlerto 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_SERIALIZEDas described above, ...).- Parameters:
error- the exception to signal, not nullfailureHandler- the failure handler that allows retrying failedSinks.EmitResult.- Throws:
Sinks.EmissionException- on non-serialized access- See Also:
-
-
currentSubscriberCount
int currentSubscriberCount()Get how manySubscribersare 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_SUBSCRIBERwhere relevant. (generally intryEmitNext(Object)). Request (and lack thereof) isn't taken into account, all registered subscribers are counted.- Returns:
- the number of subscribers at the time of invocation
-
asFlux
Return aFluxview of this sink. Every call returns the same instance.- Returns:
- the
Fluxview associated to thisSinks.Many
-