Class Subscriber<T>
- java.lang.Object
-
- rx.Subscriber<T>
-
- Type Parameters:
T- the type of items the Subscriber expects to observe
- All Implemented Interfaces:
Observer<T>,Subscription
- Direct Known Subclasses:
ActionSubscriber,BlockingOperatorLatest.LatestObserverIterator,BlockingOperatorMostRecent.MostRecentObserver,BlockingOperatorNext.NextObserver,BlockingOperatorToIterator.SubscriberIterator,CompletableOnSubscribeConcat.CompletableConcatSubscriber,CompletableOnSubscribeMerge.CompletableMergeSubscriber,DeferredScalarSubscriber,ObserverSubscriber,OnSubscribeAmb.AmbSubscriber,OnSubscribeCombineLatest.CombinerSubscriber,OnSubscribeConcatMap.ConcatMapInnerSubscriber,OnSubscribeConcatMap.ConcatMapSubscriber,OnSubscribeDetach.DetachSubscriber,OnSubscribeFilter.FilterSubscriber,OnSubscribeFlattenIterable.FlattenIterableSubscriber,OnSubscribeGroupJoin.ResultManager.LeftDurationObserver,OnSubscribeGroupJoin.ResultManager.LeftObserver,OnSubscribeGroupJoin.ResultManager.RightDurationObserver,OnSubscribeGroupJoin.ResultManager.RightObserver,OnSubscribeGroupJoin.WindowObservableFunc.WindowSubscriber,OnSubscribeJoin.ResultSink.LeftSubscriber,OnSubscribeJoin.ResultSink.LeftSubscriber.LeftDurationSubscriber,OnSubscribeJoin.ResultSink.RightSubscriber,OnSubscribeJoin.ResultSink.RightSubscriber.RightDurationSubscriber,OnSubscribeMap.MapSubscriber,OnSubscribeOnAssembly.OnAssemblySubscriber,OnSubscribePublishMulticast.ParentSubscriber,OnSubscribeReduce.ReduceSubscriber,OperatorBufferWithSingleObservable.BufferingSubscriber,OperatorBufferWithSize.BufferExact,OperatorBufferWithSize.BufferOverlap,OperatorBufferWithSize.BufferSkip,OperatorBufferWithStartEndObservable.BufferingSubscriber,OperatorBufferWithTime.ExactSubscriber,OperatorBufferWithTime.InexactSubscriber,OperatorCast.CastSubscriber,OperatorDoOnRequest.ParentSubscriber,OperatorEagerConcatMap.EagerInnerSubscriber,OperatorEagerConcatMap.EagerOuterSubscriber,OperatorGroupBy.GroupBySubscriber,OperatorMapNotification.MapNotificationSubscriber,OperatorMapPair.MapPairSubscriber,OperatorMaterialize.ParentSubscriber,OperatorMerge.InnerSubscriber,OperatorMerge.MergeSubscriber,OperatorObserveOn.ObserveOnSubscriber,OperatorOnBackpressureBuffer.BufferSubscriber,OperatorOnBackpressureLatest.LatestSubscriber,OperatorPublish.PublishSubscriber,OperatorReplay.ReplaySubscriber,OperatorRetryWithPredicate.SourceSubscriber,OperatorSampleWithTime.SamplerSubscriber,OperatorSingle.ParentSubscriber,OperatorSwitch.InnerSubscriber,OperatorSwitch.SwitchSubscriber,OperatorSwitchIfEmpty.AlternateSubscriber,OperatorSwitchIfEmpty.ParentSubscriber,OperatorTakeLast.TakeLastSubscriber,OperatorTakeLastTimed.TakeLastTimedSubscriber,OperatorTakeTimed.TakeSubscriber,OperatorTakeUntilPredicate.ParentSubscriber,OperatorTimeoutBase.TimeoutSubscriber,OperatorWindowWithObservable.BoundarySubscriber,OperatorWindowWithObservable.SourceSubscriber,OperatorWindowWithObservableFactory.BoundarySubscriber,OperatorWindowWithObservableFactory.SourceSubscriber,OperatorWindowWithSize.WindowExact,OperatorWindowWithSize.WindowOverlap,OperatorWindowWithSize.WindowSkip,OperatorWindowWithStartEndObservable.SourceSubscriber,OperatorWindowWithTime.ExactSubscriber,OperatorWindowWithTime.InexactSubscriber,OperatorWithLatestFromMany.WithLatestMainSubscriber,OperatorWithLatestFromMany.WithLatestOtherSubscriber,OperatorZip.Zip.InnerSubscriber,OperatorZip.ZipSubscriber,SafeSubscriber,SerializedSubscriber,TestSubscriber
public abstract class Subscriber<T> extends java.lang.Object implements Observer<T>, Subscription
Provides a mechanism for receiving push-based notifications from Observables, and permits manual unsubscribing from these Observables.After a Subscriber calls an
Observable'ssubscribemethod, theObservablecalls the Subscriber'sObserver.onNext(T)method to emit items. A well-behavedObservablewill call a Subscriber'sObserver.onCompleted()method exactly once or the Subscriber'sObserver.onError(java.lang.Throwable)method exactly once.- See Also:
- ReactiveX documentation: Observable
-
-
Field Summary
Fields Modifier and Type Field Description private static longNOT_SETprivate Producerproducerprivate longrequestedprivate Subscriber<?>subscriberprivate SubscriptionListsubscriptions
-
Constructor Summary
Constructors Modifier Constructor Description protectedSubscriber()protectedSubscriber(Subscriber<?> subscriber)Construct a Subscriber by using another Subscriber for backpressure and for holding the subscription list (whenthis.add(sub)is called this will in fact callsubscriber.add(sub)).protectedSubscriber(Subscriber<?> subscriber, boolean shareSubscriptions)Construct a Subscriber by using another Subscriber for backpressure and optionally for holding the subscription list (ifshareSubscriptionsistruethen whenthis.add(sub)is called this will in fact callsubscriber.add(sub)).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Subscription s)Adds aSubscriptionto this Subscriber's list of subscriptions if this list is not marked as unsubscribed.private voidaddToRequested(long n)booleanisUnsubscribed()Indicates whether this Subscriber has unsubscribed from its list of subscriptions.voidonStart()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 voidrequest(long n)Request a certain maximum number of emitted items from the Observable this Subscriber is subscribed to.voidsetProducer(Producer p)If other subscriber is set (by calling constructorSubscriber(Subscriber)orSubscriber(Subscriber, boolean)) then this method callssetProduceron the other subscriber.voidunsubscribe()Stops the receipt of notifications on theSubscriberthat was registered when this Subscription was received.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface rx.Observer
onCompleted, onError, onNext
-
-
-
-
Field Detail
-
NOT_SET
private static final long NOT_SET
- See Also:
- Constant Field Values
-
subscriptions
private final SubscriptionList subscriptions
-
subscriber
private final Subscriber<?> subscriber
-
producer
private Producer producer
-
requested
private long requested
-
-
Constructor Detail
-
Subscriber
protected Subscriber()
-
Subscriber
protected Subscriber(Subscriber<?> subscriber)
Construct a Subscriber by using another Subscriber for backpressure and for holding the subscription list (whenthis.add(sub)is called this will in fact callsubscriber.add(sub)).- Parameters:
subscriber- the other Subscriber
-
Subscriber
protected Subscriber(Subscriber<?> subscriber, boolean shareSubscriptions)
Construct a Subscriber by using another Subscriber for backpressure and optionally for holding the subscription list (ifshareSubscriptionsistruethen whenthis.add(sub)is called this will in fact callsubscriber.add(sub)).To retain the chaining of subscribers when setting
shareSubscriptionstofalse, add the created instance tosubscriberviaadd(rx.Subscription).- Parameters:
subscriber- the other SubscribershareSubscriptions-trueto share the subscription list insubscriberwith this instance- Since:
- 1.0.6
-
-
Method Detail
-
add
public final void add(Subscription s)
Adds aSubscriptionto this Subscriber's list of subscriptions if this list is not marked as unsubscribed. If the list is marked as unsubscribed,addwill indicate this by explicitly unsubscribing the newSubscriptionas well.- Parameters:
s- theSubscriptionto add
-
unsubscribe
public final void unsubscribe()
Description copied from interface:SubscriptionStops the receipt of notifications on theSubscriberthat was registered when this Subscription was received.This allows unregistering an
Subscriberbefore it has finished receiving all events (i.e. before onCompleted is called).- Specified by:
unsubscribein interfaceSubscription
-
isUnsubscribed
public final boolean isUnsubscribed()
Indicates whether this Subscriber has unsubscribed from its list of subscriptions.- Specified by:
isUnsubscribedin interfaceSubscription- Returns:
trueif this Subscriber has unsubscribed from its subscriptions,falseotherwise
-
onStart
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.
-
request
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, passLong.MAX_VALUEto this method.Requests are additive but if a sequence of requests totals more than
Long.MAX_VALUEthenLong.MAX_VALUErequests will be actioned and the extras may be ignored. Arriving atLong.MAX_VALUEby addition of requests cannot be assumed to disable backpressure. For example, the code below may result inLong.MAX_VALUErequests being actioned only.request(100); request(Long.MAX_VALUE-1);
- Parameters:
n- the maximum number of items you want the Observable to emit to the Subscriber at this time, orLong.MAX_VALUEif you want the Observable to emit items at its own pace- Throws:
java.lang.IllegalArgumentException- ifnis negative
-
addToRequested
private void addToRequested(long n)
-
setProducer
public void setProducer(Producer p)
If other subscriber is set (by calling constructorSubscriber(Subscriber)orSubscriber(Subscriber, boolean)) then this method callssetProduceron the other subscriber. If the other subscriber is not set and no requests have been made to this subscriber thenp.request(Long.MAX_VALUE)is called. If the other subscriber is not set and some requests have been made to this subscriber thenp.request(n)is called where n is the accumulated requests to this subscriber.- Parameters:
p- producer to be used by this subscriber or the other subscriber (or recursively its other subscriber) to make requests from
-
-