--- experimental/server/Queue/Queue.java 2001/01/02 01:50:17 1.3 +++ experimental/server/Queue/Queue.java 2001/01/18 22:08:07 1.4 @@ -1,9 +1,10 @@ //---PACKAGE DECLARATION--- +package uk.ac.ukc.iscream.util; //---IMPORTS--- import java.util.LinkedList; import java.util.NoSuchElementException; -//import uk.ac.ukc.iscream.util.*; +import uk.ac.ukc.iscream.util.*; /** * A Queue class designed to operate in a multi-threaded environment, with @@ -12,16 +13,16 @@ import java.util.NoSuchElementException; * actually contains some elements. * * @author $Author: tdb $ - * @version $Id: Queue.java,v 1.3 2001/01/02 01:50:17 tdb Exp $ + * @version $Id: Queue.java,v 1.4 2001/01/18 22:08:07 tdb Exp $ */ -class Queue { +public class Queue { //---FINAL ATTRIBUTES--- /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.3 $"; + public static final String REVISION = "$Revision: 1.4 $"; //---STATIC METHODS--- @@ -115,6 +116,31 @@ 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 @@ -162,12 +188,12 @@ 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--- @@ -195,13 +221,7 @@ 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---