Class DeferredScalarSubscription<T>
- Type Parameters:
T- the value type
- All Implemented Interfaces:
QueueFuseable<T>, QueueSubscription<T>, SimpleQueue<T>, Serializable, org.reactivestreams.Subscription
- Direct Known Subclasses:
DeferredScalarSubscriber
Note that the class leaks all methods of AtomicLong.
Use complete(Object) to signal the single value.
The this atomic integer stores a bit field:
bit 0: indicates that there is a value available
bit 1: indicates that there was a request made
bit 2: indicates there was a cancellation, exclusively set
bit 3: indicates in fusion mode but no value yet, exclusively set
bit 4: indicates in fusion mode and value is available, exclusively set
bit 5: indicates in fusion mode and value has been consumed, exclusively set
Where exclusively set means any other bits are 0 when that bit is set.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDeferredScalarSubscription(org.reactivestreams.Subscriber<? super @NonNull T> downstream) Creates a DeferredScalarSubscription by wrapping the given Subscriber. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()final voidclear()Removes all enqueued items from this queue.final voidCompletes this subscription by indicating the given value should be emitted when the first request arrives.final booleanReturns true if this Subscription has been cancelled.final booleanisEmpty()Returns true if the queue is empty.final Tpoll()Tries to dequeue a value (non-null) or returns null if the queue is empty.final voidrequest(long n) final intrequestFusion(int mode) Request a fusion mode from the upstream.final booleanAtomically sets a cancelled state and returns true if the current thread did it successfully.Methods inherited from class BasicIntQueueSubscription
offer, offerMethods inherited from class 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, weakCompareAndSetVolatileMethods inherited from class Number
byteValue, shortValue
-
Field Details
-
downstream
The Subscriber to emit the value to. -
value
The value is stored here if there is no request yet or in fusion mode.
-
-
Constructor Details
-
DeferredScalarSubscription
-
-
Method Details
-
request
public final void request(long n) -
complete
-
requestFusion
public final int requestFusion(int mode) Description copied from interface:QueueFuseableRequest a fusion mode from the upstream.This should be called before
onSubscribereturns.Calling this method multiple times or after
onSubscribefinished is not allowed and may result in undefined behavior.- Parameters:
mode- the requested fusion mode, allowed values areQueueFuseable.SYNC,QueueFuseable.ASYNC,QueueFuseable.ANYcombined withQueueFuseable.BOUNDARY(e.g.,requestFusion(SYNC | BOUNDARY)).- Returns:
- the established fusion mode:
QueueFuseable.NONE,QueueFuseable.SYNC,QueueFuseable.ASYNC.
-
poll
Description copied from interface:SimpleQueueTries 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:SimpleQueueReturns 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:SimpleQueueRemoves 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
-