Top Description Fields Constructors Methods
rx.observers

public Class SafeSubscriber<T>

extends Subscriber<T>
Class Inheritance
Type Parameters
<T>
the type of item expected by the Subscriber
Imports
java.util.Arrays, rx.Subscriber, rx.exceptions.*, rx.plugins.*

SafeSubscriber is a wrapper around Subscriber that ensures that the Subscriber complies with the Observable contract.

The following is taken from the Rx Design Guidelines document:

Messages sent to instances of the IObserver interface follow the following grammar:

OnNext* (OnCompleted | OnError)?

This grammar allows observable sequences to send any amount (0 or more) of OnNext messages to the subscriber, optionally followed by a single success (OnCompleted) or failure (OnError) message.

The single message indicating that an observable sequence has finished ensures that consumers of the observable sequence can deterministically establish that it is safe to perform cleanup operations.

A single failure further ensures that abort semantics can be maintained for operators that work on multiple observable sequences (see paragraph 6.6).

This wrapper does the following:

SafeSubscriber will not synchronize onNext execution. Use SerializedSubscriber to do that.

Field Summary

Modifier and TypeField and Description
private final Subscriber<? super T>
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public
SafeSubscriber(Subscriber<? super T> actual)

Method Summary

Modifier and TypeMethod and Description
protected void
_onError(Throwable e)

The logic for onError without the isFinished check so it can be called from within onCompleted.

public Subscriber<? super T>

Returns:

the Subscriber that was used to create this SafeSubscriber
getActual
()

Returns the Subscriber underlying this SafeSubscriber.

public void
onCompleted()

Implements rx.Observer.onCompleted.

Notifies the Subscriber 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 Subscriber 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 Subscriber with a new item to observe.
Inherited from rx.Subscriber:
addisUnsubscribedonStartrequestsetProducerunsubscribe

Field Detail

actualback to summary
private final Subscriber<? super T> actual
doneback to summary
pack-priv boolean done

Constructor Detail

SafeSubscriberback to summary
public SafeSubscriber(Subscriber<? super T> actual)

Method Detail

_onErrorback to summary
protected void _onError(Throwable e)

The logic for onError without the isFinished check so it can be called from within onCompleted.

Annotations
@SuppressWarnings:deprecation
See Also
the report of this bug
getActualback to summary
public Subscriber<? super T> getActual()

Returns the Subscriber underlying this SafeSubscriber.

Returns:Subscriber<? super T>

the Subscriber that was used to create this SafeSubscriber

onCompletedback to summary
public void onCompleted()

Implements rx.Observer.onCompleted.

Notifies the Subscriber 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.

Notifies the Subscriber 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.

Provides the Subscriber 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