Package rx.internal.operators
Class OperatorPublish.PublishSubscriber<T>
- java.lang.Object
-
- rx.Subscriber<T>
-
- rx.internal.operators.OperatorPublish.PublishSubscriber<T>
-
- All Implemented Interfaces:
Observer<T>,Subscription
- Enclosing class:
- OperatorPublish<T>
static final class OperatorPublish.PublishSubscriber<T> extends Subscriber<T> implements Subscription
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.atomic.AtomicReference<OperatorPublish.PublishSubscriber<T>>currentHolds onto the current connected PublishSubscriber.(package private) booleanemittingGuarded by this.(package private) static OperatorPublish.InnerProducer[]EMPTYIndicates an empty array of inner producers.(package private) booleanmissedGuarded by this.(package private) NotificationLite<T>nlThe notification-lite factory.(package private) java.util.concurrent.atomic.AtomicReference<OperatorPublish.InnerProducer[]>producersTracks the subscribed producers.(package private) java.util.Queue<java.lang.Object>queueHolds notifications from upstream.(package private) java.util.concurrent.atomic.AtomicBooleanshouldConnectAtomically changed from false to true by connect to make sure the connection is only performed by one thread.(package private) java.lang.ObjectterminalEventContains either an onCompleted or an onError token from upstream.(package private) static OperatorPublish.InnerProducer[]TERMINATEDIndicates a terminated PublishSubscriber.
-
Constructor Summary
Constructors Constructor Description PublishSubscriber(java.util.concurrent.atomic.AtomicReference<OperatorPublish.PublishSubscriber<T>> current)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleanadd(OperatorPublish.InnerProducer<T> producer)Atomically try adding a new InnerProducer to this Subscriber or return false if this Subscriber was terminated.(package private) booleancheckTerminated(java.lang.Object term, boolean empty)Perform termination actions in case the source has terminated in some way and the queue has also become empty.(package private) voiddispatch()The common serialization point of events arriving from upstream and child-subscribers requesting more.(package private) voidinit()Should be called after the constructor finished to setup nulling-out the current reference.voidonCompleted()Notifies the Observer that theObservablehas finished sending push-based notifications.voidonError(java.lang.Throwable e)Notifies the Observer that theObservablehas experienced an error condition.voidonNext(T t)Provides the Observer with a new item to observe.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.(package private) voidremove(OperatorPublish.InnerProducer<T> producer)Atomically removes the given producer from the producers array.-
Methods inherited from class rx.Subscriber
add, isUnsubscribed, request, setProducer, unsubscribe
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface rx.Subscription
isUnsubscribed, unsubscribe
-
-
-
-
Field Detail
-
queue
final java.util.Queue<java.lang.Object> queue
Holds notifications from upstream.
-
nl
final NotificationLite<T> nl
The notification-lite factory.
-
current
final java.util.concurrent.atomic.AtomicReference<OperatorPublish.PublishSubscriber<T>> current
Holds onto the current connected PublishSubscriber.
-
terminalEvent
volatile java.lang.Object terminalEvent
Contains either an onCompleted or an onError token from upstream.
-
EMPTY
static final OperatorPublish.InnerProducer[] EMPTY
Indicates an empty array of inner producers.
-
TERMINATED
static final OperatorPublish.InnerProducer[] TERMINATED
Indicates a terminated PublishSubscriber.
-
producers
final java.util.concurrent.atomic.AtomicReference<OperatorPublish.InnerProducer[]> producers
Tracks the subscribed producers.
-
shouldConnect
final java.util.concurrent.atomic.AtomicBoolean shouldConnect
Atomically changed from false to true by connect to make sure the connection is only performed by one thread.
-
emitting
boolean emitting
Guarded by this.
-
missed
boolean missed
Guarded by this.
-
-
Constructor Detail
-
PublishSubscriber
public PublishSubscriber(java.util.concurrent.atomic.AtomicReference<OperatorPublish.PublishSubscriber<T>> current)
-
-
Method Detail
-
init
void init()
Should be called after the constructor finished to setup nulling-out the current reference.
-
onStart
public void onStart()
Description copied from class:SubscriberThis 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.- Overrides:
onStartin classSubscriber<T>
-
onNext
public void onNext(T t)
Description copied from interface:ObserverProvides the Observer with a new item to observe.The
Observablemay call this method 0 or more times.The
Observablewill not call this method again after it calls eitherObserver.onCompleted()orObserver.onError(java.lang.Throwable).
-
onError
public void onError(java.lang.Throwable e)
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().
-
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).- Specified by:
onCompletedin interfaceObserver<T>
-
add
boolean add(OperatorPublish.InnerProducer<T> producer)
Atomically try adding a new InnerProducer to this Subscriber or return false if this Subscriber was terminated.- Parameters:
producer- the producer to add- Returns:
- true if succeeded, false otherwise
-
remove
void remove(OperatorPublish.InnerProducer<T> producer)
Atomically removes the given producer from the producers array.- Parameters:
producer- the producer to remove
-
checkTerminated
boolean checkTerminated(java.lang.Object term, boolean empty)Perform termination actions in case the source has terminated in some way and the queue has also become empty.- Parameters:
term- the terminal event (a NotificationLite.error or completed)empty- set to true if the queue is empty- Returns:
- true if there is indeed a terminal condition
-
dispatch
void dispatch()
The common serialization point of events arriving from upstream and child-subscribers requesting more.
-
-