Top Description Inners Fields Constructors Methods
reactor.core.publisher

public abstract Class Operators

extends Object
Class Inheritance
Imports
java.util.Collection, .Iterator, .Objects, .Queue, .Spliterator, java.util.concurrent.RejectedExecutionException, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, .AtomicLongFieldUpdater, .AtomicReferenceFieldUpdater, java.util.function.BiFunction, .Consumer, .Function, .Predicate, java.util.stream.Stream, org.reactivestreams.Publisher, .Subscriber, .Subscription, reactor.core.CorePublisher, .CoreSubscriber, .Exceptions, .Fuseable, .Fuseable.QueueSubscription, .Scannable, .Scannable.Attr.RunStyle, reactor.util.Logger, .Loggers, reactor.util.annotation.Nullable, reactor.util.context.Context

A helper to support "Operator" writing, handle noop subscriptions, validate request size and to cap concurrent additive operations to Long.MAX_VALUE, which is generic to Subscription#request(long) handling. Combine utils available to operator implementations, @see https://github.com/reactor/reactive-streams-commons

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract static class
pack-priv static class
pack-priv static class
Operators.ConditionalSubscriberAdapter<
passed subscriber type
T
>

This class wraps any non-conditional CoreSubscriber<T> so the delegate can have an emulation of reactor.core.Fuseable.ConditionalSubscriber<T> behaviors

pack-priv static class
public static class
Operators.DeferredSubscription

Base class for Subscribers that will receive their Subscriptions at any time, yet they might also need to be cancelled or requested at any time.

pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
public static class
Operators.MonoSubscriber<
The upstream sequence type
I
,
The downstream sequence type
O
>

A Subscriber/Subscription barrier that holds a single value at most and properly gates asynchronous behaviors resulting from concurrent request or cancel and onXXX signals.

pack-priv abstract static class
Operators.MultiSubscriptionSubscriber<
the input value type
I
,
the output value type
O
>

A subscription implementation that arbitrates request amounts between subsequent Subscriptions, including the duration until the first Subscription is set.

pack-priv static class
Operators.ScalarSubscription<
the value type
T
>

Represents a fuseable Subscription that emits a single constant value synchronously to a Subscriber or consumer.

Field Summary

Modifier and TypeField and Description
pack-priv static final Fuseable.ConditionalSubscriber<?>
pack-priv static final Logger

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

Addition result or Long.MAX_VALUE if overflow
addCap
(long
left operand
a
,
long
right operand
b
)

Cap an addition to Long.MAX_VALUE

public static <
the parent instance type
T
>
long

Returns:

value before addition or Long.MAX_VALUE
addCap
(AtomicLongFieldUpdater<T>
current field updater
updater
,
T
current instance to update
instance
,
long
delta to add
toAdd
)

Concurrent addition bound to Long.MAX_VALUE.

pack-priv static <
the type of the field-bearing instance
T
>
long

Returns:

the old value of the field, before update.
addCapCancellable
(AtomicLongFieldUpdater<T>
the field to update
updater
,
T
the instance bearing the field
instance
,
long
the value to add
n
)

Add the amount n to the given field, capped to Long#MAX_VALUE, unless the field is already at Long#MAX_VALUE OR Long#MIN_VALUE.

public static <
the value type of the QueueSubscription.
T
>
Fuseable.QueueSubscription<T>

Returns:

the QueueSubscription instance or null
as
(Subscription
the source subscription to try to convert.
s
)

Returns the subscription as QueueSubscription if possible or null.

public static boolean

Returns:

true if passed subscription is a subscription created in reportThrowInSubscribe(CoreSubscriber, Throwable).
canAppearAfterOnSubscribe
(Subscription
the subscription to test.
subscription
)

Check whether the provided Subscription is the one used to satisfy Spec's §1.9 rule before signalling an error.

public static Subscription

Returns:

a singleton noop Subscription to be used as an inner representation of the cancelled state
cancelledSubscription
()

A singleton Subscription that represents a cancelled subscription instance and should not be leaked to clients as it represents a terminal state.

public static void
complete(Subscriber<?>
the target subscriber
s
)

Calls onSubscribe on the target Subscriber with the empty instance followed by a call to onComplete.

pack-priv static final <
element type
R
>
Function<Context, Context>

