Class BasicFuseableSubscriber<T,R>
- java.lang.Object
-
- io.reactivex.rxjava3.internal.subscribers.BasicFuseableSubscriber<T,R>
-
- Type Parameters:
T- the upstream value typeR- the downstream value type
- All Implemented Interfaces:
FlowableSubscriber<T>,QueueFuseable<R>,QueueSubscription<R>,SimpleQueue<R>,org.reactivestreams.Subscriber<T>,org.reactivestreams.Subscription
- Direct Known Subclasses:
FlowableDistinct.DistinctSubscriber,FlowableDistinctUntilChanged.DistinctUntilChangedSubscriber,FlowableDoAfterNext.DoAfterSubscriber,FlowableDoOnEach.DoOnEachSubscriber,FlowableFilter.FilterSubscriber,FlowableMap.MapSubscriber,FlowableMapOptional.MapOptionalSubscriber
public abstract class BasicFuseableSubscriber<T,R> extends java.lang.Object implements FlowableSubscriber<T>, QueueSubscription<R>
Base class for a fuseable intermediate subscriber.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandoneFlag indicating no further onXXX event should be accepted.protected org.reactivestreams.Subscriber<? super R>downstreamThe downstream subscriber.protected QueueSubscription<T>qsThe upstream's QueueSubscription if not null.protected intsourceModeHolds the established fusion mode of the upstream.protected org.reactivestreams.SubscriptionupstreamThe upstream subscription.
-
Constructor Summary
Constructors Constructor Description BasicFuseableSubscriber(org.reactivestreams.Subscriber<? super R> downstream)Construct a BasicFuseableSubscriber 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.voidcancel()voidclear()Removes all enqueued items from this queue.protected voidfail(java.lang.Throwable t)Rethrows the throwable if it is a fatal exception or callsonError(Throwable).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()voidonError(java.lang.Throwable t)voidonSubscribe(org.reactivestreams.Subscription s)Implementors of this method should make sure everything that needs to be visible inSubscriber.onNext(Object)is established before callingSubscription.request(long).voidrequest(long n)protected inttransitiveBoundaryFusion(int mode)Calls the upstream's QueueSubscription.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
-
downstream
protected final org.reactivestreams.Subscriber<? super R> downstream
The downstream subscriber.
-
upstream
protected org.reactivestreams.Subscription upstream
The upstream subscription.
-
qs
protected QueueSubscription<T> qs
The upstream's QueueSubscription 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.
-
-
Constructor Detail
-
BasicFuseableSubscriber
public BasicFuseableSubscriber(org.reactivestreams.Subscriber<? super R> downstream)
Construct a BasicFuseableSubscriber by wrapping the given subscriber.- Parameters:
downstream- the subscriber, not null (not verified)
-
-
Method Detail
-
onSubscribe
public final void onSubscribe(org.reactivestreams.Subscription s)
Description copied from interface:FlowableSubscriberImplementors of this method should make sure everything that needs to be visible inSubscriber.onNext(Object)is established before callingSubscription.request(long). In practice this means no initialization should happen after therequest()call and additional behavior is thread safe in respect toonNext.- Specified by:
onSubscribein interfaceFlowableSubscriber<T>- Specified by:
onSubscribein interfaceorg.reactivestreams.Subscriber<T>
-
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)
- Specified by:
onErrorin interfaceorg.reactivestreams.Subscriber<T>
-
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()
- Specified by:
onCompletein interfaceorg.reactivestreams.Subscriber<T>
-
transitiveBoundaryFusion
protected final int transitiveBoundaryFusion(int mode)
Calls the upstream's QueueSubscription.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 (
qsis null), the method returnsQueueFuseable.NONE.- Parameters:
mode- the fusion mode requested- Returns:
- the established fusion mode
-
request
public void request(long n)
- Specified by:
requestin interfaceorg.reactivestreams.Subscription
-
cancel
public void cancel()
- Specified by:
cancelin interfaceorg.reactivestreams.Subscription
-
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)
-
-