Package rx.internal.operators
Class OperatorReplay.ReplaySubscriber<T>
- java.lang.Object
-
- rx.Subscriber<T>
-
- rx.internal.operators.OperatorReplay.ReplaySubscriber<T>
-
- All Implemented Interfaces:
Observer<T>,Subscription
- Enclosing class:
- OperatorReplay<T>
static final class OperatorReplay.ReplaySubscriber<T> extends Subscriber<T> implements Subscription
-
-
Field Summary
Fields Modifier and Type Field Description (package private) OperatorReplay.ReplayBuffer<T>bufferHolds notifications from upstream.(package private) booleancoordinateAllIndicate that all request amounts should be considered.(package private) java.util.List<OperatorReplay.InnerProducer<T>>coordinationQueueThe queue that holds producers with request changes that need to be coordinated.(package private) booleandoneContains either an onCompleted or an onError token from upstream.(package private) booleanemittingGuarded by this.(package private) static OperatorReplay.InnerProducer[]EMPTYIndicates an empty array of inner producers.(package private) longmaxChildRequestedContains the maximum element index the child Subscribers requested so far.(package private) longmaxUpstreamRequestedCounts the outstanding upstream requests until the producer arrives.(package private) booleanmissedGuarded by this.(package private) NotificationLite<T>nlThe notification-lite factory.(package private) ProducerproducerThe upstream producer.(package private) OpenHashSet<OperatorReplay.InnerProducer<T>>producersTracks the subscribed producers.(package private) OperatorReplay.InnerProducer<T>[]producersCacheContains a copy of the producers.(package private) longproducersCacheVersionContains the number of modifications that the producersCache holds.(package private) longproducersVersionContains number of modifications to the producers set.(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) booleanterminatedIndicates no further InnerProducers are accepted.(package private) static OperatorReplay.InnerProducer[]TERMINATEDIndicates a terminated ReplaySubscriber.
-
Constructor Summary
Constructors Constructor Description ReplaySubscriber(OperatorReplay.ReplayBuffer<T> buffer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleanadd(OperatorReplay.InnerProducer<T> producer)Atomically try adding a new InnerProducer to this Subscriber or return false if this Subscriber was terminated.(package private) OperatorReplay.InnerProducer<T>[]copyProducers()(package private) voidinit()Should be called after the constructor finished to setup nulling-out the current reference.(package private) voidmakeRequest(long maxTotalRequests, long previousTotalRequests)(package private) voidmanageRequests(OperatorReplay.InnerProducer<T> inner)Coordinates the request amounts of various child Subscribers.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.(package private) voidremove(OperatorReplay.InnerProducer<T> producer)Atomically removes the given producer from the producers array.(package private) voidreplay()Tries to replay the buffer contents to all known subscribers.voidsetProducer(Producer p)If other subscriber is set (by calling constructorSubscriber(Subscriber)orSubscriber(Subscriber, boolean)) then this method callssetProduceron the other subscriber.-
Methods inherited from class rx.Subscriber
add, isUnsubscribed, onStart, request, 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
-
buffer
final OperatorReplay.ReplayBuffer<T> buffer
Holds notifications from upstream.
-
nl
final NotificationLite<T> nl
The notification-lite factory.
-
done
boolean done
Contains either an onCompleted or an onError token from upstream.
-
EMPTY
static final OperatorReplay.InnerProducer[] EMPTY
Indicates an empty array of inner producers.
-
TERMINATED
static final OperatorReplay.InnerProducer[] TERMINATED
Indicates a terminated ReplaySubscriber.
-
terminated
volatile boolean terminated
Indicates no further InnerProducers are accepted.
-
producers
final OpenHashSet<OperatorReplay.InnerProducer<T>> producers
Tracks the subscribed producers. Guarded by itself.
-
producersCache
OperatorReplay.InnerProducer<T>[] producersCache
Contains a copy of the producers. Modified only from the source side.
-
producersVersion
volatile long producersVersion
Contains number of modifications to the producers set.
-
producersCacheVersion
long producersCacheVersion
Contains the number of modifications that the producersCache holds.
-
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.
-
maxChildRequested
long maxChildRequested
Contains the maximum element index the child Subscribers requested so far. Accessed while emitting is true.
-
maxUpstreamRequested
long maxUpstreamRequested
Counts the outstanding upstream requests until the producer arrives.
-
producer
volatile Producer producer
The upstream producer.
-
coordinationQueue
java.util.List<OperatorReplay.InnerProducer<T>> coordinationQueue
The queue that holds producers with request changes that need to be coordinated.
-
coordinateAll
boolean coordinateAll
Indicate that all request amounts should be considered.
-
-
Constructor Detail
-
ReplaySubscriber
public ReplaySubscriber(OperatorReplay.ReplayBuffer<T> buffer)
-
-
Method Detail
-
init
void init()
Should be called after the constructor finished to setup nulling-out the current reference.
-
add
boolean add(OperatorReplay.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(OperatorReplay.InnerProducer<T> producer)
Atomically removes the given producer from the producers array.- Parameters:
producer- the producer to remove
-
setProducer
public 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
-
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>
-
manageRequests
void manageRequests(OperatorReplay.InnerProducer<T> inner)
Coordinates the request amounts of various child Subscribers.
-
copyProducers
OperatorReplay.InnerProducer<T>[] copyProducers()
-
makeRequest
void makeRequest(long maxTotalRequests, long previousTotalRequests)
-
replay
void replay()
Tries to replay the buffer contents to all known subscribers.
-
-