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>>
current
Holds onto the current connected PublishSubscriber.(package private) boolean
emitting
Guarded by this.(package private) static OperatorPublish.InnerProducer[]
EMPTY
Indicates an empty array of inner producers.(package private) boolean
missed
Guarded by this.(package private) NotificationLite<T>
nl
The notification-lite factory.(package private) java.util.concurrent.atomic.AtomicReference<OperatorPublish.InnerProducer[]>
producers
Tracks the subscribed producers.(package private) java.util.Queue<java.lang.Object>
queue
Holds notifications from upstream.(package private) 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.(package private) java.lang.Object
terminalEvent
Contains either an onCompleted or an onError token from upstream.(package private) static OperatorPublish.InnerProducer[]
TERMINATED
Indicates 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) boolean
add(OperatorPublish.InnerProducer<T> producer)
Atomically try adding a new InnerProducer to this Subscriber or return false if this Subscriber was terminated.(package private) 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.(package private) void
dispatch()
The common serialization point of events arriving from upstream and child-subscribers requesting more.(package private) void
init()
Should be called after the constructor finished to setup nulling-out the current reference.void
onCompleted()
Notifies the Observer that theObservable
has finished sending push-based notifications.void
onError(java.lang.Throwable e)
Notifies the Observer that theObservable
has experienced an error condition.void
onNext(T t)
Provides the Observer with a new item to observe.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.(package private) void
remove(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:Subscriber
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.- Overrides:
onStart
in classSubscriber<T>
-
onNext
public void onNext(T t)
Description copied from interface:Observer
Provides the Observer 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 eitherObserver.onCompleted()
orObserver.onError(java.lang.Throwable)
.
-
onError
public void onError(java.lang.Throwable e)
Description copied from interface:Observer
Notifies the Observer that theObservable
has experienced an error condition.If the
Observable
calls this method, it will not thereafter callObserver.onNext(T)
orObserver.onCompleted()
.
-
onCompleted
public void onCompleted()
Description copied from interface:Observer
Notifies the Observer that theObservable
has finished sending push-based notifications.The
Observable
will not call this method if it callsObserver.onError(java.lang.Throwable)
.- Specified by:
onCompleted
in 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.
-
-