T - the contained value typepublic final class MpscLinkedQueue<T>
extends java.util.AbstractQueue<E>
| Constructor and Description |
|---|
MpscLinkedQueue() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isEmpty()
IMPLEMENTATION NOTES: Queue is empty when producerNode is the same as consumerNode. |
java.util.Iterator<E> |
iterator() |
protected LinkedQueueNode<E> |
lpConsumerNode() |
protected LinkedQueueNode<E> |
lpProducerNode() |
protected LinkedQueueNode<E> |
lvConsumerNode() |
protected LinkedQueueNode<E> |
lvProducerNode() |
boolean |
offer(T nextValue)
IMPLEMENTATION NOTES: Offer is allowed from multiple threads. |
T |
peek() |
T |
poll()
IMPLEMENTATION NOTES: Poll is allowed from a SINGLE thread. |
int |
size()
IMPLEMENTATION NOTES: This is an O(n) operation as we run through all the nodes and count them. |
protected void |
spConsumerNode(LinkedQueueNode<E> node) |
protected void |
spProducerNode(LinkedQueueNode<E> node) |
protected LinkedQueueNode<E> |
xchgProducerNode(LinkedQueueNode<E> node) |
contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitpublic final boolean offer(T nextValue)
IMPLEMENTATION NOTES:
Offer is allowed from multiple threads.
Offer allocates a new node and:
Queue.offer(java.lang.Object)public final T poll()
IMPLEMENTATION NOTES:
Poll is allowed from a SINGLE thread.
Poll reads the next node from the consumerNode and:
Queue.poll()public final T peek()
protected final LinkedQueueNode<E> lvProducerNode()
protected final LinkedQueueNode<E> lpProducerNode()
protected final void spProducerNode(LinkedQueueNode<E> node)
protected final LinkedQueueNode<E> xchgProducerNode(LinkedQueueNode<E> node)
protected final LinkedQueueNode<E> lvConsumerNode()
protected final LinkedQueueNode<E> lpConsumerNode()
protected final void spConsumerNode(LinkedQueueNode<E> node)
public final java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>iterator in interface java.util.Collection<E>iterator in class java.util.AbstractCollection<E>public final int size()
IMPLEMENTATION NOTES:
This is an O(n) operation as we run through all the nodes and count them.
size in interface java.util.Collection<E>size in class java.util.AbstractCollection<E>Collection.size()public final boolean isEmpty()
IMPLEMENTATION NOTES:
Queue is empty when producerNode is the same as consumerNode. An alternative implementation would be to observe
the producerNode.value is null, which also means an empty queue because only the consumerNode.value is allowed to
be null.
isEmpty in interface java.util.Collection<E>isEmpty in class java.util.AbstractCollection<E>