Class OneToOneConcurrentArrayQueue<E>

  • Type Parameters:
    E - type of the elements stored in the Queue.
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Queue<E>, Pipe<E>, QueuedPipe<E>

    public class OneToOneConcurrentArrayQueue<E>
    extends AbstractConcurrentArrayQueue<E>
    One producer to one consumer concurrent queue that is array backed. The algorithm is a variation of Fast Flow adapted to work with the Java Memory Model on arrays by using Unsafe.
    • Constructor Detail

      • OneToOneConcurrentArrayQueue

        public OneToOneConcurrentArrayQueue​(int requestedCapacity)
        Constructs queue with the requested capacity.
        Parameters:
        requestedCapacity - of the queue.
    • Method Detail

      • offer

        public boolean offer​(E e)
      • poll

        public E poll()
      • drain

        public int drain​(java.util.function.Consumer<E> elementConsumer)
        Drain the number of elements present in a collection at the time the operation starts.

        If possible, implementations should use smart batching to best handle burst traffic.

        Parameters:
        elementConsumer - Consumer for processing elements.
        Returns:
        the number of elements drained.
      • drain

        public int drain​(java.util.function.Consumer<E> elementConsumer,
                         int limit)
        Drain the minimum of a limit and the number of elements present in a collection at the time the operation starts.

        If possible, implementations should use smart batching to best handle burst traffic.

        Parameters:
        elementConsumer - Consumer for processing elements.
        limit - maximum number of elements to be drained in a drain operation.
        Returns:
        the number of elements drained.
      • drainTo

        public int drainTo​(java.util.Collection<? super E> target,
                           int limit)
        Drain available elements into the provided Collection up to a provided maximum limit of elements.

        If possible, implementations should use smart batching to best handle burst traffic.

        Parameters:
        target - in to which elements are drained.
        limit - maximum number of elements to be drained in a drain operation.
        Returns:
        the number of elements actually drained.