Module methanol

Class AbstractSubscription<T>

  • All Implemented Interfaces:
    java.util.concurrent.Flow.Subscription
    Direct Known Subclasses:
    AbstractPollableSubscription

    public abstract class AbstractSubscription<T>
    extends java.lang.Object
    implements java.util.concurrent.Flow.Subscription
    An abstract Flow.Subscription that implements most of the machinery for execution and backpressure control.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractSubscription​(java.util.concurrent.Flow.Subscriber<? super T> downstream, java.util.concurrent.Executor executor)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void abort​(boolean flowInterrupted)
      Releases resources held by this subscription.
      void cancel()  
      protected void cancelOnComplete​(java.util.concurrent.Flow.Subscriber<? super T> downstream)
      Calls downstream's onComplete after cancelling this subscription.
      protected void cancelOnError​(java.util.concurrent.Flow.Subscriber<? super T> downstream, java.lang.Throwable exception, boolean flowInterrupted)
      Calls downstream's onError with the given exception after cancelling this subscription.
      protected long currentDemand()  
      protected abstract long emit​(java.util.concurrent.Flow.Subscriber<? super T> downstream, long emit)
      Emits at most emit items to downstream using submitOnNext( Subscriber, Object) as long as it returns true.
      void fireOrKeepAlive()  
      void fireOrKeepAliveOnError​(java.lang.Throwable exception)  
      void fireOrKeepAliveOnNext()  
      protected boolean hasPendingErrors()
      Returns true if the subscriber is to be completed exceptionally.
      protected boolean isCancelled()
      Returns true if this subscription is cancelled.
      void request​(long n)  
      protected boolean submitOnNext​(java.util.concurrent.Flow.Subscriber<? super T> downstream, T item)
      Submits given item to the downstream, returning false and cancelling on failure.
      • Methods inherited from class java.lang.Object

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

      • AbstractSubscription

        protected AbstractSubscription​(java.util.concurrent.Flow.Subscriber<? super T> downstream,
                                       java.util.concurrent.Executor executor)
    • Method Detail

      • request

        public final void request​(long n)
        Specified by:
        request in interface java.util.concurrent.Flow.Subscription
      • cancel

        public final void cancel()
        Specified by:
        cancel in interface java.util.concurrent.Flow.Subscription
      • fireOrKeepAlive

        public void fireOrKeepAlive()
      • fireOrKeepAliveOnNext

        public void fireOrKeepAliveOnNext()
      • fireOrKeepAliveOnError

        public void fireOrKeepAliveOnError​(java.lang.Throwable exception)
      • emit

        protected abstract long emit​(java.util.concurrent.Flow.Subscriber<? super T> downstream,
                                     long emit)
        Emits at most emit items to downstream using submitOnNext( Subscriber, Object) as long as it returns true. The actual number of emitted items is returned, may be 0 in case of cancellation or if no items are emitted, perhaps due to lack thereof, or if emit itself is zero. If the underlying source is finished, the subscriber is completed with cancelOnComplete(Subscriber).
      • abort

        protected void abort​(boolean flowInterrupted)
        Releases resources held by this subscription. flowInterrupted tells whether cancellation was due to flow interruption by downstream (e.g. calling cancel() or throwing from onNext or onSubscribe), or due to ending the normal flow of signals (onSubscribe -> onNext* -> (onError | onComplete)).
      • isCancelled

        protected final boolean isCancelled()
        Returns true if this subscription is cancelled. false result is immediately outdated. Can be used by implementation to halt producing items in case the subscription was asynchronously cancelled.
      • hasPendingErrors

        protected final boolean hasPendingErrors()
        Returns true if the subscriber is to be completed exceptionally. false result is immediately outdated. Can be used by implementation to halt producing items in case the subscription was asynchronously signalled with an error.
      • cancelOnError

        protected final void cancelOnError​(java.util.concurrent.Flow.Subscriber<? super T> downstream,
                                           java.lang.Throwable exception,
                                           boolean flowInterrupted)
        Calls downstream's onError with the given exception after cancelling this subscription. flowInterrupted tells whether the error interrupted the normal flow of signals.
      • cancelOnComplete

        protected final void cancelOnComplete​(java.util.concurrent.Flow.Subscriber<? super T> downstream)
        Calls downstream's onComplete after cancelling this subscription.
      • submitOnNext

        protected final boolean submitOnNext​(java.util.concurrent.Flow.Subscriber<? super T> downstream,
                                             T item)
        Submits given item to the downstream, returning false and cancelling on failure. false is also returned if the subscription is already cancelled or has pending errors. On such cases, caller should stop emitting items.
      • currentDemand

        protected long currentDemand()