Package io.netty.util.concurrent
Class MpscAtomicIntegerArrayQueue
- java.lang.Object
-
- java.util.concurrent.atomic.AtomicIntegerArray
-
- io.netty.util.concurrent.MpscAtomicIntegerArrayQueue
-
- All Implemented Interfaces:
MpscIntQueue,java.io.Serializable
@UnstableApi public final class MpscAtomicIntegerArrayQueue extends java.util.concurrent.atomic.AtomicIntegerArray implements MpscIntQueue
This implementation is based on MpscAtomicUnpaddedArrayQueue from JCTools.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscAtomicIntegerArrayQueue>CONSUMER_INDEXprivate longconsumerIndexprivate intemptyValueprivate intmaskprivate static java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscAtomicIntegerArrayQueue>PRODUCER_INDEXprivate static java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscAtomicIntegerArrayQueue>PRODUCER_LIMITprivate longproducerIndexprivate longproducerLimitprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description MpscAtomicIntegerArrayQueue(int capacity, int emptyValue)Create a new queue instance of the given size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intdrain(int limit, IntConsumer consumer)Remove up to the given limit of elements from the queue, and pass them to the consumer in order.intfill(int limit, 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.-
Methods inherited from class java.util.concurrent.atomic.AtomicIntegerArray
accumulateAndGet, addAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, decrementAndGet, get, getAcquire, getAndAccumulate, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, getAndUpdate, getOpaque, getPlain, incrementAndGet, lazySet, length, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
PRODUCER_INDEX
private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscAtomicIntegerArrayQueue> PRODUCER_INDEX
-
PRODUCER_LIMIT
private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscAtomicIntegerArrayQueue> PRODUCER_LIMIT
-
CONSUMER_INDEX
private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscAtomicIntegerArrayQueue> CONSUMER_INDEX
-
mask
private final int mask
-
emptyValue
private final int emptyValue
-
producerIndex
private volatile long producerIndex
-
producerLimit
private volatile long producerLimit
-
consumerIndex
private volatile long consumerIndex
-
-
Constructor Detail
-
MpscAtomicIntegerArrayQueue
public MpscAtomicIntegerArrayQueue(int capacity, 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:
capacity- 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.
-
-
Method Detail
-
offer
public boolean offer(int value)
Description copied from interface:MpscIntQueueOffer the given value to the queue. This will throw an exception if the given value is the "empty" value.- Specified by:
offerin interfaceMpscIntQueue- 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
public int poll()
Description copied from interface:MpscIntQueueRemove and return the next value from the queue, or return the "empty" value if the queue is empty.- Specified by:
pollin interfaceMpscIntQueue- Returns:
- The next value or the "empty" value.
-
drain
public int drain(int limit, IntConsumer consumer)Description copied from interface:MpscIntQueueRemove up to the given limit of elements from the queue, and pass them to the consumer in order.- Specified by:
drainin interfaceMpscIntQueue- 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
public int fill(int limit, IntSupplier supplier)Description copied from interface:MpscIntQueueAdd up to the given limit of elements to this queue, from the given supplier.- Specified by:
fillin interfaceMpscIntQueue- 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
public boolean isEmpty()
Description copied from interface:MpscIntQueueQuery 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.
- Specified by:
isEmptyin interfaceMpscIntQueue- Returns:
trueif the queue was observed to be empty, otherwise {@code false.
-
size
public int size()
Description copied from interface:MpscIntQueueQuery 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.
- Specified by:
sizein interfaceMpscIntQueue- Returns:
- An estimate of the number of elements observed in the queue.
-
-