Subscribers.
This processor does not have a public constructor by design; a new empty instance of this
PublishProcessor can be created via the create() method.
Since a PublishProcessor is a Reactive Streams Processor type,
nulls are not allowed (Rule 2.13) as
parameters to onNext(Object) and onError(Throwable). Such calls will result in a
NullPointerException being thrown and the processor's state is not changed.
PublishProcessor is a io. as well as a FlowableProcessor,
however, it does not coordinate backpressure between different subscribers and between an
upstream source and a subscriber. If an upstream item is received via onNext(Object), if
a subscriber is not ready to receive an item, that subscriber is terminated via a MissingBackpressureException.
To avoid this case, use offer(Object) and retry sometime later if it returned false.
The PublishProcessor's Subscriber-side consumes items in an unbounded manner.
For a multicasting processor type that also coordinates between the downstream Subscribers and the upstream
source as well, consider using MulticastProcessor.
When this PublishProcessor is terminated via onError(Throwable) or onComplete(),
late Subscribers only receive the respective terminal event.
Unlike a BehaviorProcessor, a PublishProcessor doesn't retain/cache items, therefore, a new
Subscriber won't receive any past items.
Even though PublishProcessor implements the Subscriber interface, calling
onSubscribe is not required (Rule 2.12)
if the processor is used as a standalone source. However, calling onSubscribe
after the PublishProcessor reached its terminal state will result in the
given Subscription being canceled immediately.
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).
Note that serializing over offer(Object) is not supported through toSerialized() because it is a method
available on the PublishProcessor and BehaviorProcessor classes only.
This PublishProcessor supports the standard state-peeking methods hasComplete(), hasThrowable(),
getThrowable() and hasSubscribers().
onSubscribe which
calls requests Long#MAX_VALUE from the incoming Subscriptions. This makes it possible to subscribe the PublishProcessor
to multiple sources (note on serialization though) unlike the standard Subscriber contract. Child subscribers, however, are not overflown but receive an
IllegalStateException in case their requested amount is zero.PublishProcessor does not operate by default on a particular io.reactivex.rxjava3.core.Scheduler and
the Subscribers get notified on the thread the respective onXXX methods were invoked.onError(Throwable) is called, the PublishProcessor enters into a terminal state
and emits the same Throwable instance to the last set of Subscribers. During this emission,
if one or more Subscribers cancel their respective Subscriptions, the
Throwable is delivered to the global error handler via
io.reactivex.rxjava3.plugins.RxJavaPlugins#onError(Throwable) (multiple times if multiple Subscribers
cancel at once).
If there were no Subscribers subscribed to this PublishProcessor when the onError()
was called, the global error handler is not invoked.
PublishProcessor<Object> processor = PublishProcessor.create();
// subscriber1 will receive all onNext and onComplete events
processor.subscribe(subscriber1);
processor.onNext("one");
processor.onNext("two");
// subscriber2 will only receive "three" and onComplete
processor.subscribe(subscriber2);
processor.onNext("three");
processor.onComplete();
MulticastProcessor
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | PublishProcessor.PublishSubscription<
the value type T>Wraps the actual subscriber, tracks its requests and makes cancellation to remove itself from the current subscribers array. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final PublishProcessor. | EMPTY
An empty subscribers array to avoid allocating it all the time. |
| pack-priv Throwable | error
The error, write before terminating and read after checking subscribers. |
| pack-priv final AtomicReference | subscribers
The array of currently subscribed subscribers. |
| pack-priv static final PublishProcessor. | TERMINATED
The terminated indicator for the subscribers array. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv boolean | Returns: true if successful, false if this processor has terminatedthe subscriber to add psTries to add the given subscriber to the subscribers array atomically or returns false if this processor has terminated. |
| public static < the value type T> @NonNull PublishProcessor | |
| public @Nullable 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 the item was emitted to all Subscribersthe item to emit, not t)nullTries to emit the item to all currently subscribed |
| 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 | remove(PublishProcessor.
the subscription wrapping a subscriber to remove psAtomically removes the given subscriber if it is subscribed to this processor. |
| protected void |
| EMPTY | back to summary |
|---|---|
| pack-priv static final PublishProcessor. An empty subscribers array to avoid allocating it all the time.
| |
| error | back to summary |
|---|---|
| pack-priv Throwable error The error, write before terminating and read after checking subscribers. | |
| subscribers | back to summary |
|---|---|
| pack-priv final AtomicReference<PublishProcessor. The array of currently subscribed subscribers. | |
| TERMINATED | back to summary |
|---|---|
| pack-priv static final PublishProcessor. The terminated indicator for the subscribers array.
| |
| PublishProcessor | back to summary |
|---|---|
| pack-priv PublishProcessor() Constructs a PublishProcessor.
| |
| add | back to summary |
|---|---|
| pack-priv boolean add(PublishProcessor. Tries to add the given subscriber to the subscribers array atomically or returns false if this processor has terminated.
| |
| create | back to summary |
|---|---|
| public static <T> @NonNull PublishProcessor Constructs a PublishProcessor.
| |
| getThrowable | back to summary |
|---|---|
| public @Nullable 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 emit the item to all currently subscribed
This method should be called in a sequential manner just like the History: 2.0.8 - experimental
| |
| 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(PublishProcessor. Atomically removes the given subscriber if it is subscribed to this processor.
| |
| subscribeActual | back to summary |
|---|---|
protected void subscribeActual(@NonNull Subscriber<? super T> t)
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Subscriber | downstream
The actual subscriber. |
| pack-priv final PublishProcessor | parent
The parent processor servicing this subscriber. |
| private static final long |
| Access | Constructor and Description |
|---|---|
| pack-priv | PublishSubscription(Subscriber<? super T>
the actual subscriber actual, PublishProcessor<T> the parent PublishProcessor parent)Constructs a PublishSubscriber, wraps the actual subscriber and the state. |
| Modifier and Type | Method and Description |
|---|---|
| public void | cancel()
Implements org. Publisher to stop sending data and clean up resources.
|
| public boolean | |
| pack-priv boolean | |
| public void | |
| public void | |
| public 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 The actual subscriber. | |
| parent | back to summary |
|---|---|
| pack-priv final PublishProcessor<T> parent The parent processor servicing this subscriber. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. | |
| PublishSubscription | back to summary |
|---|---|
| pack-priv PublishSubscription(Subscriber<? super T> actual, PublishProcessor<T> parent) Constructs a PublishSubscriber, wraps the actual subscriber and the state.
| |
| 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.
| |
| isCancelled | back to summary |
|---|---|
| public boolean isCancelled() | |
| isFull | back to summary |
|---|---|
| pack-priv boolean isFull() | |
| onComplete | back to summary |
|---|---|
| public void onComplete() | |
| onError | back to summary |
|---|---|
| public void onError(Throwable t) | |
| onNext | back to summary |
|---|---|
| public 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 | |