Class SizeBlockingQueue<E>

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

    public class SizeBlockingQueue<E>
    extends java.util.AbstractQueue<E>
    implements java.util.concurrent.BlockingQueue<E>
    A size based queue wrapping another blocking queue to provide (somewhat relaxed) capacity checks. Mainly makes sense to use with blocking queues that are unbounded to provide the ability to do capacity verification.
    • Constructor Summary

      Constructors 
      Constructor Description
      SizeBlockingQueue​(java.util.concurrent.BlockingQueue<E> queue, int capacity)  
    • Method Summary

      Modifier and Type Method Description
      int capacity()  
      boolean contains​(java.lang.Object o)  
      boolean containsAll​(java.util.Collection<?> c)  
      int drainTo​(java.util.Collection<? super E> c)  
      int drainTo​(java.util.Collection<? super E> c, int maxElements)  
      void forcePut​(E e)
      Forces adding an element to the queue, without doing size checks.
      java.util.Iterator<E> iterator()  
      boolean offer​(E e)  
      boolean offer​(E e, long timeout, java.util.concurrent.TimeUnit unit)  
      E peek()  
      E poll()  
      E poll​(long timeout, java.util.concurrent.TimeUnit unit)  
      void put​(E e)  
      int remainingCapacity()  
      boolean remove​(java.lang.Object o)  
      int size()  
      E take()  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] a)  
      • Methods inherited from class java.util.AbstractQueue

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

        isEmpty, removeAll, retainAll, toString
      • 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

        add
      • Methods inherited from interface java.util.Collection

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

        forEach
      • Methods inherited from interface java.util.Queue

        element, remove
    • Constructor Detail

      • SizeBlockingQueue

        public SizeBlockingQueue​(java.util.concurrent.BlockingQueue<E> queue,
                                 int capacity)
    • Method Detail

      • size

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

        public int capacity()
      • 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>
      • peek

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

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

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

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.concurrent.BlockingQueue<E>
        Specified by:
        remove in interface java.util.Collection<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
      • forcePut

        public void forcePut​(E e)
                      throws java.lang.InterruptedException
        Forces adding an element to the queue, without doing size checks.
        Throws:
        java.lang.InterruptedException
      • offer

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

        public boolean offer​(E e,
                             long timeout,
                             java.util.concurrent.TimeUnit unit)
                      throws java.lang.InterruptedException
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • put

        public void put​(E e)
                 throws java.lang.InterruptedException
        Specified by:
        put in interface java.util.concurrent.BlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • take

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

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

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

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

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

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

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.concurrent.BlockingQueue<E>
        Specified by:
        contains in interface java.util.Collection<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<E>
        Overrides:
        containsAll in class java.util.AbstractCollection<E>