|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
An object that implements this interface meets all the requirements for a producer/consumer queue. The queue may be opened or closed at any time. If there are any threads waiting to add or read objects from the queue and the queue is closed then an exception is thrown.
Likewise, if a thread is blocked on an add or read call then if the thread is interrupted an exception is thown. For more information see the various wait() methods defined by the class java.lang.Object
Method Summary | |
void |
add(Object obj)
Adds the specified object to the tail of the producer/consumer queue. |
void |
clear()
Clears the contents of the Producer/Consumer queue. |
void |
close()
Closes the currently open queue. |
int |
entries()
Returns the current number of element in the producer/consumer queue. |
boolean |
isClosed()
Returns the current closed status of the queue. |
boolean |
isEmpty()
This method is provided as a convience check to determine if the queue currently contains any elements. |
boolean |
isFull()
This method is provided as a convience check to determine if the queue is currently full. |
boolean |
isOpen()
Returns the current open status of the queue. |
void |
oneShotNotifyAllOnAdd(Object recipient)
This method is designed to be used by classes that are waiting on new objects to be added to the queue. |
void |
oneShotNotifyAllOnRead(Object recipient)
This method is designed to be used by classes that are waiting on objects to be read from a full queue. |
void |
open()
Opens the queue so that values may be added and read from the queue. |
Object |
read()
Attempts to read the next object from the head of the producer/ consumer queue and return it to the caller. |
int |
size()
Returns the current capacity of the producer/consumer queue. |
Method Detail |
public boolean isOpen()
Returns the current open status of the queue. If the queue is open then a true value is returned. If the queue is closed or in error then a false value is returned.
public boolean isClosed()
Returns the current closed status of the queue. If the queue is closed then a true value is returned. If the queue is opened or in error then a false value is returned.
public void open()
Opens the queue so that values may be added and read from the queue. If the queue is already open then this call has no effect.
public void close()
Closes the currently open queue. Once the queue is close then no values may be added or read from the queue. Any values that may be contained in the queue will persist unless cleared.
public void add(Object obj) throws InterruptedException, QueueClosedException
Adds the specified object to the tail of the producer/consumer queue. If the queue is currently at it's predefined limit then the call blocks until there is room in the queue.
If the queue is closed while the thread is waiting to add the object then an exception is thrown. Likewise, if the adding thread is interruped then an exception is thrown by the add method.
obj
- The object to be added to the queue.InterruptedException
- Thrown if the adding
thread is interrrupted prior to completing the
addition of the object.org.opennmms.bb.common.components.QueueClosedException
- Thrown
if the queue is closed before the object is added to the
producer/consumer queue.public Object read() throws InterruptedException, QueueClosedException
Attempts to read the next object from the head of the producer/ consumer queue and return it to the caller. If there are no object in the queue currently then the call blocks until there is an object available.
If the queue is closed while the thread is waiting for an object then an exception is thrown. Likewise, if the reading thread is interrupted prior to reading an object then an exception is also thrown.
InterruptedException
- Thrown if the adding
thread is interrrupted prior to completing the
reading of an object.org.opennmms.bb.common.components.QueueClosedException
- Thrown
if the queue is closed before the object is recovered from the
producer/consumer queue.public int size()
public int entries()
public void clear()
Clears the contents of the Producer/Consumer queue. The conents of the queue are discarded regardless of the open or closed status of the queue.
Once the queue is cleared all waiters are notified.
public void oneShotNotifyAllOnAdd(Object recipient)
This method is designed to be used by classes that are waiting on new objects to be added to the queue. When an object is added to the queue after this call, the recipient object will have its notifyAll method called. The recipient will only be notified once, all subsuquent adds to the queue will not cause the recipient to be signaled.
If a recipient needs to be called after each add then it must repeatly re-register after each notification, however this does not guarentee notification for each add. The one shot notification is designed to be used by classes that check check for elements and find the list empty, they then call wait() to pause until more elements are available.
Note: If the recipient is not well behavied and continues to hold its lock when the add method is called, it could cause a deadlock condition. Recipients must either unregister or release their lock to receive notifications. Care should be taken when using this method.
recipient
- The object to be signaled when then next add succeeds.public void oneShotNotifyAllOnRead(Object recipient)
This method is designed to be used by classes that are waiting on objects to be read from a full queue. When an object is read from the queue after this call, the recipient object will have its notifyAll method called. The recipient will only be notified once, all subsuquent reads to the queue will not cause the recipient to be signaled.
If a recipient needs to be called after each read then it must repeatly re-register after each notification, however this does not guarentee notification for each read. The one shot notification is designed to be used by classes that check check for elements and find the list full, they then call wait() to pause until more elements are available.
Note: If the recipient is not well behavied and continues to hold its lock when the add method is called, it could cause a deadlock condition. Recipients must either unregister or release their lock to receive notifications. Care should be taken when using this method.
recipient
- The object to be signaled when then next read succeeds.public boolean isEmpty()
This method is provided as a convience check to determine if the queue currently contains any elements. If the method returns true then there are no entries currently in the queue and a call to read will block until an object is added.
public boolean isFull()
This method is provided as a convience check to determine if the queue is currently full. If the method returns true then there is no more room to place any elements and the next call to add will block until an object is removed.
If the PCQueue is not bounded then this method will always return false. To determine if the queue is bounded see the size method.
size()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |