Module io.smallrye.mutiny
Package io.smallrye.mutiny.subscription
Class SwitchableSubscriptionSubscriber<O>
- java.lang.Object
-
- io.smallrye.mutiny.subscription.SwitchableSubscriptionSubscriber<O>
-
- Type Parameters:
O- outgoing item type
- All Implemented Interfaces:
ContextSupport,MultiSubscriber<O>,java.util.concurrent.Flow.Subscriber<O>,java.util.concurrent.Flow.Subscription
public abstract class SwitchableSubscriptionSubscriber<O> extends java.lang.Object implements MultiSubscriber<O>, java.util.concurrent.Flow.Subscription, ContextSupport
An implementation ofFlow.Subscriptionthat allows switching the upstream, dealing with the requests accordingly.You must invoke
emitted(long)after delivered items to manage the request per subscription consistently.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicReference<java.util.concurrent.Flow.Subscription>currentUpstreamThe current upstreamprotected MultiSubscriber<? super O>downstreamThe downstream subscriber
-
Constructor Summary
Constructors Constructor Description SwitchableSubscriptionSubscriber(MultiSubscriber<? super O> downstream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()protected booleancancelUpstreamOnSwitch()Contextcontext()Provide a context.voidemitted(long n)booleanisCancelled()voidonCompletion()Method called when the upstream emits acompletionterminal event.voidonFailure(java.lang.Throwable t)Method called when the upstream emits afailureterminal event.voidonSubscribe(java.util.concurrent.Flow.Subscription s)voidrequest(long n)longrequested()protected voidsetOrSwitchUpstream(java.util.concurrent.Flow.Subscription newUpstream)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.smallrye.mutiny.subscription.MultiSubscriber
onComplete, onError, onItem, onNext
-
-
-
-
Field Detail
-
downstream
protected final MultiSubscriber<? super O> downstream
The downstream subscriber
-
currentUpstream
protected final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.Flow.Subscription> currentUpstream
The current upstream
-
-
Constructor Detail
-
SwitchableSubscriptionSubscriber
public SwitchableSubscriptionSubscriber(MultiSubscriber<? super O> downstream)
-
-
Method Detail
-
context
public Context context()
Description copied from interface:ContextSupportProvide a context.Since calls to this method shall only be triggered when a Mutiny pipeline uses a
withContextoperator, there is no need in general for caching the context value in a field of the implementing class. Exceptions include operators that have cross-subscriber semantics such as memoizers or broadcasters.This method is expected to be called once per
withContextoperator.- Specified by:
contextin interfaceContextSupport- Returns:
- the context, must not be
null.
-
cancel
public void cancel()
- Specified by:
cancelin interfacejava.util.concurrent.Flow.Subscription
-
isCancelled
public boolean isCancelled()
-
onCompletion
public void onCompletion()
Description copied from interface:MultiSubscriberMethod called when the upstream emits acompletionterminal event.No further events will be sent even if
Flow.Subscription.request(long)is invoked again.- Specified by:
onCompletionin interfaceMultiSubscriber<O>
-
onFailure
public void onFailure(java.lang.Throwable t)
Description copied from interface:MultiSubscriberMethod called when the upstream emits afailureterminal event.No further events will be sent even if
Flow.Subscription.request(long)is invoked again.- Specified by:
onFailurein interfaceMultiSubscriber<O>- Parameters:
t- the failure, must not benull.
-
onSubscribe
public void onSubscribe(java.util.concurrent.Flow.Subscription s)
- Specified by:
onSubscribein interfacejava.util.concurrent.Flow.Subscriber<O>
-
emitted
public void emitted(long n)
-
requested
public long requested()
-
request
public final void request(long n)
- Specified by:
requestin interfacejava.util.concurrent.Flow.Subscription
-
setOrSwitchUpstream
protected final void setOrSwitchUpstream(java.util.concurrent.Flow.Subscription newUpstream)
-
cancelUpstreamOnSwitch
protected boolean cancelUpstreamOnSwitch()
- Returns:
trueif we need to cancel the current subscription when we switch the upstreams.
-
-