Package jadex.collection
Class ArrayBlockingQueue<T>
java.lang.Object
jadex.collection.ArrayBlockingQueue<T>
- All Implemented Interfaces:
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.collection.IBlockingQueue
IBlockingQueue.ClosedException
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondequeue()
Remove an object from the queue (blocks until an element is available).dequeue
(long timeout) Dequeue an element.void
Add an element to the end of the queue.boolean
isClosed()
Check if the queue is closed.peek()
Peek the topmost element without dequeuing it.setClosed
(boolean closed) Open/close the queue.int
size()
Get the number of elements in the queue.toString()
Create a string representation.
-
Field Details
-
elements
The elements in the queue. -
start
protected int startPointer to the first element. -
end
protected int endInsert position for the next element. -
size
protected int sizeThe size (cached for speed). -
monitor
The monitor. -
closed
protected boolean closedThe queue state.
-
-
Constructor Details
-
ArrayBlockingQueue
public ArrayBlockingQueue()Create a new blocking queue.
-
-
Method Details
-
size
public int size()Get the number of elements in the queue.- Specified by:
size
in interfaceIBlockingQueue<T>
- Returns:
- The size.
-
enqueue
Add an element to the end of the queue.- Specified by:
enqueue
in interfaceIBlockingQueue<T>
- Parameters:
o
- The element.
-
dequeue
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
jadex.common.TimeoutException
-
peek
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
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
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
Create a string representation.
-