Class MultipartSubscription

  • All Implemented Interfaces:
    java.util.concurrent.Flow.Subscription

    class MultipartSubscription
    extends java.lang.Object
    implements java.util.concurrent.Flow.Subscription
    • Constructor Summary

      Constructors 
      Constructor Description
      MultipartSubscription​(java.lang.String boundary, java.util.List<Part> parts, ProgressMonitor monitor, java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void abort​(boolean flowInterrupted)
      Called when the subscription is cancelled.
      void cancel()  
      private void cancelOnComplete​(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)
      Calls downstream's onComplete after cancelling this subscription.
      private void cancelOnError​(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, java.lang.Throwable error, boolean flowInterrupted)
      Calls downstream's onError after cancelling this subscription.
      private long emit​(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, long emit)
      Main method for item emission.
      private long getAndAddDemand​(java.lang.Object owner, java.lang.invoke.VarHandle demand, long n)
      Adds given count to demand not exceeding Long.MAX_VALUE.
      private int getAndBitwiseOrState​(int bits)  
      private boolean hasPendingErrors()
      Returns true if the subscriber is to be completed exceptionally.
      private boolean isCancelled()
      Returns true if cancelled.
      private java.nio.ByteBuffer nextPartHeaders()  
      private java.nio.ByteBuffer pollNext()  
      private java.lang.Throwable propagateError​(java.lang.Throwable error)
      Sets pending error or adds new one as suppressed in case of multiple error sources.
      void request​(long n)  
      private void run()  
      private void signal()  
      void signal​(boolean force)
      Schedules a signaller task.
      void signalError​(java.lang.Throwable error)  
      private boolean submitOnNext​(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, java.nio.ByteBuffer item)
      Submits given item to the downstream, returning false and cancelling on failure.
      private void subscribeOnDrain​(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)  
      private boolean subscribeToPart​(Part part)  
      private long subtractAndGetDemand​(java.lang.Object owner, java.lang.invoke.VarHandle demand, long n)
      Subtracts given count from demand.
      • Methods inherited from class java.lang.Object

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

      • SYNC_EXECUTOR

        static final java.util.concurrent.Executor SYNC_EXECUTOR
      • STATE

        private static final java.lang.invoke.VarHandle STATE
      • PENDING_ERROR

        private static final java.lang.invoke.VarHandle PENDING_ERROR
      • DEMAND

        private static final java.lang.invoke.VarHandle DEMAND
      • PART_SUBSCRIBER

        private static final java.lang.invoke.VarHandle PART_SUBSCRIBER
      • CANCELLED_SUBSCRIBER

        private static final java.util.concurrent.Flow.Subscriber<java.nio.ByteBuffer> CANCELLED_SUBSCRIBER
      • boundary

        private final java.lang.String boundary
      • parts

        private final java.util.List<Part> parts
      • partIndex

        private int partIndex
      • complete

        private boolean complete
      • downstream

        private final java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream
      • executor

        private final java.util.concurrent.Executor executor
      • partSubscriber

        private volatile java.util.concurrent.Flow.Subscriber<java.nio.ByteBuffer> partSubscriber
      • state

        private volatile int state
      • demand

        private volatile long demand
      • pendingError

        private volatile java.lang.Throwable pendingError
    • Constructor Detail

      • MultipartSubscription

        MultipartSubscription​(java.lang.String boundary,
                              java.util.List<Part> parts,
                              ProgressMonitor monitor,
                              java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)
    • 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
      • getAndAddDemand

        private long getAndAddDemand​(java.lang.Object owner,
                                     java.lang.invoke.VarHandle demand,
                                     long n)
        Adds given count to demand not exceeding Long.MAX_VALUE.
      • subtractAndGetDemand

        private long subtractAndGetDemand​(java.lang.Object owner,
                                          java.lang.invoke.VarHandle demand,
                                          long n)
        Subtracts given count from demand. Caller ensures result won't be negative.
      • signal

        public final void signal​(boolean force)
        Schedules a signaller task. force tells whether to schedule in case of no demand
      • signalError

        public final void signalError​(java.lang.Throwable error)
      • isCancelled

        private final boolean isCancelled()
        Returns true if cancelled. false result is immediately outdated.
      • hasPendingErrors

        private 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

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

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

        private final boolean submitOnNext​(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream,
                                           java.nio.ByteBuffer item)
        Submits given item to the downstream, returning false and cancelling on failure.
      • signal

        private void signal()
      • run

        private void run()
      • subscribeOnDrain

        private void subscribeOnDrain​(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)
      • propagateError

        private java.lang.Throwable propagateError​(java.lang.Throwable error)
        Sets pending error or adds new one as suppressed in case of multiple error sources.
      • getAndBitwiseOrState

        private int getAndBitwiseOrState​(int bits)
      • emit

        private long emit​(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream,
                          long emit)
        Main method for item emission. At most e items are emitted to the downstream using {submitOnNext(Flow.Subscriber, Object)} as long as it returns true. The actual number of emitted items is returned, may be 0 in case of cancellation. If the underlying source is finished, the subscriber is completed with cancelOnComplete(Flow.Subscriber).
      • abort

        private void abort​(boolean flowInterrupted)
        Called when the subscription is cancelled. flowInterrupted specifies whether cancellation was due to ending the normal flow of signals (signal|signalError) or due to flow interruption by downstream (e.g. calling cancel() or throwing from onNext).
      • pollNext

        private java.nio.ByteBuffer pollNext()
      • nextPartHeaders

        private java.nio.ByteBuffer nextPartHeaders()
      • subscribeToPart

        private boolean subscribeToPart​(Part part)