Package org.jgroups.util
Class ConcurrentLinkedBlockingQueue2<T>
- java.lang.Object
- 
- java.util.AbstractCollection<E>
- 
- java.util.AbstractQueue<E>
- 
- java.util.concurrent.ConcurrentLinkedQueue<T>
- 
- org.jgroups.util.ConcurrentLinkedBlockingQueue2<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 ConcurrentLinkedBlockingQueue2<T> extends java.util.concurrent.ConcurrentLinkedQueue<T> implements java.util.concurrent.BlockingQueue<T>Attempt at writing a fast transfer queue, which is bounded. The take() method blocks until there is an element, but the offer() method drops the element and returns if the queue is full (doesn't block). The design assumes a number of producers but only one consumer. The consumer only blocks when the queue is empty (on the not-empty condition), the producers block when the queue is full (on the not-full condition). The producers increment a count atomically and if the count is greater than the capacity, they block on the not-full condition. The consumer decrements the condition and signals the not-full condition when the count is capacity -1 (from capacity to capacity-1). The producers signal not-empty when the count is 1 (from 0 to 1)- Since:
- 3.5
- Author:
- Bela Ban
- See Also:
- Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected intcapacityprotected java.util.concurrent.atomic.AtomicIntegercountprotected java.util.concurrent.locks.Conditionnot_emptyprotected java.util.concurrent.locks.Locknot_empty_lock
 - 
Constructor SummaryConstructors Constructor Description ConcurrentLinkedBlockingQueue2(int capacity)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddecrCount()intdrainTo(java.util.Collection<? super T> c)intdrainTo(java.util.Collection<? super T> c, int maxElements)protected voidincrCount()booleanoffer(T t)Drops elements if capacity has been reached.booleanoffer(T t, long timeout, java.util.concurrent.TimeUnit unit)Tpoll()Tpoll(long timeout, java.util.concurrent.TimeUnit unit)voidput(T t)intremainingCapacity()booleanremove(java.lang.Object o)intsize()Ttake()protected voidwaitForNotEmpty()- 
Methods inherited from class java.util.concurrent.ConcurrentLinkedQueueadd, addAll, clear, contains, forEach, isEmpty, iterator, peek, removeAll, removeIf, retainAll, spliterator, toArray, toArray, toString
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
- 
 
- 
- 
- 
Method Detail- 
offerpublic boolean offer(T t) Drops elements if capacity has been reached. That's OK for the ThreadPoolExecutor as dropped messages will get retransmitted
 - 
takepublic T take() throws java.lang.InterruptedException - Specified by:
- takein interface- java.util.concurrent.BlockingQueue<T>
- Throws:
- java.lang.InterruptedException
 
 - 
pollpublic T poll() 
 - 
pollpublic T poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException - Specified by:
- pollin interface- java.util.concurrent.BlockingQueue<T>
- Throws:
- java.lang.InterruptedException
 
 - 
removepublic boolean remove(java.lang.Object o) 
 - 
remainingCapacitypublic int remainingCapacity() - Specified by:
- remainingCapacityin interface- java.util.concurrent.BlockingQueue<T>
 
 - 
drainTopublic int drainTo(java.util.Collection<? super T> c) - Specified by:
- drainToin interface- java.util.concurrent.BlockingQueue<T>
 
 - 
putpublic void put(T t) throws java.lang.InterruptedException - Specified by:
- putin interface- java.util.concurrent.BlockingQueue<T>
- Throws:
- java.lang.InterruptedException
 
 - 
offerpublic boolean offer(T t, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException - Specified by:
- offerin interface- java.util.concurrent.BlockingQueue<T>
- Throws:
- java.lang.InterruptedException
 
 - 
sizepublic int size() 
 - 
drainTopublic int drainTo(java.util.Collection<? super T> c, int maxElements) - Specified by:
- drainToin interface- java.util.concurrent.BlockingQueue<T>
 
 - 
waitForNotEmptyprotected void waitForNotEmpty() throws java.lang.InterruptedException- Throws:
- java.lang.InterruptedException
 
 - 
decrCountprotected void decrCount() 
 - 
incrCountprotected void incrCount() 
 
- 
 
-