1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org.uk |
4 |
+ |
* Copyright (C) 2000-2002 i-scream |
5 |
+ |
* |
6 |
+ |
* This program is free software; you can redistribute it and/or |
7 |
+ |
* modify it under the terms of the GNU General Public License |
8 |
+ |
* as published by the Free Software Foundation; either version 2 |
9 |
+ |
* of the License, or (at your option) any later version. |
10 |
+ |
* |
11 |
+ |
* This program is distributed in the hope that it will be useful, |
12 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
+ |
* GNU General Public License for more details. |
15 |
+ |
* |
16 |
+ |
* You should have received a copy of the GNU General Public License |
17 |
+ |
* along with this program; if not, write to the Free Software |
18 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
+ |
*/ |
20 |
+ |
|
21 |
|
//---PACKAGE DECLARATION--- |
22 |
< |
package uk.ac.ukc.iscream.util; |
22 |
> |
package uk.org.iscream.cms.util; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
< |
import uk.ac.ukc.iscream.util.*; |
6 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
25 |
> |
//import uk.org.iscream.cms.util.*; |
26 |
|
|
27 |
|
/** |
28 |
|
* This class monitors a given Queue at regular intervals, |
54 |
|
* @param name A name to identify the source Queue with |
55 |
|
*/ |
56 |
|
public QueueMonitor (Queue sourceQueue, Queue destQueue, long interval, String name) { |
57 |
+ |
// set the Thread name |
58 |
+ |
setName("util.QueueMonitor"); |
59 |
+ |
|
60 |
|
_sourceQueue = sourceQueue; |
61 |
|
_destQueue = destQueue; |
62 |
|
_interval = interval; |
78 |
|
try { Thread.sleep(_interval); } catch(Exception e) {} |
79 |
|
// check the Queue |
80 |
|
String status = _sourceQueue.xmlStatus(); |
81 |
+ |
// get a hash of our Queue (for identification) |
82 |
+ |
String hashCode = String.valueOf(_sourceQueue.hashCode()); |
83 |
|
// create some XML |
84 |
|
String date = new Long(System.currentTimeMillis()/((long) 1000)).toString(); |
85 |
< |
String xml = "<packet type=\"queueStat\" date=\""+date+"\" name=\""+_srcName+"\">" + status + "</packet>"; |
85 |
> |
String xml = "<packet type=\"queueStat\" date=\""+date+"\" name=\""+_srcName+"\" hashCode=\""+hashCode+"\">" + status + "</packet>"; |
86 |
|
// write XML to destination Queue |
87 |
|
_destQueue.add(xml); |
88 |
|
} |
94 |
|
public void shutdown() { |
95 |
|
// this will stop the main loop |
96 |
|
_run = false; |
97 |
+ |
// get a hash of our Queue (for identification) |
98 |
+ |
String hashCode = String.valueOf(_sourceQueue.hashCode()); |
99 |
+ |
// create some XML |
100 |
+ |
String date = new Long(System.currentTimeMillis()/((long) 1000)).toString(); |
101 |
+ |
String xml = "<packet type=\"queueStat\" date=\""+date+"\" name=\""+_srcName+"\" hashCode=\""+hashCode+"\" shutdown=\"true\"></packet>"; |
102 |
+ |
// write XML to destination Queue |
103 |
+ |
_destQueue.add(xml); |
104 |
|
} |
105 |
|
|
106 |
|
/** |
107 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
108 |
|
* method to provide clean logging (every class should have this). |
109 |
|
* |
110 |
< |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
110 |
> |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
111 |
|
* to format the toString() |
112 |
|
* |
113 |
|
* @return the name of this class and its CVS revision |