Class DeferredScalarSubscription<T>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static int CANCELLED
      Indicates the Subscription has been cancelled.
      protected org.reactivestreams.Subscriber<? super T> downstream
      The Subscriber to emit the value to.
      (package private) static int FUSED_CONSUMED
      Indicates this Subscription is in fusion mode and its value has been consumed.
      (package private) static int FUSED_EMPTY
      Indicates this Subscription is in fusion mode and is currently empty.
      (package private) static int FUSED_READY
      Indicates this Subscription is in fusion mode and has a value.
      (package private) static int HAS_REQUEST_HAS_VALUE
      Indicates this Subscription has both request and value.
      (package private) static int HAS_REQUEST_NO_VALUE
      Indicates this Subscription has been requested but there is no value yet.
      (package private) static int NO_REQUEST_HAS_VALUE
      Indicates this Subscription has a value but not requested yet.
      (package private) static int NO_REQUEST_NO_VALUE
      Indicates this Subscription has no value and not requested yet.
      private static long serialVersionUID  
      protected T value
      The value is stored here if there is no request yet or in fusion mode.
    • Constructor Summary

      Constructors 
      Constructor Description
      DeferredScalarSubscription​(org.reactivestreams.Subscriber<? super @NonNull T> downstream)
      Creates a DeferredScalarSubscription by wrapping the given Subscriber.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()  
      void clear()
      Removes all enqueued items from this queue.
      void complete​(@NonNull T v)
      Completes this subscription by indicating the given value should be emitted when the first request arrives.
      boolean isCancelled()
      Returns true if this Subscription has been cancelled.
      boolean isEmpty()
      Returns true if the queue is empty.
      T poll()
      Tries to dequeue a value (non-null) or returns null if the queue is empty.
      void request​(long n)  
      int requestFusion​(int mode)
      Request a fusion mode from the upstream.
      boolean tryCancel()
      Atomically sets a cancelled state and returns true if the current thread did it successfully.
      • Methods inherited from class java.util.concurrent.atomic.AtomicInteger

        accumulateAndGet, addAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, decrementAndGet, doubleValue, floatValue, get, getAcquire, getAndAccumulate, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, getAndUpdate, getOpaque, getPlain, incrementAndGet, intValue, lazySet, longValue, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
      • Methods inherited from class java.lang.Number

        byteValue, shortValue
      • Methods inherited from class java.lang.Object

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

      • downstream

        protected final org.reactivestreams.Subscriber<? super T> downstream
        The Subscriber to emit the value to.
      • value

        protected T value
        The value is stored here if there is no request yet or in fusion mode.
      • NO_REQUEST_NO_VALUE

        static final int NO_REQUEST_NO_VALUE
        Indicates this Subscription has no value and not requested yet.
        See Also:
        Constant Field Values
      • NO_REQUEST_HAS_VALUE

        static final int NO_REQUEST_HAS_VALUE
        Indicates this Subscription has a value but not requested yet.
        See Also:
        Constant Field Values
      • HAS_REQUEST_NO_VALUE

        static final int HAS_REQUEST_NO_VALUE
        Indicates this Subscription has been requested but there is no value yet.
        See Also:
        Constant Field Values
      • HAS_REQUEST_HAS_VALUE

        static final int HAS_REQUEST_HAS_VALUE
        Indicates this Subscription has both request and value.
        See Also:
        Constant Field Values
      • CANCELLED

        static final int CANCELLED
        Indicates the Subscription has been cancelled.
        See Also:
        Constant Field Values
      • FUSED_EMPTY

        static final int FUSED_EMPTY
        Indicates this Subscription is in fusion mode and is currently empty.
        See Also:
        Constant Field Values
      • FUSED_READY

        static final int FUSED_READY
        Indicates this Subscription is in fusion mode and has a value.
        See Also:
        Constant Field Values
      • FUSED_CONSUMED

        static final int FUSED_CONSUMED
        Indicates this Subscription is in fusion mode and its value has been consumed.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DeferredScalarSubscription

        public DeferredScalarSubscription​(org.reactivestreams.Subscriber<? super @NonNull T> downstream)
        Creates a DeferredScalarSubscription by wrapping the given Subscriber.
        Parameters:
        downstream - the Subscriber to wrap, not null (not verified)
    • Method Detail

      • request

        public final void request​(long n)
      • complete

        public final void complete​(@NonNull T v)
        Completes this subscription by indicating the given value should be emitted when the first request arrives.

        Make sure this is called exactly once.

        Parameters:
        v - the value to signal, not null (not validated)
      • poll

        @Nullable
        public final T poll()
        Description copied from interface: SimpleQueue
        Tries to dequeue a value (non-null) or returns null if the queue is empty.

        If the producer uses SimpleQueue.offer(Object, Object) and when polling in pairs, if the first poll() returns a non-null item, the second poll() is guaranteed to return a non-null item as well.

        Returns:
        the item or null to indicate an empty queue
      • isEmpty

        public final boolean isEmpty()
        Description copied from interface: SimpleQueue
        Returns true if the queue is empty.

        Note however that due to potential fused functions in SimpleQueue.poll() it is possible this method returns false but then poll() returns null because the fused function swallowed the available item(s).

        Returns:
        true if the queue is empty
      • clear

        public final void clear()
        Description copied from interface: SimpleQueue
        Removes all enqueued items from this queue.
      • cancel

        public void cancel()
      • isCancelled

        public final boolean isCancelled()
        Returns true if this Subscription has been cancelled.
        Returns:
        true if this Subscription has been cancelled
      • tryCancel

        public final boolean tryCancel()
        Atomically sets a cancelled state and returns true if the current thread did it successfully.
        Returns:
        true if the current thread cancelled