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

public Interface MessagePassingQueue<T>

Known Direct Implementers
io.netty.util.internal.shaded.org.jctools.queues.MpscBlockingConsumerArrayQueue, io.netty.util.internal.shaded.org.jctools.queues.MpscCompoundQueueL0Pad, io.netty.util.internal.shaded.org.jctools.queues.MpUnboundedXaddArrayQueue, io.netty.util.internal.shaded.org.jctools.queues.atomic.AtomicReferenceArrayQueue, io.netty.util.internal.shaded.org.jctools.queues.atomic.BaseLinkedAtomicQueuePad0, io.netty.util.internal.shaded.org.jctools.queues.atomic.BaseMpscLinkedAtomicArrayQueue, io.netty.util.internal.shaded.org.jctools.queues.atomic.BaseSpscLinkedAtomicArrayQueue, io.netty.util.Recycler.BlockingMessageQueue, io.netty.util.internal.shaded.org.jctools.queues.BaseLinkedQueuePad0, io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueue, io.netty.util.internal.shaded.org.jctools.queues.BaseSpscLinkedArrayQueue, io.netty.util.internal.shaded.org.jctools.queues.ConcurrentCircularArrayQueue
Type Parameters
<T>
the event/message type
Imports
java.util.Queue

Message passing queues are intended for concurrent method passing. A subset of Queue methods are provided with the same semantics, while further functionality which accomodates the concurrent usecase is also on offer.

Message passing queues provide happens before semantics to messages passed through, namely that writes made by the producer before offering the message are visible to the consuming thread after the message has been polled out of the queue.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
public static interface
public static interface
public static interface

Field Summary

Modifier and TypeField and Description
public static final int

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

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

public void
clear()

Removes all items from the queue.

public int

Returns:

the number of polled elements
drain
(MessagePassingQueue.Consumer<T> c, int limit)

Remove up to limit elements from the queue and hand to consume.

public int

Returns:

the number of polled elements
drain
(MessagePassingQueue.Consumer<T> c)

Remove all available item from the queue and hand to consume.

public void
drain(MessagePassingQueue.Consumer<T> c, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit)

Remove elements from the queue and hand to consume forever.

public int

Returns:

the number of offered elements
fill
(MessagePassingQueue.Supplier<T> s, int limit)

Stuff the queue with up to limit elements from the supplier.

public int

Returns:

the number of offered elements
fill
(MessagePassingQueue.Supplier<T> s)

Stuff the queue with elements from the supplier.

public void
fill(MessagePassingQueue.Supplier<T> s, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit)

Stuff the queue with elements from the supplier forever.

public boolean

Returns:

true if empty, false otherwise
isEmpty
()

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

public boolean

Returns:

true if element was inserted into the queue, false iff full
offer
(T
not null, will throw NPE if it is
e
)

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

public T

Returns:

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

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

public T

Returns:

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

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

public boolean

Returns:

true if element was inserted into the queue, false if unable to offer
relaxedOffer
(T
not null, will throw NPE if it is
e
)

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

public T

Returns:

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

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

public T

Returns:

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

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

public int

Returns:

number of messages in the queue, between 0 and Integer#MAX_VALUE but less or equals to capacity (if bounded).
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.

Field Detail

UNBOUNDED_CAPACITYback to summary
public static final int UNBOUNDED_CAPACITY

Method Detail

capacityback to summary
public int capacity()
Returns:int

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

clearback to summary
public void clear()

Removes all items from the queue. Called from the consumer thread subject to the restrictions appropriate to the implementation and according to the Queue#clear() interface.

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

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

Exceptions
IllegalArgumentException:
  • c is null
  • if limit is negative
drainback to summary
public int drain(MessagePassingQueue.Consumer<T> c)

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

Exceptions
IllegalArgumentException:
c is null
drainback to summary
public void drain(MessagePassingQueue.Consumer<T> c, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit)

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.

Exceptions
IllegalArgumentException:
c OR wait OR exit are null
fillback to summary
public int fill(MessagePassingQueue.Supplier<T> s, int limit)

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

