Package io.netty.util.concurrent
Interface MpscIntQueue
-
- All Known Implementing Classes:
MpscIntQueue.MpscAtomicIntegerArrayQueue
public interface MpscIntQueueA multi-producer (concurrent and thread-safeofferandfill), single-consumer (single-threadedpollanddrain) queue of primitive integers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classMpscIntQueue.MpscAtomicIntegerArrayQueueThis implementation is based on MpscAtomicUnpaddedArrayQueue from JCTools.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static MpscIntQueuecreate(int size, int emptyValue)Create a new queue instance of the given size.intdrain(int limit, java.util.function.IntConsumer consumer)Remove up to the given limit of elements from the queue, and pass them to the consumer in order.intfill(int limit, java.util.function.IntSupplier supplier)Add up to the given limit of elements to this queue, from the given supplier.booleanisEmpty()Query if the queue is empty or not.booleanoffer(int value)Offer the given value to the queue.intpoll()Remove and return the next value from the queue, or return the "empty" value if the queue is empty.intsize()Query the number of elements currently in the queue.
-
-
-
Method Detail
-
create
static MpscIntQueue create(int size, int emptyValue)
Create a new queue instance of the given size.Note: the size of the queue may be rounded up to nearest power-of-2.
- Parameters:
size- The required fixed size of the queue.emptyValue- The special value that the queue should use to signal the "empty" case. This value will be returned frompoll()when the queue is empty, and giving this value tooffer(int)will cause an exception to be thrown.- Returns:
- The queue instance.
-
offer
boolean offer(int value)
Offer the given value to the queue. This will throw an exception if the given value is the "empty" value.- Parameters:
value- The value to add to the queue.- Returns:
trueif the value was added to the queue, orfalseif the value could not be added because the queue is full.
-
poll
int poll()
Remove and return the next value from the queue, or return the "empty" value if the queue is empty.- Returns:
- The next value or the "empty" value.
-
drain
int drain(int limit, java.util.function.IntConsumer consumer)Remove up to the given limit of elements from the queue, and pass them to the consumer in order.- Parameters:
limit- The maximum number of elements to dequeue.consumer- The consumer to pass the removed elements to.- Returns:
- The actual number of elements removed.
-
fill
int fill(int limit, java.util.function.IntSupplier supplier)Add up to the given limit of elements to this queue, from the given supplier.- Parameters:
limit- The maximum number of elements to enqueue.supplier- The supplier to obtain the elements from.- Returns:
- The actual number of elements added.
-
isEmpty
boolean isEmpty()
Query if the queue is empty or not.This method is inherently racy and the result may be out of date by the time the method returns.
- Returns:
trueif the queue was observed to be empty, otherwise {@code false.
-
size
int size()
Query the number of elements currently in the queue.This method is inherently racy and the result may be out of date by the time the method returns.
- Returns:
- An estimate of the number of elements observed in the queue.
-
-