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
A Subscription implementation that holds the current downstream
requested amount and responds to the downstream's request() and
cancel() calls.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) booleanIndicates the emission should stop.(package private) final Subscriber<? super Integer> The Subscriber we are emitting integer values to.(package private) final intThe end index (exclusive).(package private) intThe current index and within the [start, start + count) range that will be emitted as downstream.onNext().(package private) ThrowableHolds onto the IllegalArgumentException (containing the offending stacktrace) indicating there was a non-positive request() call from the downstream.private static final long -
Constructor Summary
ConstructorsConstructorDescriptionRangeSubscription(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). -
Method Summary
Methods inherited from class AtomicLong
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, weakCompareAndSetVolatileMethods inherited from class Number
byteValue, shortValue
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
downstream
The Subscriber we are emitting integer values to. -
end
final int endThe end index (exclusive). -
index
int indexThe current index and within the [start, start + count) range that will be emitted as downstream.onNext(). -
cancelled
volatile boolean cancelledIndicates the emission should stop. -
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 rangeend- the end of the range, exclusive
-
-
Method Details
-
request
public void request(long n) Description copied from interface:SubscriptionNo events will be sent by aPublisheruntil 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
Publisheras "effectively unbounded".Whatever has been requested can be sent by the
Publisherso only signal demand for what can be safely handled.A
Publishercan send less than is requested if the stream ends but then must emit eitherSubscriber.onError(Throwable)orSubscriber.onComplete().- Specified by:
requestin interfaceSubscription- Parameters:
n- the strictly positive number of elements to requests to the upstreamPublisher
-
cancel
public void cancel()Description copied from interface:SubscriptionRequest thePublisherto stop sending data and clean up resources.Data may still be sent to meet previously signalled demand after calling cancel.
- Specified by:
cancelin interfaceSubscription
-
emit
void emit(long currentRequested)
-