Class CompletionStageSubscriber<U,​D>

  • Type Parameters:
    U - published upstream elements
    D - mapped downstream values
    All Implemented Interfaces:
    org.reactivestreams.Subscriber<U>
    Direct Known Subclasses:
    CompletionStageOrderedSubscriber

    public class CompletionStageSubscriber<U,​D>
    extends java.lang.Object
    implements org.reactivestreams.Subscriber<U>
    This subscriber can be used to map between a Publisher of U elements and map them into CompletionStage of D promises.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.reactivestreams.Subscription delegatingSubscription  
      protected org.reactivestreams.Subscriber<? super D> downstreamSubscriber  
      protected java.util.Queue<java.util.concurrent.CompletionStage<?>> inFlightDataQ  
      protected java.util.concurrent.atomic.AtomicBoolean isTerminal  
      protected LockKit.ReentrantLock lock  
      protected java.util.function.Function<U,​java.util.concurrent.CompletionStage<D>> mapper  
      protected java.util.concurrent.atomic.AtomicReference<java.lang.Runnable> onCompleteRun  
    • Constructor Summary

      Constructors 
      Constructor Description
      CompletionStageSubscriber​(java.util.function.Function<U,​java.util.concurrent.CompletionStage<D>> mapper, org.reactivestreams.Subscriber<? super D> downstreamSubscriber)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void finallyAfterEachPromiseFinishes​(boolean isInFlightEmpty)  
      org.reactivestreams.Subscriber<? super D> getDownstreamSubscriber()
      Get instance of downstream subscriber
      protected void handleThrowableDuringMapping​(java.lang.Throwable throwable)  
      protected boolean inFlightQIsEmpty()  
      protected boolean isTerminal()
      The two terminal states are onComplete or onError
      protected void offerToInFlightQ​(java.util.concurrent.CompletionStage<?> completionStage)  
      void onComplete()  
      void onError​(java.lang.Throwable t)  
      void onNext​(U u)  
      void onSubscribe​(org.reactivestreams.Subscription subscription)  
      protected void whenNextFinished​(java.util.concurrent.CompletionStage<D> completionStage, D d, java.lang.Throwable throwable)
      This is called as each mapped CompletionStage completes with a value or exception
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mapper

        protected final java.util.function.Function<U,​java.util.concurrent.CompletionStage<D>> mapper
      • downstreamSubscriber

        protected final org.reactivestreams.Subscriber<? super D> downstreamSubscriber
      • delegatingSubscription

        protected org.reactivestreams.Subscription delegatingSubscription
      • inFlightDataQ

        protected final java.util.Queue<java.util.concurrent.CompletionStage<?>> inFlightDataQ
      • onCompleteRun

        protected final java.util.concurrent.atomic.AtomicReference<java.lang.Runnable> onCompleteRun
      • isTerminal

        protected final java.util.concurrent.atomic.AtomicBoolean isTerminal
    • Constructor Detail

      • CompletionStageSubscriber

        public CompletionStageSubscriber​(java.util.function.Function<U,​java.util.concurrent.CompletionStage<D>> mapper,
                                         org.reactivestreams.Subscriber<? super D> downstreamSubscriber)
    • Method Detail

      • getDownstreamSubscriber

        public org.reactivestreams.Subscriber<? super D> getDownstreamSubscriber()
        Get instance of downstream subscriber
        Returns:
        Subscriber
      • onSubscribe

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

        public void onNext​(U u)
        Specified by:
        onNext in interface org.reactivestreams.Subscriber<U>
      • whenNextFinished

        protected void whenNextFinished​(java.util.concurrent.CompletionStage<D> completionStage,
                                        D d,
                                        java.lang.Throwable throwable)
        This is called as each mapped CompletionStage completes with a value or exception
        Parameters:
        completionStage - the completion stage that has completed
        d - the value completed
        throwable - or the throwable that happened during completion
      • finallyAfterEachPromiseFinishes

        protected void finallyAfterEachPromiseFinishes​(boolean isInFlightEmpty)
      • handleThrowableDuringMapping

        protected void handleThrowableDuringMapping​(java.lang.Throwable throwable)
      • onError

        public void onError​(java.lang.Throwable t)
        Specified by:
        onError in interface org.reactivestreams.Subscriber<U>
      • onComplete

        public void onComplete()
        Specified by:
        onComplete in interface org.reactivestreams.Subscriber<U>
      • offerToInFlightQ

        protected void offerToInFlightQ​(java.util.concurrent.CompletionStage<?> completionStage)
      • inFlightQIsEmpty

        protected boolean inFlightQIsEmpty()
      • isTerminal

        protected boolean isTerminal()
        The two terminal states are onComplete or onError
        Returns:
        true if it's in a terminal state