Class MpscIntQueue.MpscAtomicIntegerArrayQueue

java.lang.Object
java.util.concurrent.atomic.AtomicIntegerArray
io.netty.util.concurrent.MpscIntQueue.MpscAtomicIntegerArrayQueue
All Implemented Interfaces:
MpscIntQueue, java.io.Serializable
Enclosing interface:
MpscIntQueue

public static final class MpscIntQueue.MpscAtomicIntegerArrayQueue extends java.util.concurrent.atomic.AtomicIntegerArray implements MpscIntQueue
This implementation is based on MpscAtomicUnpaddedArrayQueue from JCTools.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface MpscIntQueue

    MpscIntQueue.MpscAtomicIntegerArrayQueue
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscIntQueue.MpscAtomicIntegerArrayQueue>
     
    private long
     
    private final int
     
    private final int
     
    private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscIntQueue.MpscAtomicIntegerArrayQueue>
     
    private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscIntQueue.MpscAtomicIntegerArrayQueue>
     
    private long
     
    private long
     
    private static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    MpscAtomicIntegerArrayQueue(int capacity, int emptyValue)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    int
    fill(int limit, java.util.function.IntSupplier supplier)
    Add up to the given limit of elements to this queue, from the given supplier.
    boolean
    Query if the queue is empty or not.
    boolean
    offer(int value)
    Offer the given value to the queue.
    int
    Remove and return the next value from the queue, or return the "empty" value if the queue is empty.
    int
    Query the number of elements currently in the queue.
    int
    weakPeekReduce(int limit, int initial, java.util.function.IntBinaryOperator op)
    Peek at all available elements and compute a reduction.

    Methods inherited from class java.util.concurrent.atomic.AtomicIntegerArray

    accumulateAndGet, addAndGet, compareAndSet, decrementAndGet, get, getAndAccumulate, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, getAndUpdate, incrementAndGet, lazySet, length, set, toString, updateAndGet, weakCompareAndSet

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • PRODUCER_INDEX

      private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscIntQueue.MpscAtomicIntegerArrayQueue> PRODUCER_INDEX
    • PRODUCER_LIMIT

      private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscIntQueue.MpscAtomicIntegerArrayQueue> PRODUCER_LIMIT
    • CONSUMER_INDEX

      private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<MpscIntQueue.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 Details

    • MpscAtomicIntegerArrayQueue

      public MpscAtomicIntegerArrayQueue(int capacity, int emptyValue)
  • Method Details

    • offer

      public boolean offer(int value)
      Description copied from interface: MpscIntQueue
      Offer the given value to the queue. This will throw an exception if the given value is the "empty" value.
      Specified by:
      offer in interface MpscIntQueue
      Parameters:
      value - The value to add to the queue.
      Returns:
      true if the value was added to the queue, or false if the value could not be added because the queue is full.
    • poll

      public int poll()
      Description copied from interface: MpscIntQueue
      Remove and return the next value from the queue, or return the "empty" value if the queue is empty.
      Specified by:
      poll in interface MpscIntQueue
      Returns:
      The next value or the "empty" value.
    • drain

      public int drain(int limit, java.util.function.IntConsumer consumer)
      Description copied from interface: MpscIntQueue
      Remove up to the given limit of elements from the queue, and pass them to the consumer in order.
      Specified by:
      drain in interface MpscIntQueue
      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, java.util.function.IntSupplier supplier)
      Description copied from interface: MpscIntQueue
      Add up to the given limit of elements to this queue, from the given supplier.
      Specified by:
      fill in interface MpscIntQueue
      Parameters:
      limit - The maximum number of elements to enqueue.
      supplier - The supplier to obtain the elements from.
      Returns:
      The actual number of elements added.
    • weakPeekReduce

      public int weakPeekReduce(int limit, int initial, java.util.function.IntBinaryOperator op)
      Description copied from interface: MpscIntQueue
      Peek at all available elements and compute a reduction. The elements are not removed, and the iteration is weakly consistent.
      Specified by:
      weakPeekReduce in interface MpscIntQueue
      Parameters:
      limit - The maximum number of elements to process.
      initial - The initial value to the reduction operation.
      op - The reduction operation, taking a prior result and an element, and producing a new result.
      Returns:
      The last result of the reduction operation.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: MpscIntQueue
      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.

      Specified by:
      isEmpty in interface MpscIntQueue
      Returns:
      true if the queue was observed to be empty, otherwise
      invalid @code
      {@code false.
    • size

      public int size()
      Description copied from interface: MpscIntQueue
      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.

      Specified by:
      size in interface MpscIntQueue
      Returns:
      An estimate of the number of elements observed in the queue.