Top Description Fields Constructors Methods
rx

public abstract Class Subscriber<T>

extends Object
implements Observer<T>, Subscription
Class Inheritance
All Implemented Interfaces
rx.Subscription, rx.Observer
Known Direct Subclasses
rx.internal.observers.AssertableSubscriberObservable, rx.internal.operators.BlockingOperatorLatest.LatestObserverIterator, rx.internal.operators.BlockingOperatorMostRecent.MostRecentObserver, rx.internal.operators.BlockingOperatorNext.NextObserver, rx.internal.operators.BlockingOperatorToIterator.SubscriberIterator, rx.internal.operators.CompletableOnSubscribeConcat.CompletableConcatSubscriber, rx.internal.operators.CompletableOnSubscribeMerge.CompletableMergeSubscriber, rx.internal.operators.OperatorDoOnRequest.ParentSubscriber, rx.internal.operators.OperatorEagerConcatMap.EagerOuterSubscriber, rx.internal.operators.OperatorEagerConcatMap.EagerInnerSubscriber, rx.internal.operators.OperatorGroupBy.GroupBySubscriber, rx.internal.operators.OperatorGroupByEvicting.GroupBySubscriber, rx.internal.operators.OperatorMapNotification.MapNotificationSubscriber, rx.internal.operators.OperatorMapPair.MapPairSubscriber, rx.internal.operators.OperatorMaterialize.ParentSubscriber, rx.internal.operators.OperatorMerge.MergeSubscriber, rx.internal.operators.OperatorMerge.InnerSubscriber, rx.internal.operators.OperatorObserveOn.ObserveOnSubscriber, rx.internal.operators.OperatorOnBackpressureBuffer.BufferSubscriber, rx.internal.operators.OperatorOnBackpressureLatest.LatestSubscriber, rx.internal.operators.OperatorPublish.PublishSubscriber, rx.internal.operators.OnSubscribeFlatMapSingle.FlatMapSingleSubscriber, rx.internal.operators.OnSubscribeFlattenIterable.FlattenIterableSubscriber, rx.internal.operators.OnSubscribeGroupJoin.ResultManager.LeftObserver, rx.internal.operators.OnSubscribeGroupJoin.ResultManager.RightObserver, rx.internal.operators.OnSubscribeGroupJoin.ResultManager.LeftDurationObserver, rx.internal.operators.OnSubscribeGroupJoin.ResultManager.RightDurationObserver, rx.internal.operators.OnSubscribeGroupJoin.WindowObservableFunc.WindowSubscriber, rx.internal.operators.OnSubscribeJoin.ResultSink.LeftSubscriber, rx.internal.operators.OnSubscribeJoin.ResultSink.LeftSubscriber.LeftDurationSubscriber, rx.internal.operators.OnSubscribeJoin.ResultSink.RightSubscriber, rx.internal.operators.OnSubscribeJoin.ResultSink.RightSubscriber.RightDurationSubscriber, rx.internal.operators.OnSubscribeMap.MapSubscriber, rx.internal.operators.OnSubscribeOnAssembly.OnAssemblySubscriber, rx.internal.operators.OnSubscribePublishMulticast.ParentSubscriber, rx.internal.operators.OnSubscribeReduce.ReduceSubscriber, rx.internal.operators.OnSubscribeSkipTimed.SkipTimedSubscriber, rx.internal.operators.OperatorTakeUntilPredicate.ParentSubscriber, rx.internal.operators.OperatorWindowWithObservable.SourceSubscriber, rx.internal.operators.OperatorWindowWithObservable.BoundarySubscriber, rx.internal.operators.OperatorWindowWithObservableFactory.SourceSubscriber, rx.internal.operators.OperatorWindowWithObservableFactory.BoundarySubscriber, rx.internal.operators.OperatorWindowWithSize.WindowExact, rx.internal.operators.OperatorWindowWithSize.WindowSkip, rx.internal.operators.OperatorWindowWithSize.WindowOverlap, rx.internal.operators.OperatorWindowWithStartEndObservable.SourceSubscriber, rx.internal.operators.OperatorWindowWithTime.ExactSubscriber, rx.internal.operators.OperatorWindowWithTime.InexactSubscriber, rx.internal.operators.OperatorWithLatestFromMany.WithLatestMainSubscriber, rx.internal.operators.OperatorWithLatestFromMany.WithLatestOtherSubscriber, rx.internal.operators.OperatorZip.ZipSubscriber, rx.internal.operators.OperatorZip.Zip.InnerSubscriber, rx.internal.operators.OnSubscribeFlatMapCompletable.FlatMapCompletableSubscriber, rx.internal.operators.OnSubscribeSwitchIfEmpty.ParentSubscriber, rx.internal.operators.OnSubscribeSwitchIfEmpty.AlternateSubscriber, rx.internal.operators.OperatorReplay.ReplaySubscriber, rx.internal.operators.OnSubscribeTimeoutSelectorWithFallback.TimeoutMainSubscriber, rx.internal.operators.OnSubscribeTimeoutSelectorWithFallback.TimeoutMainSubscriber.TimeoutConsumer, rx.internal.operators.OnSubscribeTimeoutTimedWithFallback.TimeoutMainSubscriber, rx.internal.operators.OnSubscribeTimeoutTimedWithFallback.FallbackSubscriber, rx.internal.operators.OperatorBufferWithSingleObservable.BufferingSubscriber, rx.internal.operators.OperatorBufferWithSize.BufferExact, rx.internal.operators.OperatorBufferWithSize.BufferSkip, rx.internal.operators.OperatorBufferWithSize.BufferOverlap, rx.internal.operators.OperatorBufferWithStartEndObservable.BufferingSubscriber, rx.internal.operators.OperatorBufferWithTime.InexactSubscriber, rx.internal.operators.OperatorBufferWithTime.ExactSubscriber, rx.internal.operators.OperatorCast.CastSubscriber, rx.internal.operators.OperatorRetryWithPredicate.SourceSubscriber, rx.internal.operators.OperatorSampleWithTime.SamplerSubscriber, rx.internal.operators.OperatorSingle.ParentSubscriber, rx.internal.operators.OperatorSubscribeOn.SubscribeOnSubscriber, rx.internal.operators.OperatorSwitch.SwitchSubscriber, rx.internal.operators.OperatorSwitch.InnerSubscriber, rx.internal.operators.OperatorTakeLast.TakeLastSubscriber, rx.internal.operators.OperatorTakeLastTimed.TakeLastTimedSubscriber, rx.internal.operators.OperatorTakeTimed.TakeSubscriber, rx.internal.operators.SingleFromObservable.WrapSingleIntoSubscriber, rx.internal.operators.SingleTakeUntilObservable.TakeUntilSourceSubscriber.OtherSubscriber, rx.internal.operators.DeferredScalarSubscriber, rx.internal.operators.OnSubscribeAmb.AmbSubscriber, rx.internal.operators.OnSubscribeCombineLatest.CombinerSubscriber, rx.internal.operators.OnSubscribeConcatMap.ConcatMapSubscriber, rx.internal.operators.OnSubscribeConcatMap.ConcatMapInnerSubscriber, rx.internal.operators.OnSubscribeDetach.DetachSubscriber, rx.internal.operators.OnSubscribeDoOnEach.DoOnEachSubscriber, rx.internal.operators.OnSubscribeFilter.FilterSubscriber, rx.internal.util.ActionSubscriber, rx.internal.util.ObserverSubscriber, rx.observers.SafeSubscriber, rx.observers.SerializedSubscriber, rx.observers.TestSubscriber
Type Parameters
<T>
the type of items the Subscriber expects to observe
Imports
rx.internal.util.SubscriptionList

