E
- type of the element stored in the Queue
@SuppressAnimalSniffer public class MpmcArrayQueue<E> extends ConcurrentSequencedCircularArrayQueue<E>
ConcurrentCircularArrayQueue
. This implies that
any and all threads may call the offer/poll/peek methods and correctness is maintained. sequenceBuffer
buffer, BUFFER_PAD, mask, SPARSE_SHIFT
Constructor and Description |
---|
MpmcArrayQueue(int capacity) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
casConsumerIndex(long expect,
long newValue) |
protected boolean |
casProducerIndex(long expect,
long newValue) |
boolean |
isEmpty()
This method's accuracy is subject to concurrent modifications happening as the observation is carried out.
|
protected long |
lvConsumerIndex() |
protected long |
lvProducerIndex() |
boolean |
offer(E e)
Called from a producer thread subject to the restrictions appropriate to the implementation and according to the
Queue.offer(Object) interface. |
E |
peek()
Called from the consumer thread subject to the restrictions appropriate to the implementation and according to
the
Queue.peek() interface. |
E |
poll()
Called from the consumer thread subject to the restrictions appropriate to the implementation and according to
the
Queue.poll() interface. |
int |
size()
This method's accuracy is subject to concurrent modifications happening as the size is estimated and as such is a
best effort rather than absolute value.
|
calcSequenceOffset, lvSequence, soSequence
calcElementOffset, calcElementOffset, clear, iterator, lpElement, lpElement, lvElement, lvElement, soElement, soElement, spElement, spElement
add, addAll, element, remove
contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
public boolean offer(E e)
MessagePassingQueue
Queue.offer(Object)
interface.e
- the Object to enqueue, not nullpublic E poll()
Queue.poll()
interface.
Because return null indicates queue is empty we cannot simply rely on next element visibility for poll and must test producer index when next element is not visible.
public E peek()
MessagePassingQueue
Queue.peek()
interface.public int size()
MessagePassingQueue
size
in interface Collection<E>
size
in interface MessagePassingQueue<E>
size
in class AbstractCollection<E>
Integer.MAX_VALUE
if not boundedpublic boolean isEmpty()
MessagePassingQueue
isEmpty
in interface Collection<E>
isEmpty
in interface MessagePassingQueue<E>
isEmpty
in class AbstractCollection<E>
protected final long lvConsumerIndex()
protected final boolean casConsumerIndex(long expect, long newValue)
protected final long lvProducerIndex()
protected final boolean casProducerIndex(long expect, long newValue)
Copyright © 2017. All rights reserved.