Returns:

a Function that can be used to modify a Context, adding or updating a context-local discard hook.
discardLocalAdapter
(Class<R>
the type of elements to take into account
type
,
Consumer<? super R>
the discarding handler for this type of elements
discardHook
)

Create an adapter for local onDiscard hooks that check the element being discarded is of a given Class.

public static <T> CoreSubscriber<T>

Returns:

a new Subscriber whose sole purpose is to request Long.MAX
drainSubscriber
()

Return a singleton Subscriber that does not check for double onSubscribe and purely request Long.MAX.

public static <
the type of data (ignored)
T
>
CoreSubscriber<T>

Returns:

a placeholder subscriber
emptySubscriber
()

A Subscriber that is expected to be used as a placeholder and never actually be called.

public static Subscription

Returns:

a singleton noop Subscription
emptySubscription
()

A singleton enumeration that represents a no-op Subscription instance that can be freely given out to clients.

public static final Context

Returns:

a new Context that holds (potentially combined) cleanup Consumer
enableOnDiscard
(Context
the original Context
target
,
Consumer<?>
the consumer that will be used to cleanup discarded elements
discardConsumer
)

Utility method to activate the onDiscard feature (see Flux#doOnDiscard(Class, Consumer)) in a target Context.

public static void
error(Subscriber<?>
target Subscriber to error
s
,
Throwable
the actual error
e
)

Calls onSubscribe on the target Subscriber with the empty instance followed by a call to onError with the supplied error.

public static <
the input type
I
,
the output type
O
>
Function<? super Publisher<I>, ? extends Publisher<O>>

Returns:

a new Function
lift
(BiFunction<Scannable, ? super CoreSubscriber<? super O>, ? extends CoreSubscriber<? super I>>
the bifunction taking Scannable from the enclosing publisher (assuming it is compatible) and consuming CoreSubscriber. It must return a receiving CoreSubscriber that will immediately subscribe to the applied Publisher.
lifter
)

Create a function that can be used to support a custom operator via CoreSubscriber decoration.

public static <
the input and output type
O
>
Function<? super Publisher<O>, ? extends Publisher<O>>

Returns:

a new Function
lift
(Predicate<Scannable>
the predicate to match taking Scannable from the applied publisher to operate on. Assumes original is scan-compatible.
filter
,
BiFunction<Scannable, ? super CoreSubscriber<? super O>, ? extends CoreSubscriber<? super O>>
the bifunction taking Scannable from the enclosing publisher and consuming CoreSubscriber. It must return a receiving CoreSubscriber that will immediately subscribe to the applied Publisher. Assumes the original is scan-compatible.
lifter
)

Create a function that can be used to support a custom operator via CoreSubscriber decoration.

public static <
the input type
I
,
the output type
O
>
Function<? super Publisher<I>, ? extends Publisher<O>>

Returns:

a new Function
liftPublisher
(BiFunction<Publisher<T>, ? super CoreSubscriber<? super O>, ? extends CoreSubscriber<? super I>>
the bifunction taking the raw Publisher and CoreSubscriber. The publisher can be double-checked (including with instanceof, and the function must return a receiving CoreSubscriber that will immediately subscribe to the Publisher.
lifter
)

Create a function that can be used to support a custom operator via CoreSubscriber decoration.

public static <
the input and output type
O
>
Function<? super Publisher<O>, ? extends Publisher<O>>

Returns:

a new Function
liftPublisher
(Predicate<Publisher<T>>
the Predicate that the raw Publisher must pass for the transformation to occur
filter
,
BiFunction<Publisher<T>, ? super CoreSubscriber<? super O>, ? extends CoreSubscriber<? super O>>
the BiFunction taking the raw Publisher and CoreSubscriber. The publisher can be double-checked (including with instanceof, and the function must return a receiving CoreSubscriber that will immediately subscribe to the Publisher.
lifter
)

Create a function that can be used to support a custom operator via CoreSubscriber decoration.

public static long

Returns:

Product result or Long.MAX_VALUE if overflow
multiplyCap
(long
left operand
a
,
long
right operand
b
)

Cap a multiplication to Long.MAX_VALUE

pack-priv static Context
multiSubscribersContext(InnerProducer<?>[] multicastInners)

public static <
the type of the element
T
>
void
onDiscard(T
the element that is being discarded
element
,
Context
the context in which to look for a local hook
context
)

Invoke a (local or global) hook that processes elements that get discarded.

public static void
onDiscardMultiple(Stream<?>
the collection of elements to discard (possibly extracted from other collections/arrays/queues)
multiple
,
Context
the Context in which to look for local hook
context
)

Invoke a (local or global) hook that processes elements that get discarded en masse.

public static void
onDiscardMultiple(Collection<?>
the collection of elements to discard
multiple
,
Context
the Context in which to look for local hook
context
)

Invoke a (local or global) hook that processes elements that get discarded en masse.

public static void
onDiscardMultiple(Iterator<?>
the Iterator whose remainder to discard
multiple
,
boolean
is the caller guaranteeing that the iterator is finite and can be iterated over
knownToBeFinite
,
Context
the Context in which to look for local hook
context
)

Invoke a (local or global) hook that processes elements that remains in an java.util.Iterator.

public static void
onDiscardMultiple(Spliterator<?>
the Spliterator whose remainder to discard
multiple
,
boolean
is the caller guaranteeing that the iterator is finite and can be iterated over
knownToBeFinite
,
Context
the Context in which to look for local hook
context
)

Invoke a (local or global) hook that processes elements that remains in an java.util.Spliterator.

public static <
the type of the element
T
>
void
onDiscardQueueWithClear(Queue<T>
the queue that is being discarded and cleared
queue
,
Context
the context in which to look for a local hook
context
,
Function<T, Stream<?>>
an optional extractor method for cases where the queue doesn't directly contain the elements to discard
extract
)

Invoke a (local or global) hook that processes elements that get discarded en masse after having been enqueued, due to cancellation or error.

public static void
onErrorDropped(Throwable
the dropped exception
e
,
Context
a context that might hold a local error consumer
context
)

An unexpected exception is about to be dropped.

pack-priv static void
onErrorDroppedMulticast(Throwable
the dropped exception
e
,
InnerProducer<?>[]
the inner targets of the multicast
multicastInners
)

An unexpected exception is about to be dropped from an operator that has multiple subscribers (and thus potentially multiple Context with local onErrorDropped handlers).

public static <
the type of the value.
T
>
CorePublisher<T>

Returns:

a CorePublisher to subscribe on.
onLastAssembly
(CorePublisher<T>
the original CorePublisher.
source
)

Applies the hooks registered with Hooks#onLastOperator and returns CorePublisher ready to be subscribed on.

public static <
the dropped value type
T
>
void
onNextDropped(T
the dropped data
t
,
Context
a context that might hold a local next consumer
context
)

An unexpected event is about to be dropped.

pack-priv static <
the dropped value type
T
>
void
onNextDroppedMulticast(T
the dropped data
t
,
InnerProducer<?>[]
the inner targets of the multicast
multicastInners
)

An unexpected event is about to be dropped from an operator that has multiple subscribers (and thus potentially multiple Context with local onNextDropped handlers).

public static <
The type of the value causing the error.
T
>
Throwable

Returns:

a Throwable to propagate through onError if the strategy is terminal and cancelled the subscription, null if not.
onNextError
(T
The onNext value that caused an error. Can be null.
value
,
Throwable
The error.
error
,
Context
The most significant Context in which to look for an OnNextFailureStrategy.
context
,
Subscription
The mandatory Subscription that should be cancelled if the strategy is terminal. See also onNextError(Object, Throwable, Context) and onNextPollError(Object, Throwable, Context) for alternatives that don't cancel a subscription
subscriptionForCancel
)

Find the OnNextFailureStrategy to apply to the calling operator (which could be a local error mode defined in the Context) and apply it.

public static <
The type of the value causing the error.
T
>
Throwable

Returns:

a Throwable to propagate through onError if the strategy is terminal, null if not.
onNextError
(T
The onNext value that caused an error.
value
,
Throwable
The error.
error
,
Context
The most significant Context in which to look for an OnNextFailureStrategy.
context
)

Find the OnNextFailureStrategy to apply to the calling async operator (which could be a local error mode defined in the Context) and apply it.

public static final BiFunction<? super Throwable, Object, ? extends Throwable>
pack-priv static final OnNextFailureStrategy
public static <
The type of the value causing the error.
T
>
Throwable

Returns:

a Throwable to propagate through onError if the strategy is terminal and cancelled the subscription, null if not.
onNextInnerError
(Throwable
The error.
error
,
Context
The most significant Context in which to look for an OnNextFailureStrategy.
context
,
Subscription
The Subscription that should be cancelled if the strategy is terminal. Null to ignore (for poll, use onNextPollError(Object, Throwable, Context) rather than passing null).
subscriptionForCancel
)

Find the OnNextFailureStrategy to apply to the calling operator (which could be a local error mode defined in the Context) and apply it.

public static <
The type of the value causing the error.
T
>
RuntimeException

Returns:

a RuntimeException to be thrown (eg. within Queue#poll() if the error is terminal in the strategy, null if not.
onNextPollError
(T
The onNext value that caused an error.
value
,
Throwable
The error.
error
,
Context
The most significant Context in which to look for an OnNextFailureStrategy.
context
)

Find the OnNextFailureStrategy to apply to the calling async operator (which could be a local error mode defined in the Context) and apply it.

public static Throwable

Returns:

mapped Throwable
onOperatorError
(Throwable
the callback or operator error
error
,
Context
a context that might hold a local error consumer
context
)

Map an "operator" error.

public static Throwable

Returns:

mapped Throwable
onOperatorError
(Subscription
the linked operator parent Subscription
subscription
,
Throwable
the callback or operator error
error
,
Context
a context that might hold a local error consumer
context
)

Map an "operator" error given an operator parent Subscription.

public static Throwable

Returns:

mapped Throwable
onOperatorError
(Subscription
the linked operator parent Subscription
subscription
,
Throwable
the callback or operator error
error
,
Object
the value (onNext or onError) signal processed during failure
dataSignal
,
Context
a context that might hold a local error consumer
context
)

Map an "operator" error given an operator parent Subscription.

public static RuntimeException
onRejectedExecution(Throwable
the original execution error
original
,
Context
a context that might hold a local error consumer
context
)

Return a wrapped RejectedExecutionException which can be thrown by the operator.

public static RuntimeException
onRejectedExecution(Throwable
the original execution error
original
,
Subscription
the subscription to pass to onOperatorError.
subscription
,
Throwable
a Throwable to be suppressed by the RejectedExecutionException (or null if not relevant)
suppressed
,
Object
a value to be passed to onOperatorError(Subscription, Throwable, Object, Context) (or null if not relevant)
dataSignal
,
Context
a context that might hold a local error consumer
context
)

Return a wrapped RejectedExecutionException which can be thrown by the operator.

public static <
the parent instance type
T
>
long

Returns:

value after subtraction or zero
produced
(AtomicLongFieldUpdater<T>
current field updater
updater
,
T
current instance to update
instance
,
long
delta to subtract
toSub
)

Concurrent subtraction bound to 0, mostly used to decrement a request tracker by the amount produced by the operator.

pack-priv static <T> long
producedCancellable(AtomicLongFieldUpdater<T> updater, T instance, long n)

public static <
the instance type
F
>
boolean

Returns:

true if replaced
replace
(AtomicReferenceFieldUpdater<F, Subscription>
The Atomic container
field
,
F
the instance reference
instance
,
Subscription
the subscription
s
)

A generic utility to atomically replace a subscription or cancel the replacement if the current subscription is marked as already cancelled (as in cancelledSubscription()).

public static void
reportBadRequest(long
the failing demand
n
)

Log an IllegalArgumentException if the request is null or negative.

public static void
reportMoreProduced()

Log an IllegalStateException that indicates more than the requested amount was produced.

public static void
public static void
reportThrowInSubscribe(CoreSubscriber<?>
the Subscriber being subscribed when the error happened
subscriber
,
Throwable e)

Report a Throwable that was thrown from a call to Publisher#subscribe(Subscriber), attempting to notify the Subscriber by:

  1. providing a special Subscription via Subscriber#onSubscribe(Subscription)
  2. immediately delivering an onError signal after that
pack-priv static <T> CoreSubscriber<T>
pack-priv static <T> CoreSubscriber<? super T>
pack-priv static <T> CoreSubscriber<T>
pack-priv static <T> CoreSubscriber<? super T>[]
restoreContextOnSubscribers(Publisher<?> publisher, CoreSubscriber<? super T>[] subscribers)

public static <
the value type
T
>
Subscription

Returns:

a new scalar Subscription
scalarSubscription
(CoreSubscriber<? super T>
the delegate Subscriber that will be requesting the value
subscriber
,
T
the single value to be emitted
value
)

Represents a fuseable Subscription that emits a single constant value synchronously to a Subscriber or consumer.

public static <
the value type
T
>
Subscription

Returns:

a new scalar Subscription
scalarSubscription
(CoreSubscriber<? super T>
the delegate Subscriber that will be requesting the value
subscriber
,
T
the single value to be emitted
value
,
String
the String to represent the Subscription in Scannable#stepName()
stepName
)

Represents a fuseable Subscription that emits a single constant value synchronously to a Subscriber or consumer.

public static <
the relayed type
T
>
CoreSubscriber<T>

Returns:

a serializing Subscriber
serialize
(CoreSubscriber<? super T>
the subscriber to serialize
subscriber
)

Safely gate a Subscriber by making sure onNext signals are delivered sequentially (serialized).

public static <
the instance type
F
>
boolean

Returns:

true if replaced
set
(AtomicReferenceFieldUpdater<F, Subscription>
The Atomic container
field
,
F
the instance reference
instance
,
Subscription
the subscription
s
)

A generic utility to atomically replace a subscription or cancel the replacement if current subscription is marked as cancelled (as in cancelledSubscription()) or was concurrently updated before.

public static <
the instance type containing the field
F
>
boolean

Returns:

true if successful, false if the target was not empty or has been cancelled
setOnce
(AtomicReferenceFieldUpdater<F, Subscription>
the field accessor
field
,
F
the parent instance
instance
,
Subscription
the subscription to set once
s
)

Sets the given subscription once and returns true if successful, false if the field has a subscription already or has been cancelled.

public static long

Returns:

Subtraction result or 0 if overflow
subOrZero
(long
left operand
a
,
long
right operand
b
)

Cap a subtraction to 0

public static <
the instance type containing the field
F
>
boolean

Returns:

true if terminated, false if the subscription was already terminated
terminate
(AtomicReferenceFieldUpdater<F, Subscription>
the field accessor
field
,
F
the parent instance
instance
)

Atomically terminates the subscription if it is not already a cancelledSubscription(), cancelling the subscription and setting the field to the singleton cancelledSubscription().

public static <
passed subscriber type
T
>
Fuseable.ConditionalSubscriber<? super T>

Returns:

a potentially adapted reactor.core.Fuseable.ConditionalSubscriber
toConditionalSubscriber
(CoreSubscriber<? super T>
the Subscriber to adapt
actual
)

If the actual CoreSubscriber is not reactor.core.Fuseable.ConditionalSubscriber, it will apply an adapter which directly maps all reactor.core.Fuseable.ConditionalSubscriber#tryOnNext(Object) to Subscriber#onNext(Object) and always returns true as the result

public static <
passed subscriber type
T
>
CoreSubscriber<? super T>

Returns:

an eventually transformed Subscriber
toCoreSubscriber
(Subscriber<? super T>
the Subscriber to apply hook on
actual
)

If the actual Subscriber is not a CoreSubscriber, it will apply safe strict wrapping to apply all reactive streams rules including the ones relaxed by internal operators based on CoreSubscriber.

public static <T> CorePublisher<T>
toFluxOrMono(Publisher<T> publisher)

public static <T> void
toFluxOrMono(Publisher<? extends T>[] sources)

pack-priv static int
unboundedOrLimit(int prefetch)

pack-priv static int
unboundedOrLimit(int prefetch, int lowTide)

pack-priv static long
unboundedOrPrefetch(int prefetch)

private static Throwable
public static boolean

Returns:

true if Subscription can be used
validate
(Subscription
current Subscription, expected to be null
current
,
Subscription
new Subscription
next
)

Check Subscription current state and cancel new Subscription if current is set, or return true if ready to subscribe.

public static boolean

Returns:

true if valid
validate
(long
the request value
n
)

Evaluate if a request is strictly positive otherwise reportBadRequest(long)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait