public final class

PublishProcessor

extends FlowableProcessor<T>
java.lang.Object
   ↳ io.reactivex.Flowable<T>
     ↳ io.reactivex.processors.FlowableProcessor<T>
       ↳ io.reactivex.processors.PublishProcessor<T>

Class Overview

Processor that multicasts all subsequently observed items to its current Subscribers.

The processor does not coordinate backpressure for its subscribers and implements a weaker 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.

The implementation of onXXX methods are technically thread-safe but non-serialized calls to them may lead to undefined state in the currently subscribed Subscribers.

Due to the nature Flowables are constructed, the PublishProcessor can't be instantiated through new but must be created via the create() method. Example usage:

 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();

   

Summary

Public Methods
static <T> PublishProcessor<T> create()
Constructs a PublishProcessor.
Throwable getThrowable()
Returns the error that caused the Subject to terminate or null if the Subject hasn't terminated yet.
boolean hasComplete()
Returns true if the subject has reached a terminal state through a complete event.
boolean hasSubscribers()
Returns true if the subject has subscribers.
boolean hasThrowable()
Returns true if the subject has reached a terminal state through an error event.
boolean offer(T t)
Tries to emit the item to all currently subscribed Subscribers if all of them has requested some value, returns false otherwise.
void onComplete()
void onError(Throwable t)
void onNext(T t)
void onSubscribe(Subscription s)
void subscribeActual(Subscriber<? super T> t)
Operator implementations (both source and intermediate) should implement this method that performs the necessary business logic.
[Expand]
Inherited Methods
From class io.reactivex.processors.FlowableProcessor
From class io.reactivex.Flowable
From class java.lang.Object
From interface io.reactivex.FlowableSubscriber
From interface org.reactivestreams.Publisher
From interface org.reactivestreams.Subscriber

Public Methods

public static PublishProcessor<T> create ()

Constructs a PublishProcessor.

Returns
  • the new PublishProcessor

public Throwable getThrowable ()

Returns the error that caused the Subject to terminate or null if the Subject hasn't terminated yet.

The method is thread-safe.

Returns
  • the error that caused the Subject to terminate or null if the Subject hasn't terminated yet

public boolean hasComplete ()

Returns true if the subject has reached a terminal state through a complete event.

The method is thread-safe.

Returns
  • true if the subject has reached a terminal state through a complete event

public boolean hasSubscribers ()

Returns true if the subject has subscribers.

The method is thread-safe.

Returns
  • true if the subject has subscribers

public boolean hasThrowable ()

Returns true if the subject has reached a terminal state through an error event.

The method is thread-safe.

Returns
  • true if the subject has reached a terminal state through an error event

public boolean offer (T t)

Tries to emit the item to all currently subscribed Subscribers if all of them has requested some value, returns false otherwise.

This method should be called in a sequential manner just like the onXXX methods of the PublishProcessor.

Calling with null will terminate the PublishProcessor and a NullPointerException is signalled to the Subscribers.

Parameters
t the item to emit, not null
Returns
  • true if the item was emitted to all Subscribers

public void onComplete ()

public void onError (Throwable t)

public void onNext (T t)

public void onSubscribe (Subscription s)

public void subscribeActual (Subscriber<? super T> t)

Operator implementations (both source and intermediate) should implement this method that performs the necessary business logic.

There is no need to call any of the plugin hooks on the current Flowable instance or the Subscriber.

Parameters
t the incoming Subscriber, never null