Class RangePublisher.RangeSubscription

java.lang.Object
java.lang.Number
java.util.concurrent.atomic.AtomicLong
org.reactivestreams.example.unicast.RangePublisher.RangeSubscription
All Implemented Interfaces:
Serializable, Subscription
Enclosing class:
RangePublisher

static final class RangePublisher.RangeSubscription extends AtomicLong implements Subscription
A Subscription implementation that holds the current downstream requested amount and responds to the downstream's request() and cancel() calls.
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • downstream

      final Subscriber<? super Integer> downstream
      The Subscriber we are emitting integer values to.
    • end

      final int end
      The end index (exclusive).
    • index

      int index
      The current index and within the [start, start + count) range that will be emitted as downstream.onNext().
    • cancelled

      volatile boolean cancelled
      Indicates the emission should stop.
    • invalidRequest

      volatile Throwable invalidRequest
      Holds onto the IllegalArgumentException (containing the offending stacktrace) indicating there was a non-positive request() call from the downstream.
  • Constructor Details

    • RangeSubscription

      RangeSubscription(Subscriber<? super Integer> downstream, int start, int end)
      Constructs a stateful RangeSubscription that emits signals to the given downstream from an integer range of [start, end).
      Parameters:
      downstream - the Subscriber receiving the integer values and the completion signal.
      start - the first integer value emitted, start of the range
      end - the end of the range, exclusive
  • Method Details

    • request

      public void request(long n)
      Description copied from interface: Subscription
      No events will be sent by a Publisher until demand is signaled via this method.

      It can be called however often and whenever needed—but if the outstanding cumulative demand ever becomes Long.MAX_VALUE or more, it may be treated by the Publisher as "effectively unbounded".

      Whatever has been requested can be sent by the Publisher so only signal demand for what can be safely handled.

      A Publisher can send less than is requested if the stream ends but then must emit either Subscriber.onError(Throwable) or Subscriber.onComplete().

      Specified by:
      request in interface Subscription
      Parameters:
      n - the strictly positive number of elements to requests to the upstream Publisher
    • cancel

      public void cancel()
      Description copied from interface: Subscription
      Request the Publisher to stop sending data and clean up resources.

      Data may still be sent to meet previously signalled demand after calling cancel.

      Specified by:
      cancel in interface Subscription
    • emit

      void emit(long currentRequested)