Top Description Fields Constructors Methods
io.netty.util.internal.shaded.org.jctools.queues.atomic

pack-priv abstract Class BaseLinkedAtomicQueue<E>

Additional top-level classes in compilation unit: BaseLinkedAtomicQueuePad0, BaseLinkedAtomicQueueProducerNodeRef, BaseLinkedAtomicQueuePad1, BaseLinkedAtomicQueueConsumerNodeRef, BaseLinkedAtomicQueuePad2.

extends BaseLinkedAtomicQueuePad2<E>
Class Inheritance
Known Direct Subclasses
io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscLinkedAtomicQueue, io.netty.util.internal.shaded.org.jctools.queues.atomic.SpscLinkedAtomicQueue
Imports
java.util.AbstractQueue, .Iterator, .Queue, java.util.concurrent.atomic.AtomicReferenceFieldUpdater, .AtomicLongFieldUpdater, .AtomicReferenceArray, io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue, .MessagePassingQueue.Supplier, .MessagePassingQueueUtil, .QueueProgressIndicators, .IndexedQueueSizeUtil

Note

This class was automatically generated by io.netty.util.internal.shaded.org.jctools.queues.atomic.JavaParsingAtomicLinkedQueueGenerator which can found in the jctools-build module. The original source file is BaseLinkedQueue.java. A base data structure for concurrent linked queues. For convenience also pulled in common single consumer methods since at this time there's no plan to implement MC.

Field Summary

Inherited from io.netty.util.internal.shaded.org.jctools.queues.atomic.BaseLinkedAtomicQueuePad2:
b000b001b002b003b004b005b006b007b010b011b012b013b014b015b016b017b020b021b022b023b024b025b026b027b030b031b032b033b034b035b036b037b040b041b042b043b044b045b046b047b050b051b052b053b054b055b056b057b060b061b062b063b064b065b066b067b070b071b072b073b074b075b076b077b100b101b102b103b104b105b106b107b110b111b112b113b114b115b116b117b120b121b122b123b124b125b126b127b130b131b132b133b134b135b136b137b140b141b142b143b144b145b146b147b150b151b152b153b154b155b156b157b160b161b162b163b164b165b166b167b170b171b172b173b174b175b176b177

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
public int
drain(MessagePassingQueue.Consumer<E> c, int limit)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.drain.

Remove up to limit elements from the queue and hand to consume.
public int
drain(MessagePassingQueue.Consumer<E> c)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.drain.

Remove all available item from the queue and hand to consume.
public void
protected E
public boolean
isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.isEmpty, java.util.Collection.isEmpty.

This method's accuracy is subject to concurrent modifications happening as the observation is carried out.
public final Iterator<E>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Returns an iterator over the elements in this collection.
protected final LinkedQueueAtomicNode<E>
protected final LinkedQueueAtomicNode<E>
newNode(E e)

public E
peek()

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.peek, java.util.Queue.peek.

Called from the consumer thread subject to the restrictions appropriate to the implementation and according to the Queue#peek() interface.
public E
poll()

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.poll, java.util.Queue.poll.

Called from the consumer thread subject to the restrictions appropriate to the implementation and according to the Queue#poll() interface.
public boolean
relaxedOffer(E
not null, will throw NPE if it is
e
)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.relaxedOffer.

Called from a producer thread subject to the restrictions appropriate to the implementation.
public E
relaxedPeek()

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.relaxedPeek.

Called from the consumer thread subject to the restrictions appropriate to the implementation.
public E
relaxedPoll()

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.relaxedPoll.

Called from the consumer thread subject to the restrictions appropriate to the implementation.
public final int
size()

Implements abstract java.util.AbstractCollection.size.

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.size, java.util.Collection.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.
pack-priv LinkedQueueAtomicNode<E>
public String
toString()

Overrides java.util.AbstractCollection.toString.

Returns a string representation of this collection.

Constructor Detail

BaseLinkedAtomicQueueback to summary
pack-priv BaseLinkedAtomicQueue()

Method Detail

capacityback to summary
public int capacity()

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.capacity.

Returns:int

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.capacity.

the capacity of this queue or MessagePassingQueue#UNBOUNDED_CAPACITY if not bounded

Annotations
@Override
drainback to summary
public int drain(MessagePassingQueue.Consumer<E> c, int limit)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.drain.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.drain.

Remove up to limit elements from the queue and hand to consume. This should be semantically similar to:

M m;
  int i = 0;
  for(;i < limit && (m = relaxedPoll()) != null; i++){
    c.accept(m);
  }
  return i;

There's no strong commitment to the queue being empty at the end of a drain. Called from a consumer thread subject to the restrictions appropriate to the implementation.

Warning

Explicit assumptions are made with regards to Consumer#accept make sure you have read and understood these before using this method.

Returns:int

the number of polled elements

Annotations
@Override
drainback to summary
public int drain(MessagePassingQueue.Consumer<E> c)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.drain.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.drain.

Remove all available item from the queue and hand to consume. This should be semantically similar to:

M m;
while((m = relaxedPoll()) != null){
c.accept(m);
}
There's no strong commitment to the queue being empty at the end of a drain. Called from a consumer thread subject to the restrictions appropriate to the implementation.

Warning

