ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/QueueMonitor.java
Revision: 1.5
Committed: Thu Mar 1 15:46:23 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.4: +5 -3 lines
Log Message:
Now send the hashCode in the QueueMonitor shutdown packets.

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.4 2001/02/28 19:02:22 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.4 $";
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 // get a hash of our Queue (for identification)
59 String hashCode = String.valueOf(_sourceQueue.hashCode());
60 // create some XML
61 String date = new Long(System.currentTimeMillis()/((long) 1000)).toString();
62 String xml = "<packet type=\"queueStat\" date=\""+date+"\" name=\""+_srcName+"\" hashCode=\""+hashCode+"\">" + status + "</packet>";
63 // write XML to destination Queue
64 _destQueue.add(xml);
65 }
66 }
67
68 /**
69 * Shuts down this QueueMonitor
70 */
71 public void shutdown() {
72 // this will stop the main loop
73 _run = false;
74 // get a hash of our Queue (for identification)
75 String hashCode = String.valueOf(_sourceQueue.hashCode());
76 // create some XML
77 String date = new Long(System.currentTimeMillis()/((long) 1000)).toString();
78 String xml = "<packet type=\"queueStat\" date=\""+date+"\" name=\""+_srcName+"\" hashCode=\""+hashCode+"\" shutdown=\"true\"></packet>";
79 // write XML to destination Queue
80 _destQueue.add(xml);
81 }
82
83 /**
84 * Overrides the {@link java.lang.Object#toString() Object.toString()}
85 * method to provide clean logging (every class should have this).
86 *
87 * This uses the uk.ac.ukc.iscream.util.FormatName class
88 * to format the toString()
89 *
90 * @return the name of this class and its CVS revision
91 */
92 public String toString() {
93 return FormatName.getName(
94 _name,
95 getClass().getName(),
96 REVISION);
97 }
98
99 //---PRIVATE METHODS---
100
101 //---ACCESSOR/MUTATOR METHODS---
102
103 //---ATTRIBUTES---
104
105 /**
106 * This is the friendly identifier of the
107 * component this class is running in.
108 * eg, a Filter may be called "filter1",
109 * If this class does not have an owning
110 * component, a name from the configuration
111 * can be placed here. This name could also
112 * be changed to null for utility classes.
113 */
114 private String _name = null;
115
116 /**
117 * The Queue we're monitoring.
118 */
119 private Queue _sourceQueue;
120
121 /**
122 * The Queue we'll output results to.
123 */
124 private Queue _destQueue;
125
126 /**
127 * The interval at which we'll check the
128 * sourceQueue status.
129 */
130 private long _interval;
131
132 /**
133 * The name to identify the source Queue
134 */
135 private String _srcName;
136
137 /**
138 * Allows us to stop the main loop cleanly.
139 */
140 private boolean _run;
141
142 //---STATIC ATTRIBUTES---
143
144 }