Class 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:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      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 isEmpty()
      Query if the queue is empty or not.
      boolean offer​(int value)
      Offer the given value to the queue.
      int poll()
      Remove and return the next value from the queue, or return the "empty" value if the queue is empty.
      int size()
      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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MpscAtomicIntegerArrayQueue

        public MpscAtomicIntegerArrayQueue​(int capacity,
                                           int emptyValue)
    • Method Detail

      • 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.
      • 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 {@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.