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

public Class MpscLinkedAtomicQueue<E>

extends BaseLinkedAtomicQueue<E>
Class Inheritance
Imports
java.util.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 MpscLinkedQueue.java. This is a Java port of the MPSC algorithm as presented on 1024 Cores by D. Vyukov. The original has been adapted to Java and it's quirks with regards to memory model and layout:
  1. Use inheritance to ensure no false sharing occurs between producer/consumer node reference fields.
  2. Use XCHG functionality to the best of the JDK ability (see differences in JDK7/8 impls).
  3. Conform to java.util.Queue contract on poll. The original semantics are available via relaxedPoll.
The queue is initialized with a stub node which is set to both the producer and consumer node references. From this point follow the notes on offer/poll.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
fill(MessagePassingQueue.Supplier<E> s)

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

Stuff the queue with elements from the supplier.
public int
fill(MessagePassingQueue.Supplier<E> s, int limit)

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

Stuff the queue with up to limit elements from the supplier.
public void
private LinkedQueueAtomicNode<E>
public boolean
offer(final E
not null, will throw NPE if it is
e
)

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

Called from a producer thread subject to the restrictions appropriate to the implementation and according to the Queue#offer(Object) interface.
public boolean
remove(Object
element to be removed from this collection, if present
o
)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Collection.remove.

Removes a single instance of the specified element from this collection, if it is present (optional operation).
Inherited from io.netty.util.internal.shaded.org.jctools.queues.atomic.BaseLinkedAtomicQueue:
capacitydraindraindraingetSingleConsumerNodeValueisEmptyiteratornewNodenewNodepeekpollrelaxedOfferrelaxedPeekrelaxedPollsizespinWaitForNextNodetoString

Constructor Detail

MpscLinkedAtomicQueueback to summary
public MpscLinkedAtomicQueue()

Method Detail

fillback to summary
public int fill(MessagePassingQueue.Supplier<E> s)

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

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

Stuff the queue with elements from the supplier. Semantically similar to:

while(relaxedOffer(s.get());
There's no strong commitment to the queue being full at the end of a fill. Called from a producer thread subject to the restrictions appropriate to the implementation.

Unbounded queues will fill up the queue with a fixed amount rather than fill up to oblivion

Warning

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

Returns:int

the number of offered elements

Annotations
@Override
fillback to summary
public int fill(MessagePassingQueue.Supplier<E> s, int limit)

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

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

Stuff the queue with up to limit elements from the supplier. Semantically similar to:

for(int i=0; i < limit && relaxedOffer(s.get()); i++);

There's no strong commitment to the queue being full at the end of a fill. Called from a producer thread subject to the restrictions appropriate to the implementation

Warning

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

Returns:int

the number of offered elements

Annotations
@Override
fillback to summary
public void fill(MessagePassingQueue.Supplier<E> s, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit)

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

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

Stuff the queue with elements from the supplier forever. Semantically similar to:


 int idleCounter = 0;
 while (exit.keepRunning()) {
     E e = s.get();
     while (!relaxedOffer(e)) {
         idleCounter = wait.idle(idleCounter);
         continue;
     }
     idleCounter = 0;
 }

Called from a producer thread subject to the restrictions appropriate to the implementation. The main difference being that implementors MUST assure room in the queue is available BEFORE calling Supplier#get

Warning

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

Annotations
@Override
getNextConsumerNodeback to summary
private LinkedQueueAtomicNode<E> getNextConsumerNode(LinkedQueueAtomicNode<E> currConsumerNode)
offerback to summary
public boolean offer(final E e)

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

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

Called from a producer thread subject to the restrictions appropriate to the implementation and according to the Queue#offer(Object) interface.

IMPLEMENTATION NOTES:
Offer is allowed from multiple threads.
Offer allocates a new node and:

  1. Swaps it atomically with current producer node (only one producer 'wins')
  2. Sets the new node as the node following from the swapped producer node
This works because each producer is guaranteed to 'plant' a new node and link the old node. No 2 producers can get the same producer node as part of XCHG guarantee.
Parameters
e:E

not null, will throw NPE if it is

Returns:boolean

true if element was inserted into the queue, false iff full

Annotations
@Override
See Also
MessagePassingQueue#offer(Object), java.util.Queue#offer(java.lang.Object)
removeback to summary
public boolean remove(Object o)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Collection.remove.

Doc from java.util.Collection.remove.

Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).

This method is only safe to call from the (single) consumer thread, and is subject to best effort when racing with producers. This method is potentially blocking when "bubble"s in the queue are visible.

Parameters
o:Object

element to be removed from this collection, if present

Returns:boolean

true if an element was removed as a result of this call

Annotations
@Override