Package reactor.core.publisher
Class Sinks
java.lang.Object
reactor.core.publisher.Sinks
Sinks are constructs through which Reactive Streams signals can be programmatically pushed, with
Flux or Mono
semantics. These standalone sinks expose tryEmit methods that return an Sinks.EmitResult enum,
allowing to atomically fail in case the attempted signal is inconsistent with the spec and/or the state of the sink.
This class exposes a collection of (Sinks.Many builders and Sinks.One factories. Unless constructed through the
unsafe() spec, these sinks are thread safe in the sense that they will detect concurrent access and fail fast on one of
the attempts. unsafe() sinks on the other hand are expected to be externally synchronized (typically by being called from
within a Reactive Streams-compliant context, like a Subscriber or an operator, which means it is ok to remove the overhead
of detecting concurrent access from the sink itself).
- Author:
- Simon Baslé, Stephane Maldini
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAn exception representing afailedSinks.EmitResult.static interfaceA handler supporting the emit API (eg.static enumRepresents the immediate result of an emit attempt (eg.static interfaceA base interface for standaloneSinkswith complete-or-fail semantics.static interfacestatic interfaceProvidesSinks.Manyspecs for sinks which can emit multiple elementsstatic interfaceASinks.Manywhich additionally allows being subscribed to an upstreamPublisher, which is an advanced pattern requiring external synchronization.static interfacestatic interfaceProvides multicast with history/replay capacity : 1 sink, NSubscriberstatic interfaceProvides multicast : 1 sink, NSubscriberstatic interfacestatic interfacestatic interfaceProvides unicast: 1 sink, 1Subscriber -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Sinks.Empty<T>empty()ASinks.Emptywhich exclusively produces one terminal signal: error or complete.static Sinks.ManySpecmany()Help buildingSinks.Manysinks that will broadcast multiple signals to one or moreSubscriber.static <T> Sinks.One<T>one()ASinks.Onethat works like a conceptual promise: it can be completed with or without a value at any time, but only once.static Sinks.RootSpecunsafe()Return aroot specfor more advanced use cases such as building operators.
-
Method Details
-
empty
ASinks.Emptywhich exclusively produces one terminal signal: error or complete. It has the following characteristics:- Multicast
- Backpressure : this sink does not need any demand since it can only signal error or completion
- Replaying: Replay the terminal signal (error or complete).
Sinks.Empty.asMono()to expose theMonoview of the sink to downstream consumers.- Returns:
- a new
Sinks.Empty - See Also:
-
one
ASinks.Onethat works like a conceptual promise: it can be completed with or without a value at any time, but only once. This completion is replayed to late subscribers. CallingSinks.One.tryEmitValue(Object)(orSinks.One.emitValue(Object, Sinks.EmitFailureHandler)) is enough and will implicitly produce aSubscriber.onComplete()signal as well.Use
Sinks.Empty.asMono()to expose theMonoview of the sink to downstream consumers.- Returns:
- a new
Sinks.One - See Also:
-
many
Help buildingSinks.Manysinks that will broadcast multiple signals to one or moreSubscriber.Use
Sinks.Many.asFlux()to expose theFluxview of the sink to the downstream consumers.- Returns:
Sinks.ManySpec- See Also:
-
unsafe
Return aroot specfor more advanced use cases such as building operators. UnsafeSinks.Many,Sinks.OneandSinks.Emptyare not serialized nor thread safe, which implies they MUST be externally synchronized so as to respect the Reactive Streams specification. This can typically be the case when the sinks are being called from within a Reactive Streams-compliant context, like aSubscriberor an operator. In turn, this allows the sinks to have less overhead, since they don't care to detect concurrent access anymore.- Returns:
Sinks.RootSpec
-