--- experimental/server/Queue/Queue.java 2001/01/30 02:13:09 1.6 +++ experimental/server/Queue/Queue.java 2001/02/12 02:27:56 1.7 @@ -1,10 +1,10 @@ //---PACKAGE DECLARATION--- -package uk.ac.ukc.iscream.util; +//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 @@ -13,7 +13,7 @@ import uk.ac.ukc.iscream.util.*; * actually contains some elements. * * @author $Author: tdb $ - * @version $Id: Queue.java,v 1.6 2001/01/30 02:13:09 tdb Exp $ + * @version $Id: Queue.java,v 1.7 2001/02/12 02:27:56 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.6 $"; + public static final String REVISION = "$Revision: 1.7 $"; //---STATIC METHODS--- @@ -119,28 +119,26 @@ public class Queue { } /** - * 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 - * includes the current size of each queue, and the total - * items passed through. + * This method returns an XML textual status of the queues. + * It is merely for observation, and would most likely be + * used by a larger "monitoring" component. Information + * returned includes the current size of each queue, and + * the total items passed through. * - * @return A String message containing status information. + * @return A String message containing status information in XML format */ - public String status() { - String status = ""; + public String xmlStatus() { + String status = ""; return status; } @@ -210,6 +208,59 @@ public class Queue { } /** + * Start a monitor on our own Queue. This will log XML + * statistics about our Queue to a given Queue (could be + * the one being monitored). + * + * @param interval The long interval, in milliseconds, at which to take samples + * @param destQueue The queue to monitor to + * @param name A name to identify this Queue with + * @return whether we succeeded + */ + public boolean startMonitor(long interval, Queue destQueue, String name) { + if(_queueMon == null) { + // start a monitor + _queueMon = new QueueMonitor(this, destQueue, interval, name); + _queueMon.start(); + return true; + } + else { + // already have a monitor running + return false; + } + } + + /** + * Start a monitor on our own Queue. This will log XML + * statistics about our Queue to this Queue. + * + * @param interval The long interval, in milliseconds, at which to take samples + * @param name A name to identify this Queue with + * @return whether we succeeded + */ + public boolean startMonitor(long interval, String name) { + return startMonitor(interval, this, name); + } + + /** + * Stop a monitor on our Queue if we have on running. + * + * @return whether we succeeded + */ + public boolean stopMonitor() { + if(_queueMon != null) { + // stop a monitor + _queueMon.shutdown(); + _queueMon = null; + return true; + } + else { + // no monitor running + return false; + } + } + + /** * Overrides the {@link java.lang.Object#toString() Object.toString()} * method to provide clean logging (every class should have this). * @@ -241,6 +292,11 @@ public class Queue { * passed through, for statistical purposes. */ private int _count = 0; + + /** + * A reference to our QueueMonitor, if we have one. + */ + private QueueMonitor _queueMon = null; /** * This is the friendly identifier of the