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.IBlockingQueue
IBlockingQueue.ClosedException
-
-
Field Summary
Fields 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 Summary
Constructors Constructor Description ArrayBlockingQueue()Create a new blocking queue.
-
Method Summary
All 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
-
elements
protected java.lang.Object[] elements
The elements in the queue.
-
start
protected int start
Pointer to the first element.
-
end
protected int end
Insert position for the next element.
-
size
protected int size
The size (cached for speed).
-
monitor
protected java.lang.Object monitor
The monitor.
-
closed
protected boolean closed
The queue state.
-
-
Method Detail
-
size
public int size()
Get the number of elements in the queue.- Specified by:
sizein interfaceIBlockingQueue<T>- Returns:
- The size.
-
enqueue
public void enqueue(java.lang.Object o)
Add an element to the end of the queue.- Specified by:
enqueuein interfaceIBlockingQueue<T>- Parameters:
o- The element.
-
dequeue
public T dequeue(long timeout) throws IBlockingQueue.ClosedException, TimeoutException
Dequeue an element.- Specified by:
dequeuein interfaceIBlockingQueue<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.ClosedExceptionTimeoutException
-
peek
public T peek() throws IBlockingQueue.ClosedException
Peek the topmost element without dequeuing it.- Specified by:
peekin interfaceIBlockingQueue<T>- Returns:
- The element. When queue is empty the methods blocks until an element is added.
- Throws:
IBlockingQueue.ClosedException
-
dequeue
public T dequeue()
Remove an object from the queue (blocks until an element is available).- Specified by:
dequeuein interfaceIBlockingQueue<T>- Returns:
- The element. When queue is empty the methods blocks until an element is added.
-
setClosed
public java.util.List<T> setClosed(boolean closed)
Open/close the queue.- Specified by:
setClosedin interfaceIBlockingQueue<T>- Parameters:
closed- The closed state.- Returns:
- The remaining elements after the queue has been closed.
-
isClosed
public boolean isClosed()
Check if the queue is closed.- Specified by:
isClosedin interfaceIBlockingQueue<T>
-
toString
public java.lang.String toString()
Create a string representation.- Overrides:
toStringin classjava.lang.Object
-
-