Class SpscExactAtomicArrayQueue<T>

  • Type Parameters:
    T - the value type held by this queue
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.Queue<T>

    public final class SpscExactAtomicArrayQueue<T>
    extends java.util.concurrent.atomic.AtomicReferenceArray<T>
    implements java.util.Queue<T>
    A single-producer single-consumer bounded queue with exact capacity tracking.

    This means that a queue of 10 will allow exactly 10 offers, however, the underlying storage is still power-of-2.

    The implementation uses field updaters and thus should be platform-safe.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) int capacitySkip  
      (package private) java.util.concurrent.atomic.AtomicLong consumerIndex  
      (package private) int mask  
      (package private) java.util.concurrent.atomic.AtomicLong producerIndex  
      private static long serialVersionUID  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T e)  
      boolean addAll​(java.util.Collection<? extends T> c)  
      void clear()  
      boolean contains​(java.lang.Object o)  
      boolean containsAll​(java.util.Collection<?> c)  
      T element()  
      boolean isEmpty()  
      java.util.Iterator<T> iterator()  
      boolean offer​(T value)  
      T peek()  
      T poll()  
      T remove()  
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean retainAll​(java.util.Collection<?> c)  
      int size()  
      java.lang.Object[] toArray()  
      <E> E[] toArray​(E[] a)  
      • Methods inherited from class java.util.concurrent.atomic.AtomicReferenceArray

        accumulateAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, get, getAcquire, getAndAccumulate, getAndSet, getAndUpdate, getOpaque, getPlain, 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
      • Methods inherited from interface java.util.Collection

        equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Field Detail

      • mask

        final int mask
      • capacitySkip

        final int capacitySkip
      • producerIndex

        final java.util.concurrent.atomic.AtomicLong producerIndex
      • consumerIndex

        final java.util.concurrent.atomic.AtomicLong consumerIndex
    • Constructor Detail

      • SpscExactAtomicArrayQueue

        public SpscExactAtomicArrayQueue​(int capacity)
    • Method Detail

      • offer

        public boolean offer​(T value)
        Specified by:
        offer in interface java.util.Queue<T>
      • poll

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

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

        public void clear()
        Specified by:
        clear in interface java.util.Collection<T>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<T>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<T>
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<T>
      • toArray

        public <E> E[] toArray​(E[] a)
        Specified by:
        toArray in interface java.util.Collection<T>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<T>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<T>
      • addAll

        public boolean addAll​(java.util.Collection<? extends T> c)
        Specified by:
        addAll in interface java.util.Collection<T>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<T>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<T>
      • add

        public boolean add​(T e)
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.Queue<T>
      • remove

        public T remove()
        Specified by:
        remove in interface java.util.Queue<T>
      • element

        public T element()
        Specified by:
        element in interface java.util.Queue<T>