Provides a mechanism for receiving push-based notifications from Observables, and permits manual unsubscribing from these Observables.

After a Subscriber calls an Observable's subscribe method, the Observable calls the Subscriber's onNext method to emit items. A well-behaved Observable will call a Subscriber's onCompleted method exactly once or the Subscriber's onError method exactly once.

See Also
ReactiveX documentation: Observable

Field Summary

Modifier and TypeField and Description
private static final long
private Producer
private long
private final Subscriber<?>
private final SubscriptionList

Constructor Summary

AccessConstructor and Description
protected
protected
Subscriber(Subscriber<?>
the other Subscriber
subscriber
)

Construct a Subscriber by using another Subscriber for backpressure and for holding the subscription list (when this.add(sub) is called this will in fact call subscriber.add(sub)).

protected
Subscriber(Subscriber<?>
the other Subscriber
subscriber
,
boolean
true to share the subscription list in subscriber with this instance
shareSubscriptions
)

Construct a Subscriber by using another Subscriber for backpressure and optionally for holding the subscription list (if shareSubscriptions is true then when this.add(sub) is called this will in fact call subscriber.add(sub)).

Method Summary

Modifier and TypeMethod and Description
public final void
add(Subscription
the Subscription to add
s
)

Adds a Subscription to this Subscriber's list of subscriptions if this list is not marked as unsubscribed.

