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.void
Enqueue an element.boolean
isClosed()
Check if the queue is closed.static void
Main for testing.peek()
Peek the topmost element without dequeuing it.setClosed
(boolean closed) Open/close the queue.int
size()
Return the size of the queue.static void
Main for testing.static void
Main for testing.static void
Main 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:
enqueue
in interfaceIBlockingQueue<T>
- Parameters:
element
- 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
Dequeue an element.- Specified by:
dequeue
in 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:
isClosed
in interfaceIBlockingQueue<T>
-
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.
-
size
public int size()Return the size of the queue.- Specified by:
size
in 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
-