|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exolab.core.util.FifoQueue
public class FifoQueue
This is a very simple implementation of a FIFO queue. The queue only holds object types, and is created with a fixed size, and will NOT grow during its life. The queue is thread safe.
Items can be added or removed to and from the queue either one at a time or in bulk. When the queue is full any attempt to add another object will block until the queue has space for it. Any attempt to get an object from an empty queue will block until at least one item has been added.
Clients can check to see if the queue is full or empty with available helper methods.
When objects are added or removed from the queue, a notify all is called to wake any sleeping threads waiting on a queue resource.
Constructor Summary | |
---|---|
FifoQueue(int capacity)
The queue constructor. |
Method Summary | |
---|---|
void |
add(java.lang.Object obj)
Add a new object to the head of the queue. |
void |
add(java.lang.Object[] list)
Add a new list of objects to the head of the queue. |
java.lang.Object |
get()
Remove and return the object at the end of the queue. |
java.lang.Object[] |
getAll()
Remove and return all the objects in the queue in the order they were added. |
int |
getCapacity()
Get the queues max capacity. |
int |
getSize()
Get the number of elements the queue currently holds |
boolean |
isEmpty()
Return true if the queue currently holds no elements. |
boolean |
isFull()
Return true if the queue is currently full. |
void |
waitUntilEmpty()
Wait until the queue becomes empty. |
boolean |
waitUntilEmpty(long timeout)
Wait until timeout if the queue is empty. |
void |
waitUntilFull()
Wait until the queue becomes full. |
void |
waitWhileEmpty()
Wait while the queue is empty. |
void |
waitWhileFull()
Wait while the queue is full. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FifoQueue(int capacity)
capacity
- the total number of elements this queue is
allowed to holdMethod Detail |
---|
public int getCapacity()
public int getSize()
public boolean isEmpty()
public boolean isFull()
public void add(java.lang.Object obj) throws java.lang.InterruptedException
obj
- The new object to add to the queue.
java.lang.InterruptedException
- If interupted while waitingpublic void add(java.lang.Object[] list) throws java.lang.InterruptedException
list
- The list of objects to add to the queue.
java.lang.InterruptedException
- If interupted while waitingpublic java.lang.Object get() throws java.lang.InterruptedException
java.lang.InterruptedException
- If interupted while waitingpublic java.lang.Object[] getAll() throws java.lang.InterruptedException
If the queue is empty an empty list is returned.
java.lang.InterruptedException
- If interupted while waitingpublic boolean waitUntilEmpty(long timeout) throws java.lang.InterruptedException
Note: when there are multiple threads waiting on a queue there is no guarantee which one will succeed first.
timeout
- The time to wait for in ms.
java.lang.InterruptedException
- If interupted while waitingpublic void waitUntilEmpty() throws java.lang.InterruptedException
java.lang.InterruptedException
- If interupted while waitingpublic void waitWhileEmpty() throws java.lang.InterruptedException
java.lang.InterruptedException
- If interupted while waitingpublic void waitUntilFull() throws java.lang.InterruptedException
java.lang.InterruptedException
- If interupted while waitingpublic void waitWhileFull() throws java.lang.InterruptedException
java.lang.InterruptedException
- If interupted while waiting
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |