Class SwitchableSubscriptionSubscriber<O>

  • Type Parameters:
    O - outgoing item type
    All Implemented Interfaces:
    MultiSubscriber<O>, org.reactivestreams.Subscriber<O>, org.reactivestreams.Subscription
    Direct Known Subclasses:
    MultiRepeatUntilOp.RepeatProcessor

    public abstract class SwitchableSubscriptionSubscriber<O>
    extends java.lang.Object
    implements MultiSubscriber<O>, org.reactivestreams.Subscription
    An implementation of 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 Detail

      • downstream

        protected final MultiSubscriber<? super O> downstream
        The downstream subscriber
      • currentUpstream

        protected final java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> currentUpstream
        The current upstream
    • Constructor Detail

      • SwitchableSubscriptionSubscriber

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

      • cancel

        public void cancel()
        Specified by:
        cancel in interface org.reactivestreams.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 Subscription.request(long) is invoked again.

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

        public void onFailure​(java.lang.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 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​(org.reactivestreams.Subscription s)
        Specified by:
        onSubscribe in interface org.reactivestreams.Subscriber<O>
      • emitted

        public void emitted​(long n)
      • request

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

        protected final void setOrSwitchUpstream​(org.reactivestreams.Subscription newUpstream)
      • cancelUpstreamOnSwitch

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