Package jadex.collection
Class BlockingQueue<T>
java.lang.Object
jadex.collection.BlockingQueue<T>
- All Implemented Interfaces:
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.collection.IBlockingQueue
IBlockingQueue.ClosedException -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondequeue()Dequeue an element.dequeue(long timeout) Dequeue an element.voidEnqueue an element.booleanisClosed()Check if the queue is closed.static voidMain for testing.peek()Peek the topmost element without dequeuing it.setClosed(boolean closed) Open/close the queue.intsize()Return the size of the queue.static voidMain for testing.static voidMain for testing.static voidMain for testing.
-
Field Details
-
elems
The element storage. -
closed
protected volatile boolean closedThe queue state. -
monitor
The monitor.
-
-
Constructor Details
-
BlockingQueue
public BlockingQueue()Create a blocking queue.
-
-
Method Details
-
enqueue
Enqueue an element.- Specified by:
enqueuein interfaceIBlockingQueue<T>- Parameters:
element- The element.
-
dequeue
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.ClosedExceptionjadex.common.TimeoutException
-
peek
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
Dequeue an element.- Specified by:
dequeuein interfaceIBlockingQueue<T>- Returns:
- The element. When queue is empty the methods blocks until an element is added.
- Throws:
IBlockingQueue.ClosedException
-
isClosed
public boolean isClosed()Check if the queue is closed.- Specified by:
isClosedin interfaceIBlockingQueue<T>
-
setClosed
Open/close the queue.- Specified by:
setClosedin interfaceIBlockingQueue<T>- Parameters:
closed- The closed state.- Returns:
- The remaining elements after the queue has been closed.
-
size
public int size()Return the size of the queue.- Specified by:
sizein interfaceIBlockingQueue<T>- Returns:
- The size.
-
main
Main for testing.- Throws:
InterruptedException
-
test1
Main for testing.- Throws:
InterruptedException
-
test1b
Main for testing.- Throws:
InterruptedException
-
test2
Main for testing.- Throws:
InterruptedException
-