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 Details

  • Constructor Details

    • SwitchableSubscriptionSubscriber

      public SwitchableSubscriptionSubscriber(MultiSubscriber<? super O> downstream)
  • Method Details

    • context

      public Context context()
      Description copied from interface: ContextSupport
      Provide a context.

      Since calls to this method shall only be triggered when a Mutiny pipeline uses a withContext operator, 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 withContext operator.

      Specified by:
      context in interface ContextSupport
      Returns:
      the context, must not be null.
    • cancel

      public void cancel()
      Specified by:
      cancel in interface Flow.Subscription
    • isCancelled

      public boolean isCancelled()
    • onCompletion

      public void onCompletion()
      Description copied from interface: MultiSubscriber
      Method called when the upstream emits a completion terminal event.

      No further events will be sent even if Flow.Subscription.request(long) is invoked again.

      Specified by:
      onCompletion in interface MultiSubscriber<O>
    • onFailure

      public void onFailure(Throwable t)
      Description copied from interface: MultiSubscriber
      Method called when the upstream emits a failure terminal event.

      No further events will be sent even if Flow.Subscription.request(long) is invoked again.

      Specified by:
      onFailure in interface MultiSubscriber<O>
      Parameters:
      t - the failure, must not be null.
    • onSubscribe

      public void onSubscribe(Flow.Subscription s)
      Specified by:
      onSubscribe in interface Flow.Subscriber<O>
    • emitted

      public void emitted(long n)
    • requested

      public long requested()
    • request

      public final void request(long n)
      Specified by:
      request in interface Flow.Subscription
    • setOrSwitchUpstream

      protected final void setOrSwitchUpstream(Flow.Subscription newUpstream)
    • cancelUpstreamOnSwitch

      protected boolean cancelUpstreamOnSwitch()
      Returns:
      true if we need to cancel the current subscription when we switch the upstreams.