private void
public final boolean

Returns:

true if this Subscriber has unsubscribed from its subscriptions, false otherwise
isUnsubscribed
()

Implements rx.Subscription.isUnsubscribed.

Indicates whether this Subscriber has unsubscribed from its list of subscriptions.
public void
onStart()

This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber.

protected final void
request(long
the maximum number of items you want the Observable to emit to the Subscriber at this time, or Long.MAX_VALUE if you want the Observable to emit items at its own pace
n
)

Request a certain maximum number of emitted items from the Observable this Subscriber is subscribed to.

public void
setProducer(Producer
producer to be used by this subscriber or the other subscriber (or recursively its other subscriber) to make requests from
p
)

If other subscriber is set (by calling constructor Subscriber(Subscriber) or Subscriber(Subscriber, boolean)) then this method calls setProducer on the other subscriber.

public final void
unsubscribe()

Implements rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

NOT_SETback to summary
private static final long NOT_SET
producerback to summary
private Producer producer
requestedback to summary
private long requested
subscriberback to summary
private final Subscriber<?> subscriber
subscriptionsback to summary
private final SubscriptionList subscriptions

Constructor Detail

Subscriberback to summary
protected Subscriber()
Subscriberback to summary
protected Subscriber(Subscriber<?> subscriber)

Construct a Subscriber by using another Subscriber for backpressure and for holding the subscription list (when this.add(sub) is called this will in fact call subscriber.add(sub)).

Parameters
subscriber:Subscriber<?>

the other Subscriber

Subscriberback to summary
protected Subscriber(Subscriber<?> subscriber, boolean shareSubscriptions)

Construct a Subscriber by using another Subscriber for backpressure and optionally for holding the subscription list (if shareSubscriptions is true then when this.add(sub) is called this will in fact call subscriber.add(sub)).

To retain the chaining of subscribers when setting shareSubscriptions to false, add the created instance to subscriber via add.

Parameters
subscriber:Subscriber<?>

the other Subscriber

shareSubscriptions:boolean

true to share the subscription list in subscriber with this instance

Since
1.0.6

Method Detail

addback to summary
public final void add(Subscription s)

Adds a Subscription to this Subscriber's list of subscriptions if this list is not marked as unsubscribed. If the list is marked as unsubscribed, add will indicate this by explicitly unsubscribing the new Subscription as well.

Parameters
s:Subscription

the Subscription to add

addToRequestedback to summary
private void addToRequested(long n)
isUnsubscribedback to summary
public final boolean isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Indicates whether this Subscriber has unsubscribed from its list of subscriptions.

Returns:boolean

true if this Subscriber has unsubscribed from its subscriptions, false otherwise

Annotations
@Override
onStartback to summary
public void onStart()

This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber. Override this method to add any useful initialization to your subscription, for instance to initiate backpressure.

requestback to summary
protected final void request(long n)

Request a certain maximum number of emitted items from the Observable this Subscriber is subscribed to. This is a way of requesting backpressure. To disable backpressure, pass Long.MAX_VALUE to this method.

Requests are additive but if a sequence of requests totals more than Long.MAX_VALUE then Long.MAX_VALUE requests will be actioned and the extras may be ignored. Arriving at Long.MAX_VALUE by addition of requests cannot be assumed to disable backpressure. For example, the code below may result in Long.MAX_VALUE requests being actioned only.

request(100);
request(Long.MAX_VALUE-1);
Parameters
n:long

the maximum number of items you want the Observable to emit to the Subscriber at this time, or Long.MAX_VALUE if you want the Observable to emit items at its own pace

Exceptions
IllegalArgumentException:
if n is negative
setProducerback to summary
public void setProducer(Producer p)

If other subscriber is set (by calling constructor Subscriber(Subscriber) or Subscriber(Subscriber, boolean)) then this method calls setProducer on the other subscriber. If the other subscriber is not set and no requests have been made to this subscriber then p.request(Long.MAX_VALUE) is called. If the other subscriber is not set and some requests have been made to this subscriber then p.request(n) is called where n is the accumulated requests to this subscriber.

Parameters
p:Producer

producer to be used by this subscriber or the other subscriber (or recursively its other subscriber) to make requests from

unsubscribeback to summary
public final void unsubscribe()

Implements rx.Subscription.unsubscribe.

Doc from rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.

This allows deregistering an Subscriber before it has finished receiving all events (i.e. before onCompleted is called).

Annotations
@Override