Top Description Fields Constructors Methods
reactor.util.concurrent

pack-priv final Class SpscLinkedArrayQueue<T>

extends AbstractQueue<T>
implements BiPredicate<T, T>
Class Inheritance
All Implemented Interfaces
java.util.function.BiPredicate
Type Parameters
<T>
the value type
Imports
java.util.AbstractQueue, .Iterator, .Objects, java.util.concurrent.atomic.AtomicLongFieldUpdater, .AtomicReferenceArray, java.util.function.BiPredicate, reactor.util.annotation.Nullable

An unbounded, array-backed single-producer, single-consumer queue with a fixed link size.

This implementation is based on JCTools' SPSC algorithms: SpscUnboundedArrayQueue and SpscUnboundedAtomicArrayQueue of which the SpscUnboundedAtomicArrayQueue was contributed by one of the authors of this library. The notable difference is that this class is not padded and there is no lookahead cache involved; padding has a toll on short lived or bursty uses and lookahead doesn't really matter with small queues.

Field Summary

Modifier and TypeField and Description
pack-priv static final AtomicLongFieldUpdater<SpscLinkedArrayQueue<T>>
pack-priv AtomicReferenceArray<Object>
pack-priv volatile long
pack-priv final int
pack-priv static final Object
pack-priv static final AtomicLongFieldUpdater<SpscLinkedArrayQueue<T>>
pack-priv AtomicReferenceArray<Object>
pack-priv volatile long

Constructor Summary

AccessConstructor and Description
pack-priv
SpscLinkedArrayQueue(int linkSize)

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Overrides java.util.AbstractQueue.clear.

Implements java.util.Collection.clear.

Removes all of the elements from this queue.
public boolean
isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.Collection.isEmpty.

Returns true if this collection contains no elements.
public Iterator<T>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Returns an iterator over the elements in this collection.
public boolean
offer(T
the element to add
e
)

Implements java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
public T
peek()

Implements java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
public T
poll()

Implements java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size.

Returns the number of elements in this collection.
public boolean

Returns:

true if the queue accepted the two new values
test
(T
the first value, not null
first
,
T
the second value, not null
second
)

Implements java.util.function.BiPredicate.test.

Offer two elements at the same time.
Inherited from java.util.AbstractQueue:
addaddAllelementremove

Field Detail

CONSUMER_INDEXback to summary
pack-priv static final AtomicLongFieldUpdater<SpscLinkedArrayQueue<T>> CONSUMER_INDEX
Annotations
@SuppressWarnings:rawtypes
consumerArrayback to summary
pack-priv AtomicReferenceArray<Object> consumerArray
consumerIndexback to summary
pack-priv volatile long consumerIndex
maskback to summary
pack-priv final int mask
NEXTback to summary
pack-priv static final Object NEXT
PRODUCER_INDEXback to summary
pack-priv static final AtomicLongFieldUpdater<SpscLinkedArrayQueue<T>> PRODUCER_INDEX
Annotations
@SuppressWarnings:rawtypes
producerArrayback to summary
pack-priv AtomicReferenceArray<Object> producerArray
producerIndexback to summary
pack-priv volatile long producerIndex

Constructor Detail

SpscLinkedArrayQueueback to summary
pack-priv SpscLinkedArrayQueue(int linkSize)

Method Detail

clearback to summary
public void clear()

Overrides java.util.AbstractQueue.clear.

Implements java.util.Collection.clear.

Doc from java.util.AbstractQueue.clear.

Removes all of the elements from this queue. The queue will be empty after this call returns.

This implementation repeatedly invokes poll until it returns null.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.Collection.isEmpty.

Doc from java.util.Collection.isEmpty.

Returns true if this collection contains no elements.

Returns:boolean

true if this collection contains no elements

Annotations
@Override
iteratorback to summary
public Iterator<T> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Doc from java.util.Collection.iterator.

Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).

Returns:Iterator<T>

an Iterator over the elements in this collection

Annotations
@Override
offerback to summary
public boolean offer(T e)

Implements java.util.Queue.offer.

Doc from java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to add, which can fail to insert an element only by throwing an exception.

Parameters
e:T

the element to add

Returns:boolean

true if the element was added to this queue, else false

Annotations
@Override
peekback to summary
public T peek()

Implements java.util.Queue.peek.

Doc from java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Returns:T

the head of this queue, or null if this queue is empty

Annotations
@SuppressWarnings:unchecked
@Override
@Nullable
pollback to summary
public T poll()

Implements java.util.Queue.poll.

Doc from java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Returns:T

the head of this queue, or null if this queue is empty

Annotations
@SuppressWarnings:unchecked
@Override
@Nullable
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size.

Doc from java.util.Collection.size.

Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this collection

Annotations
@Override
testback to summary
public boolean test(T first, T second)

Implements java.util.function.BiPredicate.test.

Offer two elements at the same time.

Don't use the regular offer() with this at all!

Parameters
first:T

the first value, not null

second:T

the second value, not null

Returns:boolean

true if the queue accepted the two new values

Annotations
@Override