Package rx.observers
Class SerializedObserver<T>
- java.lang.Object
-
- rx.observers.SerializedObserver<T>
-
- Type Parameters:
T- the type of items expected to be observed by theObserver
- All Implemented Interfaces:
Observer<T>
public class SerializedObserver<T> extends java.lang.Object implements Observer<T>
Enforces single-threaded, serialized, ordered execution ofonNext(T),onCompleted(), andonError(java.lang.Throwable).When multiple threads are emitting and/or notifying they will be serialized by:
- Allowing only one thread at a time to emit
- Adding notifications to a queue if another thread is already emitting
- Not holding any locks or blocking any threads while emitting
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classSerializedObserver.FastList
-
Field Summary
Fields Modifier and Type Field Description private Observer<? super T>actualprivate booleanemittingprivate NotificationLite<T>nlprivate SerializedObserver.FastListqueueIf not null, it indicates more work.private booleanterminatedSet to true if a terminal event was received.
-
Constructor Summary
Constructors Constructor Description SerializedObserver(Observer<? super T> s)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
Field Detail
-
emitting
private boolean emitting
-
terminated
private volatile boolean terminated
Set to true if a terminal event was received.
-
queue
private SerializedObserver.FastList queue
If not null, it indicates more work.
-
nl
private final NotificationLite<T> nl
-
-
Method Detail
-
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>
-
-