T
- the value typepublic class DeferredScalarSubscription<T> extends BasicIntQueueSubscription<T>
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.
Modifier and Type | Field and Description |
---|---|
protected org.reactivestreams.Subscriber<? super T> |
actual
The Subscriber to emit the value to.
|
protected T |
value
The value is stored here if there is no request yet or in fusion mode.
|
Constructor and Description |
---|
DeferredScalarSubscription(org.reactivestreams.Subscriber<? super T> actual)
Creates a DeferredScalarSubscription by wrapping the given Subscriber.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel() |
void |
clear()
Removes all enqueued items from this queue.
|
void |
complete(T v)
Completes this subscription by indicating the given value should
be emitted when the first request arrives.
|
boolean |
isCancelled()
Returns true if this Subscription has been cancelled.
|
boolean |
isEmpty()
Returns true if the queue is empty.
|
T |
poll()
Tries to dequeue a value (non-null) or returns null if
the queue is empty.
|
void |
request(long n) |
int |
requestFusion(int mode)
Request a fusion mode from the upstream.
|
boolean |
tryCancel()
Atomically sets a cancelled state and returns true if
the current thread did it successfully.
|
offer, offer
accumulateAndGet, addAndGet, compareAndSet, decrementAndGet, doubleValue, floatValue, get, getAndAccumulate, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, getAndUpdate, incrementAndGet, intValue, lazySet, longValue, set, toString, updateAndGet, weakCompareAndSet
byteValue, shortValue
protected final org.reactivestreams.Subscriber<? super T> actual
protected T value
public DeferredScalarSubscription(org.reactivestreams.Subscriber<? super T> actual)
actual
- the Subscriber to wrap, not null (not verified)public final void request(long n)
public final void complete(T v)
Make sure this is called exactly once.
v
- the value to signal, not null (not validated)public final int requestFusion(int mode)
QueueFuseable
This should be called before onSubscribe
returns.
Calling this method multiple times or after onSubscribe
finished is not allowed
and may result in undefined behavior.
mode
- the requested fusion mode, allowed values are QueueFuseable.SYNC
, QueueFuseable.ASYNC
,
QueueFuseable.ANY
combined with QueueFuseable.BOUNDARY
(e.g., requestFusion(SYNC | BOUNDARY)
).QueueFuseable.NONE
, QueueFuseable.SYNC
, QueueFuseable.ASYNC
.@Nullable public final T poll()
SimpleQueue
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.
public final boolean isEmpty()
SimpleQueue
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).
public final void clear()
SimpleQueue
public void cancel()
public final boolean isCancelled()
public final boolean tryCancel()
Copyright © 2018 JBoss by Red Hat. All rights reserved.