Top Description Fields Constructors Methods
rx.subjects

public Class SerializedSubject<T, R>

extends Subject<T, R>
Class Inheritance
Type Parameters
<T>
the input value type
<R>
the output value type
Imports
rx.Subscriber, rx.observers.SerializedObserver

Wraps a Subject so that it is safe to call its various on methods from different threads.

When you use an ordinary Subject as a Subscriber, you must take care not to call its Subscriber#onNext method (or its other on methods) from multiple threads, as this could lead to non-serialized calls, which violates the Observable contract and creates an ambiguity in the resulting Subject.

To protect a Subject from this danger, you can convert it into a SerializedSubject with code like the following:

mySafeSubject = new SerializedSubject( myUnsafeSubject );

Field Summary

Modifier and TypeField and Description
private final Subject<T, R>
private final SerializedObserver<T>

Constructor Summary

AccessConstructor and Description
public
SerializedSubject(final Subject<T, R> actual)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasObservers()

Implements abstract rx.subjects.Subject.hasObservers.

Indicates whether the Subject has Observers subscribed to it.
public void
onCompleted()

Implements rx.Observer.onCompleted.

Notifies the Observer that the Observable has finished sending push-based notifications.
public void
onError(Throwable
the exception encountered by the Observable
e
)

Implements rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.
public void
onNext(T
the item emitted by the Observable
t
)

Implements rx.Observer.onNext.

Provides the Observer with a new item to observe.
Inherited from rx.subjects.Subject:
toSerialized

Field Detail

actualback to summary
private final Subject<T, R> actual
observerback to summary
private final SerializedObserver<T> observer

Constructor Detail

SerializedSubjectback to summary
public SerializedSubject(final Subject<T, R> actual)

Method Detail

hasObserversback to summary
public boolean hasObservers()

Implements abstract rx.subjects.Subject.hasObservers.

Doc from rx.subjects.Subject.hasObservers.

Indicates whether the Subject has Observers subscribed to it.

Returns:boolean

true if there is at least one Observer subscribed to this Subject, false otherwise

Annotations
@Override
onCompletedback to summary
public void onCompleted()

Implements rx.Observer.onCompleted.

Doc from rx.Observer.onCompleted.

Notifies the Observer that the Observable has finished sending push-based notifications.

The Observable will not call this method if it calls onError.

Annotations
@Override
onErrorback to summary
public void onError(Throwable e)

Implements rx.Observer.onError.

Doc from rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.

If the Observable calls this method, it will not thereafter call onNext or onCompleted.

Parameters
e:Throwable

the exception encountered by the Observable

Annotations
@Override
onNextback to summary
public void onNext(T t)

Implements rx.Observer.onNext.

Doc from rx.Observer.onNext.

Provides the Observer with a new item to observe.

The Observable may call this method 0 or more times.

The Observable will not call this method again after it calls either onCompleted or onError.

Parameters
t:T

the item emitted by the Observable

Annotations
@Override