Class BaseSubscriberAdapter<T,​U>

  • Type Parameters:
    T - the type that the delegate subscriber demands.
    U - the type sent by the publisher this subscriber is subscribed to.
    All Implemented Interfaces:
    org.reactivestreams.Subscriber<T>
    Direct Known Subclasses:
    DelegatingBufferingSubscriber, FlatteningSubscriber

    public abstract class BaseSubscriberAdapter<T,​U>
    extends DelegatingSubscriber<T,​U>
    Base of subscribers that can adapt one type to another. This subscriber will receive onNext signal with the U type, but will need to fulfill the downstream demand of the delegate subscriber with instance of the T type.
    • Field Detail

      • upstreamDemand

        protected final AtomicLong upstreamDemand
        The amount of unfulfilled demand open against the upstream subscriber.
      • downstreamDemand

        protected final AtomicLong downstreamDemand
        The amount of unfulfilled demand the downstream subscriber has opened against us.
      • handlingStateUpdate

        protected final AtomicBoolean handlingStateUpdate
        A flag that is used to ensure that only one thread is handling updates to the state of this subscriber at a time. This allows us to ensure that the downstream onNext, onComplete and onError are only ever invoked serially.
      • onErrorFromUpstream

        protected final AtomicReference<Throwable> onErrorFromUpstream
        Whether the upstream subscriber has called onError on us. If this is null, we haven't gotten an onError. If it's non-null this will be the exception that the upstream passed to our onError. After we get an onError, we'll call onError on the downstream subscriber as soon as possible.
      • terminalCallMadeDownstream

        protected volatile boolean terminalCallMadeDownstream
        Whether we have called onComplete or onNext on the downstream subscriber.
      • onCompleteCalledByUpstream

        protected volatile boolean onCompleteCalledByUpstream
        Whether the upstream subscriber has called onComplete on us. After this happens, we'll drain any outstanding items in the allItems queue and then call onComplete on the downstream subscriber.
      • upstreamSubscription

        protected org.reactivestreams.Subscription upstreamSubscription
        The subscription to the upstream subscriber.
    • Constructor Detail

      • BaseSubscriberAdapter

        protected BaseSubscriberAdapter​(org.reactivestreams.Subscriber<? super U> subscriber)
    • Method Detail

      • fulfillDownstreamDemand

        protected abstract void fulfillDownstreamDemand()
        This method is called when demand from the downstream subscriber needs to be fulfilled. Called in a loop until downstreamDemand is no longer needed. Implementations are responsible for decrementing the downstreamDemand accordingly as demand gets fulfilled.
      • onSubscribe

        public void onSubscribe​(org.reactivestreams.Subscription subscription)
        Specified by:
        onSubscribe in interface org.reactivestreams.Subscriber<T>
        Overrides:
        onSubscribe in class DelegatingSubscriber<T,​U>
      • onNext

        public void onNext​(T item)
      • onComplete

        public void onComplete()
        Specified by:
        onComplete in interface org.reactivestreams.Subscriber<T>
        Overrides:
        onComplete in class DelegatingSubscriber<T,​U>
      • handleStateUpdate

        protected void handleStateUpdate()
        This is invoked after each downstream request or upstream onNext, onError or onComplete.