public final class Sinks extends Object
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).
Modifier and Type | Class and Description |
---|---|
static class |
Sinks.EmissionException
An exception representing a
failed Sinks.EmitResult . |
static interface |
Sinks.EmitFailureHandler
A handler supporting the emit API (eg.
|
static class |
Sinks.EmitResult
Represents the immediate result of an emit attempt (eg.
|
static interface |
Sinks.Empty<T>
A base interface for standalone
Sinks with complete-or-fail semantics. |
static interface |
Sinks.Many<T>
|
static interface |
Sinks.ManySpec
Provides
Sinks.Many specs for sinks which can emit multiple elements |
static interface |
Sinks.ManyWithUpstream<T>
A
Sinks.Many which additionally allows being subscribed to an upstream Publisher ,
which is an advanced pattern requiring external synchronization. |
static interface |
Sinks.ManyWithUpstreamUnsafeSpec
|
static interface |
Sinks.MulticastReplaySpec
Provides multicast with history/replay capacity : 1 sink, N
Subscriber |
static interface |
Sinks.MulticastSpec
Provides multicast : 1 sink, N
Subscriber |
static interface |
Sinks.One<T>
|
static interface |
Sinks.RootSpec
|
static interface |
Sinks.UnicastSpec
Provides unicast: 1 sink, 1
Subscriber |
Modifier and Type | Method and Description |
---|---|
static <T> Sinks.Empty<T> |
empty()
A
Sinks.Empty which exclusively produces one terminal signal: error or complete. |
static Sinks.ManySpec |
many()
Help building
Sinks.Many sinks that will broadcast multiple signals to one or more Subscriber . |
static <T> Sinks.One<T> |
one()
A
Sinks.One that works like a conceptual promise: it can be completed
with or without a value at any time, but only once. |
static Sinks.RootSpec |
unsafe()
Return a
root spec for more advanced use cases such as building operators. |
public static <T> Sinks.Empty<T> empty()
Sinks.Empty
which exclusively produces one terminal signal: error or complete.
It has the following characteristics:
Sinks.Empty.asMono()
to expose the Mono
view of the sink to downstream consumers.Sinks.Empty
Sinks.RootSpec.empty()
public static <T> Sinks.One<T> one()
Sinks.One
that 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.
Calling Sinks.One.tryEmitValue(Object)
(or Sinks.One.emitValue(Object, Sinks.EmitFailureHandler)
) is enough and will
implicitly produce a Subscriber.onComplete()
signal as well.
Use Sinks.Empty.asMono()
to expose the Mono
view of the sink to downstream consumers.
Sinks.One
Sinks.RootSpec.one()
public static Sinks.ManySpec many()
Sinks.Many
sinks that will broadcast multiple signals to one or more Subscriber
.
Use Sinks.Many.asFlux()
to expose the Flux
view of the sink to the downstream consumers.
Sinks.ManySpec
Sinks.RootSpec.many()
public static Sinks.RootSpec unsafe()
root spec
for more advanced use cases such as building operators.
Unsafe Sinks.Many
, Sinks.One
and Sinks.Empty
are 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 a Subscriber
or an operator. In turn, this allows the sinks to have less overhead, since they
don't care to detect concurrent access anymore.Sinks.RootSpec