Package jadex.commons.collection
Class ArrayBlockingQueue<T>
- java.lang.Object
- 
- jadex.commons.collection.ArrayBlockingQueue<T>
 
- 
- All Implemented Interfaces:
- IBlockingQueue<T>
 
 public class ArrayBlockingQueue<T> extends java.lang.Object implements IBlockingQueue<T> Blocking queue implemented as array. The array is expanded automatically when the queue grows.
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface jadex.commons.collection.IBlockingQueueIBlockingQueue.ClosedException
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected booleanclosedThe queue state.protected java.lang.Object[]elementsThe elements in the queue.protected intendInsert position for the next element.protected java.lang.ObjectmonitorThe monitor.protected intsizeThe size (cached for speed).protected intstartPointer to the first element.
 - 
Constructor SummaryConstructors Constructor Description ArrayBlockingQueue()Create a new blocking queue.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description Tdequeue()Remove an object from the queue (blocks until an element is available).Tdequeue(long timeout)Dequeue an element.voidenqueue(java.lang.Object o)Add an element to the end of the queue.booleanisClosed()Check if the queue is closed.Tpeek()Peek the topmost element without dequeuing it.java.util.List<T>setClosed(boolean closed)Open/close the queue.intsize()Get the number of elements in the queue.java.lang.StringtoString()Create a string representation.
 
- 
- 
- 
Field Detail- 
elementsprotected java.lang.Object[] elements The elements in the queue.
 - 
startprotected int start Pointer to the first element.
 - 
endprotected int end Insert position for the next element.
 - 
sizeprotected int size The size (cached for speed).
 - 
monitorprotected java.lang.Object monitor The monitor.
 - 
closedprotected boolean closed The queue state.
 
- 
 - 
Method Detail- 
sizepublic int size() Get the number of elements in the queue.- Specified by:
- sizein interface- IBlockingQueue<T>
- Returns:
- The size.
 
 - 
enqueuepublic void enqueue(java.lang.Object o) Add an element to the end of the queue.- Specified by:
- enqueuein interface- IBlockingQueue<T>
- Parameters:
- o- 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() Remove an object from the queue (blocks until an element is available).- Specified by:
- dequeuein interface- IBlockingQueue<T>
- Returns:
- The element. When queue is empty the methods blocks until an element is added.
 
 - 
setClosedpublic java.util.List<T> 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.
 
 - 
isClosedpublic boolean isClosed() Check if the queue is closed.- Specified by:
- isClosedin interface- IBlockingQueue<T>
 
 - 
toStringpublic java.lang.String toString() Create a string representation.- Overrides:
- toStringin class- java.lang.Object
 
 
- 
 
-