Class SpscLinkedArrayQueue<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
org.jboss.resteasy.microprofile.client.publisher.SpscLinkedArrayQueue<E>
Type Parameters:
E - the element type of the queue
All Implemented Interfaces:
Iterable<E>, Collection<E>, Queue<E>

public final class SpscLinkedArrayQueue<E> extends AbstractQueue<E> implements Queue<E>
A single-producer single-consumer array-backed queue which can allocate new arrays in case the consumer is slower than the producer.

Code inspired from https://github.com/JCTools/JCTools/blob/master/jctools-core/src/main/java/org/jctools/queues/atomic.

  • Constructor Details

    • SpscLinkedArrayQueue

      public SpscLinkedArrayQueue(int bufferSize)
  • Method Details

    • roundToPowerOfTwo

      public static int roundToPowerOfTwo(int value)
      Find the next larger positive power of two value up from the given value. If value is a power of two then this value will be returned.
      Parameters:
      value - from which next positive power of two will be found.
      Returns:
      the next positive power of 2 or this value if it is a power of 2.
    • offer

      public boolean offer(E e)

      This implementation is correct for single producer thread use only.

      Specified by:
      offer in interface Queue<E>
    • poll

      public E poll()

      This implementation is correct for single consumer thread use only.

      Specified by:
      poll in interface Queue<E>
    • peek

      public E peek()
      Specified by:
      peek in interface Queue<E>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
      Overrides:
      clear in class AbstractQueue<E>
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in class AbstractCollection<E>
    • size

      public int size()
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in class AbstractCollection<E>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<E>
      Overrides:
      isEmpty in class AbstractCollection<E>
    • offer

      public boolean offer(E first, E second)
      Offer two elements at the same time.

      Don't use the regular offer() with this at all!

      Parameters:
      first - the first value, not null
      second - the second value, not null
      Returns:
      true if the queue accepted the two new values