Class SpscLinkedArrayQueue<E>

  • Type Parameters:
    E - the element type of the queue
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Queue<E>

    public final class SpscLinkedArrayQueue<E>
    extends java.util.AbstractQueue<E>
    implements java.util.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, and it's RX Java 2 version.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean isEmpty()  
      java.util.Iterator<E> iterator()  
      boolean offer​(E e)
      boolean offer​(E first, E second)
      Offer two elements at the same time.
      E peek()  
      E poll()
      int size()  
      • Methods inherited from class java.util.AbstractQueue

        add, addAll, element, remove
      • Methods inherited from class java.util.AbstractCollection

        contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        addAll, contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Queue

        add, element, remove
    • Constructor Detail

      • SpscLinkedArrayQueue

        public SpscLinkedArrayQueue​(int bufferSize)
    • Method Detail

      • offer

        public boolean offer​(E e)

        This implementation is correct for single producer thread use only.

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

        public E poll()

        This implementation is correct for single consumer thread use only.

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

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

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

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

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

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Overrides:
        isEmpty in class java.util.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