public final class

PublishSubject

extends Subject<T>
java.lang.Object
   ↳ io.reactivex.Observable<T>
     ↳ io.reactivex.subjects.Subject<T>
       ↳ io.reactivex.subjects.PublishSubject<T>

Class Overview

Subject that, once an Observer has subscribed, emits all subsequently observed items to the subscriber.

Example usage:

 PublishSubject<Object> subject = PublishSubject.create();
  // observer1 will receive all onNext and onComplete events
  subject.subscribe(observer1);
  subject.onNext("one");
  subject.onNext("two");
  // observer2 will only receive "three" and onComplete
  subject.subscribe(observer2);
  subject.onNext("three");
  subject.onComplete();

   

Summary

Public Methods
static <T> PublishSubject<T> create()
Constructs a PublishSubject.
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 hasObservers()
Returns true if the subject has any Observers.
boolean hasThrowable()
Returns true if the subject has reached a terminal state through an error event.
void onComplete()
void onError(Throwable t)
void onNext(T t)
void onSubscribe(Disposable s)
void subscribeActual(Observer<? 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.subjects.Subject
From class io.reactivex.Observable
From class java.lang.Object
From interface io.reactivex.ObservableSource
From interface io.reactivex.Observer

Public Methods

public static PublishSubject<T> create ()

Constructs a PublishSubject.

Returns
  • the new PublishSubject

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

Returns true if the subject has any Observers.

The method is thread-safe.

Returns
  • true if the subject has any Observers

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 void onComplete ()

public void onError (Throwable t)

public void onNext (T t)

public void onSubscribe (Disposable s)

public void subscribeActual (Observer<? 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 Observable instance or the Subscriber.

Parameters
t the incoming Observer, never null