Class GrowableMpScArrayConsumerBlockingQueue<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.concurrent.BlockingQueue<T>, java.util.Queue<T>

    public class GrowableMpScArrayConsumerBlockingQueue<T>
    extends java.util.AbstractQueue<T>
    implements java.util.concurrent.BlockingQueue<T>
    This implements a BlockingQueue backed by an array with no fixed capacity.

    When the capacity is reached, data will be moved to a bigger array.

    This queue only allows 1 consumer thread to dequeue items and multiple producer threads.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T e)  
      void clear()  
      int drainTo​(java.util.Collection<? super T> c)  
      int drainTo​(java.util.Collection<? super T> c, int maxElements)  
      T element()  
      java.util.Iterator<T> iterator()  
      boolean offer​(T e)  
      boolean offer​(T e, long timeout, java.util.concurrent.TimeUnit unit)  
      T peek()  
      T poll()  
      T poll​(long timeout, java.util.concurrent.TimeUnit unit)  
      void put​(T e)  
      int remainingCapacity()  
      T remove()  
      int size()  
      T take()  
      java.lang.String toString()  
      • Methods inherited from class java.util.AbstractQueue

        addAll
      • Methods inherited from class java.util.AbstractCollection

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

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

        contains, remove
      • Methods inherited from interface java.util.Collection

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

        forEach
    • Constructor Detail

      • GrowableMpScArrayConsumerBlockingQueue

        public GrowableMpScArrayConsumerBlockingQueue()
      • GrowableMpScArrayConsumerBlockingQueue

        public GrowableMpScArrayConsumerBlockingQueue​(int initialCapacity)
    • Method Detail

      • remove

        public T remove()
        Specified by:
        remove in interface java.util.Queue<T>
        Overrides:
        remove in class java.util.AbstractQueue<T>
      • poll

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

        public T element()
        Specified by:
        element in interface java.util.Queue<T>
        Overrides:
        element in class java.util.AbstractQueue<T>
      • peek

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

        public boolean offer​(T e)
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<T>
        Specified by:
        offer in interface java.util.Queue<T>
      • put

        public void put​(T e)
        Specified by:
        put in interface java.util.concurrent.BlockingQueue<T>
      • add

        public boolean add​(T e)
        Specified by:
        add in interface java.util.concurrent.BlockingQueue<T>
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.Queue<T>
        Overrides:
        add in class java.util.AbstractQueue<T>
      • offer

        public boolean offer​(T e,
                             long timeout,
                             java.util.concurrent.TimeUnit unit)
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<T>
      • take

        public T take()
               throws java.lang.InterruptedException
        Specified by:
        take in interface java.util.concurrent.BlockingQueue<T>
        Throws:
        java.lang.InterruptedException
      • poll

        public T poll​(long timeout,
                      java.util.concurrent.TimeUnit unit)
               throws java.lang.InterruptedException
        Specified by:
        poll in interface java.util.concurrent.BlockingQueue<T>
        Throws:
        java.lang.InterruptedException
      • remainingCapacity

        public int remainingCapacity()
        Specified by:
        remainingCapacity in interface java.util.concurrent.BlockingQueue<T>
      • drainTo

        public int drainTo​(java.util.Collection<? super T> c)
        Specified by:
        drainTo in interface java.util.concurrent.BlockingQueue<T>
      • drainTo

        public int drainTo​(java.util.Collection<? super T> c,
                           int maxElements)
        Specified by:
        drainTo in interface java.util.concurrent.BlockingQueue<T>
      • clear

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

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in class java.util.AbstractCollection<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>
        Specified by:
        iterator in class java.util.AbstractCollection<T>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractCollection<T>