Class RangePublisher.RangeSubscription
- java.lang.Object
-
- java.lang.Number
-
- java.util.concurrent.atomic.AtomicLong
-
- org.reactivestreams.example.unicast.RangePublisher.RangeSubscription
-
- All Implemented Interfaces:
java.io.Serializable
,Subscription
- Enclosing class:
- RangePublisher
static final class RangePublisher.RangeSubscription extends java.util.concurrent.atomic.AtomicLong implements Subscription
A Subscription implementation that holds the current downstream requested amount and responds to the downstream's request() and cancel() calls.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
cancelled
Indicates the emission should stop.(package private) Subscriber<? super java.lang.Integer>
downstream
The Subscriber we are emitting integer values to.(package private) int
end
The end index (exclusive).(package private) int
index
The current index and within the [start, start + count) range that will be emitted as downstream.onNext().(package private) java.lang.Throwable
invalidRequest
Holds onto the IllegalArgumentException (containing the offending stacktrace) indicating there was a non-positive request() call from the downstream.private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description RangeSubscription(Subscriber<? super java.lang.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Request thePublisher
to stop sending data and clean up resources.(package private) void
emit(long currentRequested)
void
request(long n)
No events will be sent by aPublisher
until demand is signaled via this method.-
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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
downstream
final Subscriber<? super java.lang.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 java.lang.Throwable invalidRequest
Holds onto the IllegalArgumentException (containing the offending stacktrace) indicating there was a non-positive request() call from the downstream.
-
-
Constructor Detail
-
RangeSubscription
RangeSubscription(Subscriber<? super java.lang.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 Detail
-
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)
-
-