Interface MpscIntQueue

All Known Implementing Classes:
MpscAtomicIntegerArrayQueue

public interface MpscIntQueue
A multi-producer (concurrent and thread-safe offer and fill), single-consumer (single-threaded poll and drain) queue of primitive integers.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    drain(int limit, 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, 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.
  • Method Details

    • 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:
      true if the value was added to the queue, or false if 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, 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, 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:
      true if the queue was observed to be empty, otherwise
      invalid @code
      {@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.