ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/Queue/QueueMonitor.java
Revision: 1.1
Committed: Mon Feb 12 02:27:56 2001 UTC (23 years, 9 months ago) by tdb
Branch: MAIN
Log Message:
Brought in line with changes in main tree. Now supports Queue monitoring in
XML format, to another Queue (or the same Queue).

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 //package uk.ac.ukc.iscream.util;
3
4 //---IMPORTS---
5 //import uk.ac.ukc.iscream.util.*;
6
7 /**
8 * This class monitors a given Queue at regular intervals,
9 * reporting back to a Queue with XML - this could be the
10 * same Queue being monitored.
11 *
12 * @author $Author: tdb1 $
13 * @version $Id: QueueMonitor.java,v 1.1 2001/02/12 02:20:23 tdb1 Exp $
14 */
15 class QueueMonitor extends Thread {
16
17 //---FINAL ATTRIBUTES---
18
19 /**
20 * The current CVS revision of this class
21 */
22 public static final String REVISION = "$Revision: 1.1 $";
23
24 //---STATIC METHODS---
25
26 //---CONSTRUCTORS---
27
28 /**
29 * Construct a new QueueMonitor.
30 *
31 * @param sourceQueue The Queue to monitor
32 * @param destQueue The Queue to monitor to
33 * @param interval The interval, in milliseconds, at which to sample
34 * @param name A name to identify the source Queue with
35 */
36 public QueueMonitor (Queue sourceQueue, Queue destQueue, long interval, String name) {
37 _sourceQueue = sourceQueue;
38 _destQueue = destQueue;
39 _interval = interval;
40 _srcName = name;
41 }
42
43 //---PUBLIC METHODS---
44
45 /**
46 * Loops continuosly polling our source Queue at
47 * the given interval, and then logging the results
48 * in the destination Queue.
49 */
50 public void run() {
51 _run = true;
52 // so we can stop this thread...
53 while(_run) {
54 // first sleep for our interval
55 try { Thread.sleep(_interval); } catch(Exception e) {}
56 // check the Queue
57 String status = _sourceQueue.xmlStatus();
58 // create some XML
59 String date = new Long(System.currentTimeMillis()/((long) 1000)).toString();
60 String xml = "<packet type=\"queueStat\" date=\""+date+"\" name=\""+_srcName+"\">" + status + "</packet>";
61 // write XML to destination Queue
62 _destQueue.add(xml);
63 }
64 }
65
66 /**
67 * Shuts down this QueueMonitor
68 */
69 public void shutdown() {
70 // this will stop the main loop
71 _run = false;
72 }
73
74 /**
75 * Overrides the {@link java.lang.Object#toString() Object.toString()}
76 * method to provide clean logging (every class should have this).
77 *
78 * This uses the uk.ac.ukc.iscream.util.FormatName class
79 * to format the toString()
80 *
81 * @return the name of this class and its CVS revision
82 */
83 public String toString() {
84 return FormatName.getName(
85 _name,
86 getClass().getName(),
87 REVISION);
88 }
89
90 //---PRIVATE METHODS---
91
92 //---ACCESSOR/MUTATOR METHODS---
93
94 //---ATTRIBUTES---
95
96 /**
97 * This is the friendly identifier of the
98 * component this class is running in.
99 * eg, a Filter may be called "filter1",
100 * If this class does not have an owning
101 * component, a name from the configuration
102 * can be placed here. This name could also
103 * be changed to null for utility classes.
104 */
105 private String _name = null;
106
107 /**
108 * The Queue we're monitoring.
109 */
110 private Queue _sourceQueue;
111
112 /**
113 * The Queue we'll output results to.
114 */
115 private Queue _destQueue;
116
117 /**
118 * The interval at which we'll check the
119 * sourceQueue status.
120 */
121 private long _interval;
122
123 /**
124 * The name to identify the source Queue
125 */
126 private String _srcName;
127
128 /**
129 * Allows us to stop the main loop cleanly.
130 */
131 private boolean _run;
132
133 //---STATIC ATTRIBUTES---
134
135 }