public class ArrayBlockingQueue<T> extends java.lang.Object implements IBlockingQueue<T>
IBlockingQueue.ClosedException
Modifier and Type | Field and 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 and Description |
---|
ArrayBlockingQueue()
Create a new blocking queue.
|
Modifier and Type | Method and 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.
|
protected java.lang.Object[] elements
protected int start
protected int end
protected int size
protected java.lang.Object monitor
protected boolean closed
public int size()
size
in interface IBlockingQueue<T>
public void enqueue(java.lang.Object o)
enqueue
in interface IBlockingQueue<T>
o
- The element.public T dequeue(long timeout) throws IBlockingQueue.ClosedException, TimeoutException
dequeue
in interface IBlockingQueue<T>
timeout
- the time to wait (in millis) or -1 for no timeout.IBlockingQueue.ClosedException
TimeoutException
public T peek() throws IBlockingQueue.ClosedException
peek
in interface IBlockingQueue<T>
IBlockingQueue.ClosedException
public T dequeue()
dequeue
in interface IBlockingQueue<T>
public java.util.List<T> setClosed(boolean closed)
setClosed
in interface IBlockingQueue<T>
closed
- The closed state.public boolean isClosed()
isClosed
in interface IBlockingQueue<T>
public java.lang.String toString()
toString
in class java.lang.Object