Class SpscLinkedArrayQueue<T>
java.lang.Object
io.reactivex.rxjava4.operators.SpscLinkedArrayQueue<T>
- Type Parameters:
T- the contained value type
- All Implemented Interfaces:
SimplePlainQueue<T>, SimpleQueue<T>
A single-producer single-consumer array-backed queue which can allocate new arrays in case the consumer is slower
than the producer.
- Since:
- 3.1.1
-
Constructor Summary
ConstructorsConstructorDescriptionSpscLinkedArrayQueue(int bufferSize) Constructs a linked array-based queue instance with the given island size rounded up to the next power of 2. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all enqueued items from this queue.booleanisEmpty()Returns true if the queue is empty.booleanAtomically enqueue a single value.booleanOffer two elements at the same time.peek()Returns the next element in this queue without removing it ornullif this queue is emptypoll()Tries to dequeue a value (non-null) or returns null if the queue is empty.intsize()Returns the number of elements in the queue.
-
Constructor Details
-
SpscLinkedArrayQueue
public SpscLinkedArrayQueue(int bufferSize) Constructs a linked array-based queue instance with the given island size rounded up to the next power of 2.- Parameters:
bufferSize- the maximum number of elements per island
-
-
Method Details
-
offer
Atomically enqueue a single value.This implementation is correct for single producer thread use only.
- Specified by:
offerin interfaceSimpleQueue<T>- Parameters:
e- the value to enqueue, not null- Returns:
- true if successful, false if the value was not enqueued likely due to reaching the queue capacity)
-
poll
Tries 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.This implementation is correct for single consumer thread use only.
- Specified by:
pollin interfaceSimplePlainQueue<T>- Specified by:
pollin interfaceSimpleQueue<T>- Returns:
- the item or null to indicate an empty queue
-
peek
-
clear
public void clear()Description copied from interface:SimpleQueueRemoves all enqueued items from this queue.- Specified by:
clearin interfaceSimpleQueue<T>
-
size
public int size()Returns the number of elements in the queue.- Returns:
- the number of elements in the queue
-
isEmpty
public 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).- Specified by:
isEmptyin interfaceSimpleQueue<T>- Returns:
- true if the queue is empty
-
offer
Offer two elements at the same time.Don't use the regular offer() with this at all!
- Specified by:
offerin interfaceSimpleQueue<T>- Parameters:
first- the first value, not nullsecond- the second value, not null- Returns:
- true if the queue accepted the two new values
-