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>,Flow.Subscriber<O>,Flow.Subscription
public abstract class SwitchableSubscriptionSubscriber<O>
extends Object
implements MultiSubscriber<O>, Flow.Subscription, ContextSupport
An implementation of
Flow.Subscription that 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
FieldsModifier and TypeFieldDescriptionprotected final AtomicReference<Flow.Subscription> The current upstreamprotected final MultiSubscriber<? super O> The downstream subscriber -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()protected booleancontext()Provide a context.voidemitted(long n) booleanvoidMethod called when the upstream emits acompletionterminal event.voidMethod called when the upstream emits afailureterminal event.voidfinal voidrequest(long n) longprotected final voidsetOrSwitchUpstream(Flow.Subscription newUpstream) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.smallrye.mutiny.subscription.MultiSubscriber
onComplete, onError, onItem, onNext
-
Field Details
-
downstream
The downstream subscriber -
currentUpstream
The current upstream
-
-
Constructor Details
-
SwitchableSubscriptionSubscriber
-
-
Method Details
-
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 interfaceFlow.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
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
- Specified by:
onSubscribein interfaceFlow.Subscriber<O>
-
emitted
public void emitted(long n) -
requested
public long requested() -
request
public final void request(long n) - Specified by:
requestin interfaceFlow.Subscription
-
setOrSwitchUpstream
-
cancelUpstreamOnSwitch
protected boolean cancelUpstreamOnSwitch()- Returns:
trueif we need to cancel the current subscription when we switch the upstreams.
-