Class ConcurrentLinkedBlockingQueue<T>

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

    public class ConcurrentLinkedBlockingQueue<T>
    extends java.util.concurrent.ConcurrentLinkedQueue<T>
    implements java.util.concurrent.BlockingQueue<T>
    Concurrent queue which offers optional blocking on empty / full. Designed for multiple producers, but only a single consumer. Only methods required by message bundlers (offer(), poll(), drainTo(), size() etc) are implemented. Might add more implementation as needed.
    See https://issues.redhat.com/browse/JGRP-2890 for details
    Since:
    5.5.0
    Author:
    Bela Ban
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean block_on_empty  
      protected boolean block_on_full  
      protected int capacity  
      protected java.util.function.IntUnaryOperator INCR  
      protected java.util.concurrent.locks.Lock lock  
      protected java.util.concurrent.locks.Condition not_empty  
      protected java.util.concurrent.locks.Condition not_full  
      protected java.util.concurrent.atomic.AtomicInteger size  
    • Constructor Summary

      Constructors 
      Constructor Description
      ConcurrentLinkedBlockingQueue​(int capacity, boolean block_on_empty, boolean block_on_full)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T t)  
      boolean addAll​(java.util.Collection<? extends T> c)  
      void clear()  
      int drainTo​(java.util.Collection<? super T> c)  
      int drainTo​(java.util.Collection<? super T> c, int max)  
      boolean isEmpty()  
      boolean offer​(T t)  
      boolean offer​(T t, long timeout, java.util.concurrent.TimeUnit unit)  
      T poll()  
      T poll​(long timeout, java.util.concurrent.TimeUnit unit)  
      void put​(T t)  
      int remainingCapacity()  
      T remove()  
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean removeIf​(java.util.function.Predicate<? super T> filter)  
      boolean retainAll​(java.util.Collection<?> c)  
      protected void signalNotEmpty()  
      protected void signalNotFull()  
      int size()  
      T take()  
      • Methods inherited from class java.util.concurrent.ConcurrentLinkedQueue

        contains, forEach, iterator, peek, spliterator, toArray, toArray, toString
      • Methods inherited from class java.util.AbstractQueue

        element
      • Methods inherited from class java.util.AbstractCollection

        containsAll
      • 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
      • Methods inherited from interface java.util.Collection

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

        forEach
      • Methods inherited from interface java.util.Queue

        element, peek
    • Field Detail

      • capacity

        protected final int capacity
      • size

        protected final java.util.concurrent.atomic.AtomicInteger size
      • block_on_empty

        protected final boolean block_on_empty
      • block_on_full

        protected final boolean block_on_full
      • lock

        protected final java.util.concurrent.locks.Lock lock
      • not_empty

        protected final java.util.concurrent.locks.Condition not_empty
      • not_full

        protected final java.util.concurrent.locks.Condition not_full
      • INCR

        protected final java.util.function.IntUnaryOperator INCR
    • Constructor Detail

      • ConcurrentLinkedBlockingQueue

        public ConcurrentLinkedBlockingQueue​(int capacity,
                                             boolean block_on_empty,
                                             boolean block_on_full)
    • Method Detail

      • put

        public void put​(T t)
                 throws java.lang.InterruptedException
        Specified by:
        put in interface java.util.concurrent.BlockingQueue<T>
        Throws:
        java.lang.InterruptedException
      • add

        public boolean add​(T t)
        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.concurrent.ConcurrentLinkedQueue<T>
      • addAll

        public boolean addAll​(java.util.Collection<? extends T> c)
        Specified by:
        addAll in interface java.util.Collection<T>
        Overrides:
        addAll in class java.util.concurrent.ConcurrentLinkedQueue<T>
      • offer

        public boolean offer​(T t)
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<T>
        Specified by:
        offer in interface java.util.Queue<T>
        Overrides:
        offer in class java.util.concurrent.ConcurrentLinkedQueue<T>
      • offer

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

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

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<T>
        Overrides:
        isEmpty in class java.util.concurrent.ConcurrentLinkedQueue<T>
      • poll

        public T poll()
        Specified by:
        poll in interface java.util.Queue<T>
        Overrides:
        poll in class java.util.concurrent.ConcurrentLinkedQueue<T>
      • 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
      • take

        public T take()
               throws java.lang.InterruptedException
        Specified by:
        take in interface java.util.concurrent.BlockingQueue<T>
        Throws:
        java.lang.InterruptedException
      • 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 max)
        Specified by:
        drainTo in interface java.util.concurrent.BlockingQueue<T>
      • remove

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

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

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<T>
        Overrides:
        removeAll in class java.util.concurrent.ConcurrentLinkedQueue<T>
      • removeIf

        public boolean removeIf​(java.util.function.Predicate<? super T> filter)
        Specified by:
        removeIf in interface java.util.Collection<T>
        Overrides:
        removeIf in class java.util.concurrent.ConcurrentLinkedQueue<T>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<T>
        Overrides:
        retainAll in class java.util.concurrent.ConcurrentLinkedQueue<T>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Overrides:
        size in class java.util.concurrent.ConcurrentLinkedQueue<T>
      • remainingCapacity

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

        protected void signalNotEmpty()
      • signalNotFull

        protected void signalNotFull()