public final class

UnicastSubject

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

Class Overview

Subject that allows only a single Subscriber to subscribe to it during its lifetime.

This subject buffers notifications and replays them to the Subscriber as requested.

This subject holds an unbounded internal buffer.

If more than one Subscriber attempts to subscribe to this Subject, they will receive an IllegalStateException if this Subject hasn't terminated yet, or the Subscribers receive the terminal event (error or completion) if this Subject has terminated.

Summary

Public Methods
static <T> UnicastSubject<T> create(int capacityHint, Runnable onTerminate)
Creates an UnicastSubject with the given internal buffer capacity hint and a callback for the case when the single Subscriber cancels its subscription.
static <T> UnicastSubject<T> create(int capacityHint)
Creates an UnicastSubject with the given internal buffer capacity hint.
static <T> UnicastSubject<T> create(boolean delayError)
Creates an UnicastSubject with an internal buffer capacity hint 16 and given delay error flag.
static <T> UnicastSubject<T> create(int capacityHint, Runnable onTerminate, boolean delayError)
Creates an UnicastSubject with the given internal buffer capacity hint, delay error flag and a callback for the case when the single Subscriber cancels its subscription.
static <T> UnicastSubject<T> create()
Creates an UnicastSubject with an internal buffer capacity hint 16.
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)
Protected Methods
void subscribeActual(Observer<? super T> observer)
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 UnicastSubject<T> create (int capacityHint, Runnable onTerminate)

Creates an UnicastSubject with the given internal buffer capacity hint and a callback for the case when the single Subscriber cancels its subscription.

The callback, if not null, is called exactly once and non-overlapped with any active replay.

Parameters
capacityHint the hint to size the internal unbounded buffer
onTerminate the callback to run when the Subject is terminated or cancelled, null not allowed
Returns
  • an UnicastSubject instance

public static UnicastSubject<T> create (int capacityHint)

Creates an UnicastSubject with the given internal buffer capacity hint.

Parameters
capacityHint the hint to size the internal unbounded buffer
Returns
  • an UnicastSubject instance

public static UnicastSubject<T> create (boolean delayError)

Creates an UnicastSubject with an internal buffer capacity hint 16 and given delay error flag.

The callback, if not null, is called exactly once and non-overlapped with any active replay.

Parameters
delayError deliver pending onNext events before onError
Returns
  • an UnicastSubject instance

public static UnicastSubject<T> create (int capacityHint, Runnable onTerminate, boolean delayError)

Creates an UnicastSubject with the given internal buffer capacity hint, delay error flag and a callback for the case when the single Subscriber cancels its subscription.

The callback, if not null, is called exactly once and non-overlapped with any active replay.

Parameters
capacityHint the hint to size the internal unbounded buffer
onTerminate the callback to run when the Subject is terminated or cancelled, null not allowed
delayError deliver pending onNext events before onError
Returns
  • an UnicastSubject instance

public static UnicastSubject<T> create ()

Creates an UnicastSubject with an internal buffer capacity hint 16.

Returns
  • an UnicastSubject instance

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)

Protected Methods

protected void subscribeActual (Observer<? super T> observer)

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
observer the incoming Observer, never null