--- projects/cms/source/util/uk/org/iscream/cms/util/Queue.java 2001/01/02 03:24:51 1.2 +++ projects/cms/source/util/uk/org/iscream/cms/util/Queue.java 2001/01/30 01:56:28 1.7 @@ -13,7 +13,7 @@ import uk.ac.ukc.iscream.util.*; * actually contains some elements. * * @author $Author: tdb $ - * @version $Id: Queue.java,v 1.2 2001/01/02 03:24:51 tdb Exp $ + * @version $Id: Queue.java,v 1.7 2001/01/30 01:56:28 tdb Exp $ */ public class Queue { @@ -22,7 +22,7 @@ public class Queue { /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.2 $"; + public static final String REVISION = "$Revision: 1.7 $"; //---STATIC METHODS--- @@ -88,8 +88,36 @@ public class Queue { } return o; } - + /** + * This method releases a get() method that's currently + * waiting on an empty queue. This was designed for + * shutdown() type methods that may have problems closing + * if the thread of control is waiting on a queue. + * + * @param queue the queue to release + */ + public void releaseQueue(int queue) { + synchronized(((LinkedList) _lists.get(queue))) { + ((LinkedList) _lists.get(queue)).notifyAll(); + } + } + + /** + * This method erases the contents of a given queue. This + * method should be used with care. It can only empty one + * internal queue, not all of them. This must be called + * multiple times to empty all queues. + * + * @param queue the queue to empty. + */ + public void clearQueue(int queue) { + synchronized(this) { + ((LinkedList) _lists.get(queue)).clear(); + } + } + + /** * This method returns a textual status of the queues. It * is merely for observation, and would most likely be used * by a larger "monitoring" component. Information returned @@ -116,6 +144,31 @@ public class Queue { } /** + * Returns the size of a given queue. A consumer can use + * this to see how big their queue is at any given time. + * they should use their queue number as the parameter. + * + * @param queue The queue number to query. + * @return the current size of the queue. + */ + public int queueSize(int queue) throws InvalidQueueException { + if (queue >= _lists.size() || _lists.get(queue) == null) { + throw new InvalidQueueException("Requested queue "+queue+" does not exist"); + } + return ((LinkedList) _lists.get(queue)).size(); + } + + /** + * Returns the total numer of elements to have passed + * through this queue (ie. a counter on the add method). + * + * @return the element-ometer + */ + public int elementCount() { + return _count; + } + + /** * This method assigns a queue to a consumer. The idea behind * this is to ensure that only 1 consumer can be associated with * a given queue, otherwise the whole "blocking" thing fails @@ -163,12 +216,12 @@ public class Queue { * * @return the name of this class and its CVS revision */ - /*public String toString() { + public String toString() { return FormatName.getName( _name, getClass().getName(), REVISION); - }*/ + } //---PRIVATE METHODS--- @@ -196,13 +249,7 @@ public class Queue { * can be placed here. This name could also * be changed to null for utility classes. */ - //private String _name = ; - - /** - * This holds a reference to the - * system logger that is being used. - */ - //private Logger _logger = ReferenceManager.getInstance().getLogger(); + private String _name = null; //---STATIC ATTRIBUTES---