Package rx.internal.operators
Class DeferredScalarSubscriber<T,R>
- java.lang.Object
-
- rx.Subscriber<T>
-
- rx.internal.operators.DeferredScalarSubscriber<T,R>
-
- Type Parameters:
T- the source value typeR- the result value type
- All Implemented Interfaces:
Observer<T>,Subscription
- Direct Known Subclasses:
OnSubscribeCollect.CollectSubscriber,OnSubscribeReduceSeed.ReduceSeedSubscriber,OnSubscribeTakeLastOne.TakeLastOneSubscriber
public abstract class DeferredScalarSubscriber<T,R> extends Subscriber<T>
Base class for Subscribers that consume the entire upstream and signal zero or one element (or an error) in a backpressure honoring fashion.Store any temporary value in
valueand indicate there is a value available when completing by settinghasValue.subscribeTo(Observable)to properly setup the link between this and the downstream subscriber.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classDeferredScalarSubscriber.InnerProducerRedirects the downstream request amount bach to the DeferredScalarSubscriber.
-
Field Summary
Fields Modifier and Type Field Description protected Subscriber<? super R>actualThe downstream subscriber.(package private) static intHAS_REQUEST_HAS_VALUEValue will be emitted.(package private) static intHAS_REQUEST_NO_VALUERequest came first.protected booleanhasValueIndicates there is a value available in value.(package private) static intNO_REQUEST_HAS_VALUEValue came first.(package private) static intNO_REQUEST_NO_VALUEInitial state.(package private) java.util.concurrent.atomic.AtomicIntegerstateThe state, see the constants below.protected RvalueThe holder of the single value.
-
Constructor Summary
Constructors Constructor Description DeferredScalarSubscriber(Subscriber<? super R> actual)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcomplete()Signals onCompleted() to the downstream subscriber.protected voidcomplete(R value)Atomically switches to the terminal state and emits the value if there is a request for it or stores it for retrieval bydownstreamRequest(long).(package private) voiddownstreamRequest(long n)voidonCompleted()Notifies the Observer that theObservablehas finished sending push-based notifications.voidonError(java.lang.Throwable ex)Notifies the Observer that theObservablehas experienced an error condition.voidsetProducer(Producer p)If other subscriber is set (by calling constructorSubscriber(Subscriber)orSubscriber(Subscriber, boolean)) then this method callssetProduceron the other subscriber.(package private) voidsetupDownstream()voidsubscribeTo(Observable<? extends T> source)Links up with the downstream Subscriber (cancellation, backpressure) and subscribes to the source Observable.-
Methods inherited from class rx.Subscriber
add, isUnsubscribed, onStart, request, unsubscribe
-
-
-
-
Field Detail
-
actual
protected final Subscriber<? super R> actual
The downstream subscriber.
-
hasValue
protected boolean hasValue
Indicates there is a value available in value.
-
value
protected R value
The holder of the single value.
-
state
final java.util.concurrent.atomic.AtomicInteger state
The state, see the constants below.
-
NO_REQUEST_NO_VALUE
static final int NO_REQUEST_NO_VALUE
Initial state.- See Also:
- Constant Field Values
-
HAS_REQUEST_NO_VALUE
static final int HAS_REQUEST_NO_VALUE
Request came first.- See Also:
- Constant Field Values
-
NO_REQUEST_HAS_VALUE
static final int NO_REQUEST_HAS_VALUE
Value came first.- See Also:
- Constant Field Values
-
HAS_REQUEST_HAS_VALUE
static final int HAS_REQUEST_HAS_VALUE
Value will be emitted.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DeferredScalarSubscriber
public DeferredScalarSubscriber(Subscriber<? super R> actual)
-
-
Method Detail
-
onError
public void onError(java.lang.Throwable ex)
Description copied from interface:ObserverNotifies the Observer that theObservablehas experienced an error condition.If the
Observablecalls this method, it will not thereafter callObserver.onNext(T)orObserver.onCompleted().- Parameters:
ex- the exception encountered by the Observable
-
onCompleted
public void onCompleted()
Description copied from interface:ObserverNotifies the Observer that theObservablehas finished sending push-based notifications.The
Observablewill not call this method if it callsObserver.onError(java.lang.Throwable).
-
complete
protected final void complete()
Signals onCompleted() to the downstream subscriber.
-
complete
protected final void complete(R value)
Atomically switches to the terminal state and emits the value if there is a request for it or stores it for retrieval bydownstreamRequest(long).- Parameters:
value- the value to complete with
-
downstreamRequest
final void downstreamRequest(long n)
-
setProducer
public final void setProducer(Producer p)
Description copied from class:SubscriberIf 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.- Overrides:
setProducerin classSubscriber<T>- Parameters:
p- producer to be used by this subscriber or the other subscriber (or recursively its other subscriber) to make requests from
-
subscribeTo
public final void subscribeTo(Observable<? extends T> source)
Links up with the downstream Subscriber (cancellation, backpressure) and subscribes to the source Observable.- Parameters:
source- the source Observable
-
setupDownstream
final void setupDownstream()
-
-