Class BasicFuseableObserver<T,R>
- java.lang.Object
-
- io.reactivex.rxjava3.internal.observers.BasicFuseableObserver<T,R>
-
- Type Parameters:
T- the upstream value typeR- the downstream value type
- All Implemented Interfaces:
Observer<T>,Disposable,QueueDisposable<R>,QueueFuseable<R>,SimpleQueue<R>
- Direct Known Subclasses:
ObservableDistinct.DistinctObserver,ObservableDistinctUntilChanged.DistinctUntilChangedObserver,ObservableDoAfterNext.DoAfterObserver,ObservableFilter.FilterObserver,ObservableMap.MapObserver,ObservableMapOptional.MapOptionalObserver
public abstract class BasicFuseableObserver<T,R> extends java.lang.Object implements Observer<T>, QueueDisposable<R>
Base class for a fuseable intermediate observer.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandoneFlag indicating no further onXXX event should be accepted.protected Observer<? super R>downstreamThe downstream subscriber.protected QueueDisposable<T>qdThe upstream's QueueDisposable if not null.protected intsourceModeHolds the established fusion mode of the upstream.protected DisposableupstreamThe upstream subscription.
-
Constructor Summary
Constructors Constructor Description BasicFuseableObserver(Observer<? super R> downstream)Construct a BasicFuseableObserver by wrapping the given subscriber.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterDownstream()Override this to perform actions after the call toactual.onSubscribe(this)happened.protected booleanbeforeDownstream()Override this to perform actions before the callactual.onSubscribe(this)happens.voidclear()Removes all enqueued items from this queue.voiddispose()Dispose the resource, the operation should be idempotent.protected voidfail(java.lang.Throwable t)Rethrows the throwable if it is a fatal exception or callsonError(Throwable).booleanisDisposed()Returns true if this resource has been disposed.booleanisEmpty()Returns true if the queue is empty.booleanoffer(R e)Atomically enqueue a single value.booleanoffer(R v1, R v2)Atomically enqueue two values.voidonComplete()Notifies theObserverthat theObservablehas finished sending push-based notifications.voidonError(java.lang.Throwable t)Notifies theObserverthat theObservablehas experienced an error condition.voidonSubscribe(Disposable d)Provides theObserverwith the means of cancelling (disposing) the connection (channel) with theObservablein both synchronous (from withinObserver.onNext(Object)) and asynchronous manner.protected inttransitiveBoundaryFusion(int mode)Calls the upstream's QueueDisposable.requestFusion with the mode and saves the established mode insourceModeif that mode doesn't have theQueueFuseable.BOUNDARYflag set.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.reactivex.rxjava3.operators.QueueFuseable
requestFusion
-
Methods inherited from interface io.reactivex.rxjava3.operators.SimpleQueue
poll
-
-
-
-
Field Detail
-
upstream
protected Disposable upstream
The upstream subscription.
-
qd
protected QueueDisposable<T> qd
The upstream's QueueDisposable if not null.
-
done
protected boolean done
Flag indicating no further onXXX event should be accepted.
-
sourceMode
protected int sourceMode
Holds the established fusion mode of the upstream.
-
-
Method Detail
-
onSubscribe
public final void onSubscribe(Disposable d)
Description copied from interface:ObserverProvides theObserverwith the means of cancelling (disposing) the connection (channel) with theObservablein both synchronous (from withinObserver.onNext(Object)) and asynchronous manner.- Specified by:
onSubscribein interfaceObserver<T>- Parameters:
d- theDisposableinstance whoseDisposable.dispose()can be called anytime to cancel the connection
-
beforeDownstream
protected boolean beforeDownstream()
Override this to perform actions before the callactual.onSubscribe(this)happens.- Returns:
- true if onSubscribe should continue with the call
-
afterDownstream
protected void afterDownstream()
Override this to perform actions after the call toactual.onSubscribe(this)happened.
-
onError
public void onError(java.lang.Throwable t)
Description copied from interface:ObserverNotifies theObserverthat theObservablehas experienced an error condition.If the
Observablecalls this method, it will not thereafter callObserver.onNext(T)orObserver.onComplete().
-
fail
protected final void fail(java.lang.Throwable t)
Rethrows the throwable if it is a fatal exception or callsonError(Throwable).- Parameters:
t- the throwable to rethrow or signal to the actual subscriber
-
onComplete
public void onComplete()
Description copied from interface:ObserverNotifies theObserverthat theObservablehas finished sending push-based notifications.The
Observablewill not call this method if it callsObserver.onError(java.lang.Throwable).- Specified by:
onCompletein interfaceObserver<T>
-
transitiveBoundaryFusion
protected final int transitiveBoundaryFusion(int mode)
Calls the upstream's QueueDisposable.requestFusion with the mode and saves the established mode insourceModeif that mode doesn't have theQueueFuseable.BOUNDARYflag set.If the upstream doesn't support fusion (
qdis null), the method returnsQueueFuseable.NONE.- Parameters:
mode- the fusion mode requested- Returns:
- the established fusion mode
-
dispose
public void dispose()
Description copied from interface:DisposableDispose the resource, the operation should be idempotent.- Specified by:
disposein interfaceDisposable
-
isDisposed
public boolean isDisposed()
Description copied from interface:DisposableReturns true if this resource has been disposed.- Specified by:
isDisposedin interfaceDisposable- Returns:
- true if this resource has been disposed
-
isEmpty
public boolean isEmpty()
Description copied from interface:SimpleQueueReturns true if the queue is empty.Note however that due to potential fused functions in
SimpleQueue.poll()it is possible this method returns false but then poll() returns null because the fused function swallowed the available item(s).- Specified by:
isEmptyin interfaceSimpleQueue<T>- Returns:
- true if the queue is empty
-
clear
public void clear()
Description copied from interface:SimpleQueueRemoves all enqueued items from this queue.- Specified by:
clearin interfaceSimpleQueue<T>
-
offer
public final boolean offer(R e)
Description copied from interface:SimpleQueueAtomically enqueue a single value.- Specified by:
offerin interfaceSimpleQueue<T>- Parameters:
e- the value to enqueue, not null- Returns:
- true if successful, false if the value was not enqueued likely due to reaching the queue capacity)
-
offer
public final boolean offer(R v1, R v2)
Description copied from interface:SimpleQueueAtomically enqueue two values.- Specified by:
offerin interfaceSimpleQueue<T>- Parameters:
v1- the first value to enqueue, not nullv2- the second value to enqueue, not null- Returns:
- true if successful, false if the value was not enqueued likely due to reaching the queue capacity)
-
-