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.8
Committed: Tue May 29 17:02:35 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Changes since 1.7: +5 -5 lines
Log Message:
Major change in the java package naming. This has been held off for some time
now, but it really needed doing. The future packaging of all i-scream products
will be;

uk.org.iscream.<product>.<subpart>.*

In the case of the central monitoring system server this will be;

uk.org.iscream.cms.server.*

The whole server has been changed to follow this structure, and tested to a
smallish extent. Further changes in other parts of the CMS will follow.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.cms.server.util;
3
4 //---IMPORTS---
5 import uk.org.iscream.cms.server.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.7 2001/03/14 23:25:29 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.7 $";
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 // set the Thread name
38 setName("util.QueueMonitor");
39
40 _sourceQueue = sourceQueue;
41 _destQueue = destQueue;
42 _interval = interval;
43 _srcName = name;
44 }
45
46 //---PUBLIC METHODS---
47
48 /**
49 * Loops continuosly polling our source Queue at
50 * the given interval, and then logging the results
51 * in the destination Queue.
52 */
53 public void run() {
54 _run = true;
55 // so we can stop this thread...
56 while(_run) {
57 // first sleep for our interval
58 try { Thread.sleep(_interval); } catch(Exception e) {}
59 // check the Queue
60 String status = _sourceQueue.xmlStatus();
61 // get a hash of our Queue (for identification)
62 String hashCode = String.valueOf(_sourceQueue.hashCode());
63 // create some XML
64 String date = new Long(System.currentTimeMillis()/((long) 1000)).toString();
65 String xml = "<packet type=\"queueStat\" date=\""+date+"\" name=\""+_srcName+"\" hashCode=\""+hashCode+"\">" + status + "</packet>";
66 // write XML to destination Queue
67 _destQueue.add(xml);
68 }
69 }
70
71 /**
72 * Shuts down this QueueMonitor
73 */
74 public void shutdown() {
75 // this will stop the main loop
76 _run = false;
77 // get a hash of our Queue (for identification)
78 String hashCode = String.valueOf(_sourceQueue.hashCode());
79 // create some XML
80 String date = new Long(System.currentTimeMillis()/((long) 1000)).toString();
81 String xml = "<packet type=\"queueStat\" date=\""+date+"\" name=\""+_srcName+"\" hashCode=\""+hashCode+"\" shutdown=\"true\"></packet>";
82 // write XML to destination Queue
83 _destQueue.add(xml);
84 }
85
86 /**
87 * Overrides the {@link java.lang.Object#toString() Object.toString()}
88 * method to provide clean logging (every class should have this).
89 *
90 * This uses the uk.org.iscream.cms.server.util.FormatName class
91 * to format the toString()
92 *
93 * @return the name of this class and its CVS revision
94 */
95 public String toString() {
96 return FormatName.getName(
97 _name,
98 getClass().getName(),
99 REVISION);
100 }
101
102 //---PRIVATE METHODS---
103
104 //---ACCESSOR/MUTATOR METHODS---
105
106 //---ATTRIBUTES---
107
108 /**
109 * This is the friendly identifier of the
110 * component this class is running in.
111 * eg, a Filter may be called "filter1",
112 * If this class does not have an owning
113 * component, a name from the configuration
114 * can be placed here. This name could also
115 * be changed to null for utility classes.
116 */
117 private String _name = null;
118
119 /**
120 * The Queue we're monitoring.
121 */
122 private Queue _sourceQueue;
123
124 /**
125 * The Queue we'll output results to.
126 */
127 private Queue _destQueue;
128
129 /**
130 * The interval at which we'll check the
131 * sourceQueue status.
132 */
133 private long _interval;
134
135 /**
136 * The name to identify the source Queue
137 */
138 private String _srcName;
139
140 /**
141 * Allows us to stop the main loop cleanly.
142 */
143 private boolean _run;
144
145 //---STATIC ATTRIBUTES---
146
147 }