FlowableProcessor implementation that coordinates downstream requests through
a front-buffer and stable-prefetching, optionally canceling the upstream if all
subscribers have cancelled.
This processor does not have a public constructor by design; a new empty instance of this
MulticastProcessor can be created via the following create methods that
allow configuring it:
create(): create an empty MulticastProcessor with
Flowable.bufferSize() prefetch amount
and no reference counting behavior.create(int): create an empty MulticastProcessor with
the given prefetch amount and no reference counting behavior.create(boolean): create an empty MulticastProcessor with
Flowable.bufferSize() prefetch amount
and an optional reference counting behavior.create(int, boolean): create an empty MulticastProcessor with
the given prefetch amount and an optional reference counting behavior.
When the reference counting behavior is enabled, the MulticastProcessor cancels its
upstream when all Subscribers have cancelled. Late Subscribers will then be
immediately completed.
Because MulticastProcessor implements the Subscriber interface, calling
onSubscribe is mandatory (Rule 2.12).
If MulticastProcessor should run standalone, i.e., without subscribing the MulticastProcessor to another Publisher,
use start() or startUnbounded() methods to initialize the internal buffer.
Failing to do so will lead to a NullPointerException at runtime.
Use offer(Object) to try and offer/emit items but don't fail if the
internal buffer is full.
A MulticastProcessor is a Processor type in the Reactive Streams specification,
nulls are not allowed (Rule 2.13) as
parameters to onSubscribe(Subscription), offer(Object), onNext(Object) and onError(Throwable).
Such calls will result in a NullPointerException being thrown and the processor's state is not changed.
Since a MulticastProcessor is a io., it supports backpressure.
The backpressure from the currently subscribed Subscribers are coordinated by emitting upstream
items only if all of those Subscribers have requested at least one item. This behavior
is also called lockstep-mode because even if some Subscribers can take any number
of items, other Subscribers requesting less or infrequently will slow down the overall
throughput of the flow.
Calling onNext(Object), offer(Object), onError(Throwable) and onComplete()
is required to be serialized (called from the same thread or called non-overlappingly from different threads
through external means of serialization). The toSerialized() method available to all FlowableProcessors
provides such serialization and also protects against reentrance (i.e., when a downstream Subscriber
consuming this processor also wants to call onNext(Object) on this processor recursively).
This MulticastProcessor supports the standard state-peeking methods hasComplete(), hasThrowable(),
getThrowable() and hasSubscribers(). This processor doesn't allow peeking into its buffer.
When this MulticastProcessor is terminated via onError(Throwable) or onComplete(),
all previously signaled but not yet consumed items will be still available to Subscribers and the respective
terminal even is only emitted when all previous items have been successfully delivered to Subscribers.
If there are no Subscribers, the remaining items will be buffered indefinitely.
The MulticastProcessor does not support clearing its cached events (to appear empty again).
Subscribers are coordinated by emitting upstream
items only if all of those Subscribers have requested at least one item. This behavior
is also called lockstep-mode because even if some Subscribers can take any number
of items, other Subscribers requesting less or infrequently will slow down the overall
throughput of the flow.MulticastProcessor does not operate by default on a particular io.reactivex.rxjava3.core.Scheduler and
the Subscribers get notified on an arbitrary thread in a serialized fashion.Example:
MulticastProcessor<Integer> mp = Flowable.range(1, 10)
.subscribeWith(MulticastProcessor.create());
mp.test().assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
// --------------------
MulticastProcessor<Integer> mp2 = MulticastProcessor.create(4);
mp2.start();
assertTrue(mp2.offer(1));
assertTrue(mp2.offer(2));
assertTrue(mp2.offer(3));
assertTrue(mp2.offer(4));
assertFalse(mp2.offer(5));
mp2.onComplete();
mp2.test().assertResult(1, 2, 3, 4);
History: 2.1.14 - experimental
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final int | |
| pack-priv int | |
| pack-priv volatile boolean | |
| pack-priv static final MulticastProcessor. | |
| pack-priv volatile Throwable | |
| pack-priv int | |
| pack-priv final int | |
| pack-priv volatile SimpleQueue | |
| pack-priv final boolean | |
| pack-priv final AtomicReference | |
| pack-priv static final MulticastProcessor. | |
| pack-priv final AtomicReference | |
| pack-priv final AtomicInteger |
| Access | Constructor and Description |
|---|---|
| pack-priv | MulticastProcessor(int
the prefetch amount bufferSize, boolean if true and if all Subscribers have canceled, the upstream
is cancelled refCount)Constructs a fresh instance with the given prefetch amount and the optional refCount-behavior. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv boolean | |
| public static < the input and output value type T> @NonNull MulticastProcessor | Returns: the new MulticastProcessor instanceConstructs a fresh instance with the default Flowable.bufferSize() prefetch amount and no refCount-behavior. |
| public static < the input and output value type T> @NonNull MulticastProcessor | Returns: the new MulticastProcessor instanceif true and if all Subscribers have canceled, the upstream
is cancelled refCount)Constructs a fresh instance with the default Flowable.bufferSize() prefetch amount and the optional refCount-behavior. |
| public static < the input and output value type T> @NonNull MulticastProcessor | Returns: the new MulticastProcessor instancethe prefetch amount bufferSize)Constructs a fresh instance with the given prefetch amount and no refCount behavior. |
| public static < the input and output value type T> @NonNull MulticastProcessor | Returns: the new MulticastProcessor instancethe prefetch amount bufferSize, boolean if true and if all Subscribers have canceled, the upstream
is cancelled refCount)Constructs a fresh instance with the given prefetch amount and the optional refCount-behavior. |
| pack-priv void | |
| public Throwable | getThrowable()
Implements abstract io. |
| public boolean | hasComplete()
Implements abstract io. |
| public boolean | hasSubscribers()
Implements abstract io. |
| public boolean | hasThrowable()
Implements abstract io. |
| public boolean | Returns: true if successful, false if the queue is fullthe item to offer, not t)nullTries to offer an item into the internal queue and returns false if the queue is full. |
| public void | |
| public void | onError(@NonNull Throwable
the throwable signaled t)Implements org. |
| public void | onNext(T
the element signaled t)Implements org. Publisher in response to requests to Subscription#request(long).
|
| public void | onSubscribe(@NonNull Subscription
the s)Subscription that allows requesting data via Subscription#request(long)Implements org. Publisher#subscribe(Subscriber).
|
| pack-priv void | |
| public void | start()
Initializes this Processor by setting an upstream Subscription that ignores request amounts, uses a fixed buffer and allows using the onXXX and offer methods afterwards. |
| public void | startUnbounded()
Initializes this Processor by setting an upstream Subscription that ignores request amounts, uses an unbounded buffer and allows using the onXXX and offer methods afterwards. |
| protected void |
| bufferSize | back to summary |
|---|---|
| pack-priv final int bufferSize | |
| consumed | back to summary |
|---|---|
| pack-priv int consumed | |
| done | back to summary |
|---|---|
| pack-priv volatile boolean done | |
| EMPTY | back to summary |
|---|---|
pack-priv static final MulticastProcessor.
| |
| error | back to summary |
|---|---|
| pack-priv volatile Throwable error | |
| fusionMode | back to summary |
|---|---|
| pack-priv int fusionMode | |
| limit | back to summary |
|---|---|
| pack-priv final int limit | |
| queue | back to summary |
|---|---|
| pack-priv volatile SimpleQueue<T> queue | |
| refcount | back to summary |
|---|---|
| pack-priv final boolean refcount | |
| subscribers | back to summary |
|---|---|
| pack-priv final AtomicReference<MulticastProcessor. | |
| TERMINATED | back to summary |
|---|---|
pack-priv static final MulticastProcessor.
| |
| upstream | back to summary |
|---|---|
| pack-priv final AtomicReference<Subscription> upstream | |
| wip | back to summary |
|---|---|
| pack-priv final AtomicInteger wip | |
| MulticastProcessor | back to summary |
|---|---|
| pack-priv MulticastProcessor(int bufferSize, boolean refCount) Constructs a fresh instance with the given prefetch amount and the optional refCount-behavior.
| |
| add | back to summary |
|---|---|
| pack-priv boolean add(MulticastProcessor. | |
| create | back to summary |
|---|---|
| public static <T> @NonNull MulticastProcessor Constructs a fresh instance with the default Flowable.bufferSize() prefetch amount and no refCount-behavior.
| |
| create | back to summary |
|---|---|
| public static <T> @NonNull MulticastProcessor Constructs a fresh instance with the default Flowable.bufferSize() prefetch amount and the optional refCount-behavior.
| |
| create | back to summary |
|---|---|
| public static <T> @NonNull MulticastProcessor Constructs a fresh instance with the given prefetch amount and no refCount behavior.
| |
| create | back to summary |
|---|---|
| public static <T> @NonNull MulticastProcessor Constructs a fresh instance with the given prefetch amount and the optional refCount-behavior.
| |
| drain | back to summary |
|---|---|
pack-priv void drain()
| |
| getThrowable | back to summary |
|---|---|
| public Throwable getThrowable() Implements abstract io. Doc from io. Returns the error that caused the FlowableProcessor to terminate or null if the FlowableProcessor hasn't terminated yet. The method is thread-safe.
| |
| hasComplete | back to summary |
|---|---|
| public boolean hasComplete() Implements abstract io. Doc from io. Returns true if the FlowableProcessor has reached a terminal state through a complete event. The method is thread-safe.
| |
| hasSubscribers | back to summary |
|---|---|
| public boolean hasSubscribers() Implements abstract io. Doc from io. Returns true if the FlowableProcessor has subscribers. The method is thread-safe.
| |
| hasThrowable | back to summary |
|---|---|
| public boolean hasThrowable() Implements abstract io. Doc from io. Returns true if the FlowableProcessor has reached a terminal state through an error event. The method is thread-safe.
| |
| offer | back to summary |
|---|---|
| public boolean offer(T t) Tries to offer an item into the internal queue and returns false if the queue is full.
| |
| onComplete | back to summary |
|---|---|
| public void onComplete() Implements org. Doc from org. Successful terminal state.
No further events will be sent even if
| |
| onError | back to summary |
|---|---|
| public void onError(@NonNull Throwable t) Implements org. Doc from org. Failed terminal state.
No further events will be sent even if | |
| onNext | back to summary |
|---|---|
| public void onNext(T t) Implements org. Doc from org. Data notification sent by the
| |
| onSubscribe | back to summary |
|---|---|
| public void onSubscribe(@NonNull Subscription s) Implements org. Doc from org. Invoked after calling
No data will start flowing until
It is the responsibility of this
The
| |
| remove | back to summary |
|---|---|
pack-priv void remove(MulticastProcessor.
| |
| start | back to summary |
|---|---|
| public void start() Initializes this Processor by setting an upstream Subscription that ignores request amounts, uses a fixed buffer and allows using the onXXX and offer methods afterwards. | |
| startUnbounded | back to summary |
|---|---|
| public void startUnbounded() Initializes this Processor by setting an upstream Subscription that ignores request amounts, uses an unbounded buffer and allows using the onXXX and offer methods afterwards. | |
| subscribeActual | back to summary |
|---|---|
protected void subscribeActual(@NonNull Subscriber<? super T> s)
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Subscriber | |
| pack-priv long | |
| pack-priv final MulticastProcessor | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | cancel()
Implements org. Publisher to stop sending data and clean up resources.
|
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| public void | request(long
the strictly positive number of elements to requests to the upstream n)PublisherImplements org. Publisher until demand is signaled via this method.
|
| downstream | back to summary |
|---|---|
| pack-priv final Subscriber<? super T> downstream | |
| emitted | back to summary |
|---|---|
| pack-priv long emitted | |
| parent | back to summary |
|---|---|
| pack-priv final MulticastProcessor<T> parent | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. | |
| MulticastSubscription | back to summary |
|---|---|
| pack-priv MulticastSubscription(Subscriber<? super T> actual, MulticastProcessor<T> parent) | |
| cancel | back to summary |
|---|---|
| public void cancel() Implements org. Doc from org. Request the Data may still be sent to meet previously signalled demand after calling cancel.
| |
| onComplete | back to summary |
|---|---|
| pack-priv void onComplete() | |
| onError | back to summary |
|---|---|
| pack-priv void onError(Throwable t) | |
| onNext | back to summary |
|---|---|
| pack-priv void onNext(T t) | |
| request | back to summary |
|---|---|
| public void request(long n) Implements org. Doc from org. No events will be sent by a
It can be called however often and whenever needed—but if the outstanding cumulative demand ever becomes Long.MAX_VALUE or more,
it may be treated by the
Whatever has been requested can be sent by the
A | |