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

public Class MpscUnboundedXaddArrayQueue<E>

extends MpUnboundedXaddArrayQueue<MpscUnboundedXaddChunk<E>, E>
Class Inheritance
Imports
io.netty.util.internal.shaded.org.jctools.util.PortableJvmInfo

An MPSC array queue which grows unbounded in linked chunks.
Differently from MpscUnboundedArrayQueue it is designed to provide a better scaling when more producers are concurrently offering.
Users should be aware that poll() could spin while awaiting a new element to be available: to avoid this behaviour relaxedPoll() should be used instead, accounting for the semantic differences between the twos.
Author
https://github.com/franz1981

Field Summary

Inherited from io.netty.util.internal.shaded.org.jctools.queues.MpUnboundedXaddArrayQueue:
chunkMaskchunkShiftfreeChunksPoolmaxPooledChunks

Constructor Summary

AccessConstructor and Description
public
MpscUnboundedXaddArrayQueue(int
The buffer size to be used in each chunk of this queue
chunkSize
,
int
The maximum number of reused chunks kept around to avoid allocation, chunks are pre-allocated
maxPooledChunks
)

public

Method Summary

Modifier and TypeMethod and Description
public int
public int
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.
pack-priv final MpscUnboundedXaddChunk<E>
public boolean
offer(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 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.
private MpscUnboundedXaddChunk<E>
pollNextBuffer(MpscUnboundedXaddChunk<E> cChunk, long cIndex)

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.
private MpscUnboundedXaddChunk<E>
Inherited from io.netty.util.internal.shaded.org.jctools.queues.MpUnboundedXaddArrayQueue:
capacitychunkSizecurrentConsumerIndexcurrentProducerIndexdraindrainfillisEmptyiteratormaxPooledChunksmoveToNextConsumerChunkproducerChunkForIndexrelaxedOffersizetoString

Constructor Detail

MpscUnboundedXaddArrayQueueback to summary
public MpscUnboundedXaddArrayQueue(int chunkSize, int maxPooledChunks)
Parameters
chunkSize:int

The buffer size to be used in each chunk of this queue

maxPooledChunks:int

The maximum number of reused chunks kept around to avoid allocation, chunks are pre-allocated

MpscUnboundedXaddArrayQueueback to summary
public MpscUnboundedXaddArrayQueue(int chunkSize)

Method Detail

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

Overrides io.netty.util.internal.shaded.org.jctools.queues.MpUnboundedXaddArrayQueue.drain.

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
fillback to summary
public int fill(MessagePassingQueue.Supplier<E> s)

Overrides io.netty.util.internal.shaded.org.jctools.queues.MpUnboundedXaddArrayQueue.fill.

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
newChunkback to summary
pack-priv final MpscUnboundedXaddChunk<E> newChunk(long index, MpscUnboundedXaddChunk<E> prev, int chunkSize, boolean pooled)

Implements abstract io.netty.util.internal.shaded.org.jctools.queues.MpUnboundedXaddArrayQueue.newChunk.

Annotations
@Override
offerback to summary
public boolean offer(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.

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
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.

Returns:E

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

Annotations
@Override
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.

Returns:E

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

Annotations
@Override
pollNextBufferback to summary
private MpscUnboundedXaddChunk<E> pollNextBuffer(MpscUnboundedXaddChunk<E> cChunk, long cIndex)
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
spinForNextIfNotEmptyback to summary
private MpscUnboundedXaddChunk<E> spinForNextIfNotEmpty(MpscUnboundedXaddChunk<E> cChunk, long cIndex)