Package jadex.commons.collection
Class BlockingQueue<T>
- java.lang.Object
- 
- jadex.commons.collection.BlockingQueue<T>
 
- 
- All Implemented Interfaces:
- IBlockingQueue<T>
 
 public class BlockingQueue<T> extends java.lang.Object implements IBlockingQueue<T> A blocking queue allows to enqueue or dequeue elements. It blocks, when it is tried to dequeue an element, but the queue is empty.
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface jadex.commons.collection.IBlockingQueueIBlockingQueue.ClosedException
 
- 
 - 
Constructor SummaryConstructors Constructor Description BlockingQueue()Create a blocking queue.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Tdequeue()Dequeue an element.Tdequeue(long timeout)Dequeue an element.voidenqueue(T element)Enqueue an element.booleanisClosed()Check if the queue is closed.static voidmain(java.lang.String[] args)Main for testing.Tpeek()Peek the topmost element without dequeuing it.java.util.ListsetClosed(boolean closed)Open/close the queue.intsize()Return the size of the queue.static voidtest1(java.lang.String[] args)Main for testing.static voidtest1b(java.lang.String[] args)Main for testing.static voidtest2(java.lang.String[] args)Main for testing.
 
- 
- 
- 
Field Detail- 
elemsprotected java.util.List<T> elems The element storage.
 - 
closedprotected volatile boolean closed The queue state.
 - 
monitorprotected java.lang.Object monitor The monitor.
 
- 
 - 
Method Detail- 
enqueuepublic void enqueue(T element) Enqueue an element.- Specified by:
- enqueuein interface- IBlockingQueue<T>
- Parameters:
- element- The element.
 
 - 
dequeuepublic T dequeue(long timeout) throws IBlockingQueue.ClosedException, TimeoutException Dequeue an element.- Specified by:
- dequeuein interface- IBlockingQueue<T>
- Parameters:
- timeout- the time to wait (in millis) or -1 for no timeout.
- Returns:
- The element. When queue is empty the methods blocks until an element is added or the timeout occurs.
- Throws:
- IBlockingQueue.ClosedException
- TimeoutException
 
 - 
peekpublic T peek() throws IBlockingQueue.ClosedException Peek the topmost element without dequeuing it.- Specified by:
- peekin interface- IBlockingQueue<T>
- Returns:
- The element. When queue is empty the methods blocks until an element is added.
- Throws:
- IBlockingQueue.ClosedException
 
 - 
dequeuepublic T dequeue() throws IBlockingQueue.ClosedException Dequeue an element.- Specified by:
- dequeuein interface- IBlockingQueue<T>
- Returns:
- The element. When queue is empty the methods blocks until an element is added.
- Throws:
- IBlockingQueue.ClosedException
 
 - 
isClosedpublic boolean isClosed() Check if the queue is closed.- Specified by:
- isClosedin interface- IBlockingQueue<T>
 
 - 
setClosedpublic java.util.List setClosed(boolean closed) Open/close the queue.- Specified by:
- setClosedin interface- IBlockingQueue<T>
- Parameters:
- closed- The closed state.
- Returns:
- The remaining elements after the queue has been closed.
 
 - 
sizepublic int size() Return the size of the queue.- Specified by:
- sizein interface- IBlockingQueue<T>
- Returns:
- The size.
 
 - 
mainpublic static void main(java.lang.String[] args) throws java.lang.InterruptedExceptionMain for testing.- Throws:
- java.lang.InterruptedException
 
 - 
test1public static void test1(java.lang.String[] args) throws java.lang.InterruptedExceptionMain for testing.- Throws:
- java.lang.InterruptedException
 
 - 
test1bpublic static void test1b(java.lang.String[] args) throws java.lang.InterruptedExceptionMain for testing.- Throws:
- java.lang.InterruptedException
 
 - 
test2public static void test2(java.lang.String[] args) throws java.lang.InterruptedExceptionMain for testing.- Throws:
- java.lang.InterruptedException
 
 
- 
 
-