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 boolean
closed
The queue state.protected java.lang.Object[]
elements
The elements in the queue.protected int
end
Insert position for the next element.protected java.lang.Object
monitor
The monitor.protected int
size
The size (cached for speed).protected int
start
Pointer 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 T
dequeue()
Remove an object from the queue (blocks until an element is available).T
dequeue(long timeout)
Dequeue an element.void
enqueue(java.lang.Object o)
Add an element to the end of the queue.boolean
isClosed()
Check if the queue is closed.T
peek()
Peek the topmost element without dequeuing it.java.util.List<T>
setClosed(boolean closed)
Open/close the queue.int
size()
Get the number of elements in the queue.java.lang.String
toString()
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:
size
in interfaceIBlockingQueue<T>
- Returns:
- The size.
-
enqueue
public void enqueue(java.lang.Object o)
Add an element to the end of the queue.- Specified by:
enqueue
in interfaceIBlockingQueue<T>
- Parameters:
o
- The element.
-
dequeue
public T dequeue(long timeout) throws IBlockingQueue.ClosedException, TimeoutException
Dequeue an element.- Specified by:
dequeue
in 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.ClosedException
TimeoutException
-
peek
public T peek() throws IBlockingQueue.ClosedException
Peek the topmost element without dequeuing it.- Specified by:
peek
in 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:
dequeue
in 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:
setClosed
in 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:
isClosed
in interfaceIBlockingQueue<T>
-
toString
public java.lang.String toString()
Create a string representation.- Overrides:
toString
in classjava.lang.Object
-
-