Exceptions
IllegalArgumentException:
  • s is null
  • if limit is negative
fillback to summary
public int fill(MessagePassingQueue.Supplier<T> s)

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

Exceptions
IllegalArgumentException:
s is null
fillback to summary
public void fill(MessagePassingQueue.Supplier<T> s, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit)

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.

Exceptions
IllegalArgumentException:
s OR wait OR exit are null
isEmptyback to summary
public boolean isEmpty()

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

Returns:boolean

true if empty, false otherwise

offerback to summary
public boolean offer(T e)

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

Parameters
e:T

not null, will throw NPE if it is

Returns:boolean

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

peekback to summary
public T peek()

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

Returns:T

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

pollback to summary
public T poll()

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

Returns:T

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

relaxedOfferback to summary
public boolean relaxedOffer(T e)

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:T

not null, will throw NPE if it is

Returns:boolean

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

relaxedPeekback to summary
public T 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:T

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

relaxedPollback to summary
public T 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:T

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

sizeback to summary
public 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. For some implementations this method may be O(n) rather than O(1).

Returns:int

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

io.netty.util.internal.shaded.org.jctools.queues back to summary

public Interface MessagePassingQueue.Consumer<T>

Known Direct Implementers
io.netty.util.Recycler.LocalPool

Method Summary

Modifier and TypeMethod and Description
public void
accept(T
not null
e
)

This method will process an element already removed from the queue.

Method Detail

acceptback to summary
public void accept(T e)

This method will process an element already removed from the queue. This method is expected to never throw an exception.

Users should be aware that underlying queue implementations may upfront claim parts of the queue for batch operations and this will effect the view on the queue from the accept method. In particular size and any poll/peek methods may take the view that the full batch has already happened.

Warning

this method is assumed to never throw. Breaking this assumption can lead to a broken queue.

Parameters
e:T

not null

io.netty.util.internal.shaded.org.jctools.queues back to summary

public Interface MessagePassingQueue.ExitCondition


Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true as long as we should keep running
keepRunning
()

This method should be implemented such that the flag read or determination cannot be hoisted out of a loop which notmally means a volatile load, but with JDK9 VarHandles may mean getOpaque.

Method Detail

keepRunningback to summary
public boolean keepRunning()

This method should be implemented such that the flag read or determination cannot be hoisted out of a loop which notmally means a volatile load, but with JDK9 VarHandles may mean getOpaque.

Returns:boolean

true as long as we should keep running

io.netty.util.internal.shaded.org.jctools.queues back to summary

public Interface MessagePassingQueue.Supplier<T>


Method Summary

Modifier and TypeMethod and Description
public T

Returns:

new element, NEVER null
get
()

This method will return the next value to be written to the queue.

Method Detail

getback to summary
public T get()

This method will return the next value to be written to the queue. As such the queue implementations are commited to insert the value once the call is made.

Users should be aware that underlying queue implementations may upfront claim parts of the queue for batch operations and this will effect the view on the queue from the supplier method. In particular size and any offer methods may take the view that the full batch has already happened.

Warning

this method is assumed to never throw. Breaking this assumption can lead to a broken queue.

Warning

this method is assumed to never return null. Breaking this assumption can lead to a broken queue.

Returns:T

new element, NEVER null

io.netty.util.internal.shaded.org.jctools.queues back to summary

public Interface MessagePassingQueue.WaitStrategy


Method Summary

Modifier and TypeMethod and Description
public int

Returns:

new counter value to be used on subsequent idle cycle
idle
(int
idle calls counter, managed by the idle method until reset
idleCounter
)

This method can implement static or dynamic backoff.

Method Detail

idleback to summary
public int idle(int idleCounter)

This method can implement static or dynamic backoff. Dynamic backoff will rely on the counter for estimating how long the caller has been idling. The expected usage is:


int ic = 0;
while(true) {
  if(!isGodotArrived()) {
    ic = w.idle(ic);
    continue;
  }
  ic = 0;
  // party with Godot until he goes again
}

Parameters
idleCounter:int

idle calls counter, managed by the idle method until reset

Returns:int

new counter value to be used on subsequent idle cycle