Explicit assumptions are made with regards to Consumer#accept make sure you have read and understood these before using this method.

Returns:int

the number of polled elements

Annotations
@Override
drainback to summary
public void drain(MessagePassingQueue.Consumer<E> c, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.drain.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.drain.

Remove elements from the queue and hand to consume forever. Semantically similar to:

 int idleCounter = 0;
 while (exit.keepRunning()) {
     E e = relaxedPoll();
     if(e==null){
         idleCounter = wait.idle(idleCounter);
         continue;
     }
     idleCounter = 0;
     c.accept(e);
 }

Called from a consumer thread subject to the restrictions appropriate to the implementation.

Warning

Explicit assumptions are made with regards to Consumer#accept make sure you have read and understood these before using this method.

Annotations
@Override
getSingleConsumerNodeValueback to summary
protected E getSingleConsumerNodeValue(LinkedQueueAtomicNode<E> currConsumerNode, LinkedQueueAtomicNode<E> nextNode)
isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.isEmpty, java.util.Collection.isEmpty.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.isEmpty.

This method's accuracy is subject to concurrent modifications happening as the observation is carried out.

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.

Returns:boolean

true if empty, false otherwise

Annotations
@Override
See Also
MessagePassingQueue#isEmpty()
iteratorback to summary
public final Iterator<E> 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<E>

an Iterator over the elements in this collection

Annotations
@Override
newNodeback to summary
protected final LinkedQueueAtomicNode<E> newNode()
newNodeback to summary
protected final LinkedQueueAtomicNode<E> newNode(E e)
peekback to summary
public E peek()

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.peek, java.util.Queue.peek.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.peek.

Called from the consumer thread subject to the restrictions appropriate to the implementation and according to the Queue#peek() interface.

IMPLEMENTATION NOTES:
Peek is allowed from a SINGLE thread.
Peek is potentially blocking here as the Queue#peek() does not allow returning null if the queue is not empty. This is very different from the original Vyukov guarantees. See relaxedPeek() for the original semantics.
Poll reads the next node from the consumerNode and:

  1. If it is null AND the queue is empty return null, if queue is not empty spin wait for value to become visible.
  2. If it is not null return it's value.
Returns:E

a message from the queue if one is available, null iff empty

Annotations
@Override
See Also
MessagePassingQueue#peek(), java.util.Queue#peek()
pollback to summary
public E poll()

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.poll, java.util.Queue.poll.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.poll.

Called from the consumer thread subject to the restrictions appropriate to the implementation and according to the Queue#poll() interface.

IMPLEMENTATION NOTES:
Poll is allowed from a SINGLE thread.
Poll is potentially blocking here as the Queue#poll() does not allow returning null if the queue is not empty. This is very different from the original Vyukov guarantees. See relaxedPoll() for the original semantics.
Poll reads consumerNode.next and:

  1. If it is null AND the queue is empty return null, if queue is not empty spin wait for value to become visible.
  2. If it is not null set it as the consumer node and return it's now evacuated value.
This means the consumerNode.value is always null, which is also the starting point for the queue. Because null values are not allowed to be offered this is the only node with it's value set to null at any one time.
Returns:E

a message from the queue if one is available, null iff empty

Annotations
@Override
See Also
MessagePassingQueue#poll(), java.util.Queue#poll()
relaxedOfferback to summary
public boolean relaxedOffer(E e)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.relaxedOffer.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.relaxedOffer.

Called from a producer thread subject to the restrictions appropriate to the implementation. As opposed to Queue#offer(Object) this method may return false without the queue being full.

Parameters
e:E

not null, will throw NPE if it is

Returns:boolean

true if element was inserted into the queue, false if unable to offer

Annotations
@Override
relaxedPeekback to summary
public E relaxedPeek()

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.relaxedPeek.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.relaxedPeek.

Called from the consumer thread subject to the restrictions appropriate to the implementation. As opposed to Queue#peek() this method may return null without the queue being empty.

Returns:E

a message from the queue if one is available, null if unable to peek

Annotations
@Override
relaxedPollback to summary
public E relaxedPoll()

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.relaxedPoll.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.relaxedPoll.

Called from the consumer thread subject to the restrictions appropriate to the implementation. As opposed to Queue#poll() this method may return null without the queue being empty.

Returns:E

a message from the queue if one is available, null if unable to poll

Annotations
@Override
sizeback to summary
public final int size()

Implements abstract java.util.AbstractCollection.size.

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.size, java.util.Collection.size.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.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. For some implementations this method may be O(n) rather than O(1).

Implementation Notes


This is an O(n) operation as we run through all the nodes and count them.
The accuracy of the value returned by this method is subject to races with producer/consumer threads. In particular when racing with the consumer thread this method may under estimate the size.

Returns:int

number of messages in the queue, between 0 and Integer#MAX_VALUE but less or equals to capacity (if bounded).

Annotations
@Override
See Also
java.util.Queue#size()
spinWaitForNextNodeback to summary
pack-priv LinkedQueueAtomicNode<E> spinWaitForNextNode(LinkedQueueAtomicNode<E> currNode)
toStringback to summary
public String toString()

Overrides java.util.AbstractCollection.toString.

Doc from java.util.AbstractCollection.toString.

Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String#valueOf(Object).

Returns:String

a string representation of this collection

Annotations
@Override