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) boolean
Indicates the emission should stop.(package private) final Subscriber
<? super Integer> The Subscriber we are emitting integer values to.(package private) final int
The end index (exclusive).(package private) int
The current index and within the [start, start + count) range that will be emitted as downstream.onNext().(package private) Throwable
Holds 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 java.util.concurrent.atomic.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, weakCompareAndSetVolatile
Methods inherited from class java.lang.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:Subscription
No events will be sent by aPublisher
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 eitherSubscriber.onError(Throwable)
orSubscriber.onComplete()
.- Specified by:
request
in interfaceSubscription
- Parameters:
n
- the strictly positive number of elements to requests to the upstreamPublisher
-
cancel
public void cancel()Description copied from interface:Subscription
Request thePublisher
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 interfaceSubscription
-
emit
void emit(long currentRequested)
-