Class SpscLinkedArrayQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
org.jboss.resteasy.microprofile.client.publisher.SpscLinkedArrayQueue<E>
- Type Parameters:
E- the element type of the queue
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Queue<E>
A single-producer single-consumer array-backed queue which can allocate new arrays in case the consumer is slower
than the producer.
Code inspired from https://github.com/JCTools/JCTools/blob/master/jctools-core/src/main/java/org/jctools/queues/atomic.
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.util.AbstractQueue
add, addAll, element, removeMethods inherited from class java.util.AbstractCollection
contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
addAll, contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
Constructor Details
-
SpscLinkedArrayQueue
public SpscLinkedArrayQueue(int bufferSize)
-
-
Method Details
-
roundToPowerOfTwo
public static int roundToPowerOfTwo(int value) Find the next larger positive power of two value up from the given value. If value is a power of two then this value will be returned.- Parameters:
value- from which next positive power of two will be found.- Returns:
- the next positive power of 2 or this value if it is a power of 2.
-
offer
This implementation is correct for single producer thread use only.
-
poll
This implementation is correct for single consumer thread use only.
-
peek
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractQueue<E>
-
iterator
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin classAbstractCollection<E>
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
offer
Offer two elements at the same time.Don't use the regular offer() with this at all!
- Parameters:
first- the first value, not nullsecond- the second value, not null- Returns:
- true if the queue accepted the two new values
-