1 |
tdb |
1.15 |
/* |
2 |
|
|
* i-scream central monitoring system |
3 |
tdb |
1.16 |
* http://www.i-scream.org.uk |
4 |
tdb |
1.15 |
* 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 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
22 |
tdb |
1.14 |
package uk.org.iscream.cms.server.client; |
23 |
tdb |
1.1 |
|
24 |
|
|
//---IMPORTS--- |
25 |
tdb |
1.14 |
import uk.org.iscream.cms.server.componentmanager.*; |
26 |
|
|
import uk.org.iscream.cms.server.core.*; |
27 |
tdb |
1.18 |
import uk.org.iscream.cms.util.*; |
28 |
tdb |
1.1 |
import java.util.*; |
29 |
|
|
|
30 |
|
|
/** |
31 |
|
|
* A manager for the Monitors. |
32 |
|
|
* |
33 |
ajm |
1.13 |
* This class starts by loading all the monitors as specificed in the configuration. |
34 |
|
|
* These monitors should implement the PluginMonitor interface. |
35 |
|
|
* |
36 |
|
|
* This class then takes the feed of data coming in over CORBA from |
37 |
|
|
* the ClientServant queue. This data is then looked at to determine |
38 |
|
|
* type. It then places it into either a data queue, a heartbeat queue or |
39 |
|
|
* an other queue, and all data in the the all queue. |
40 |
|
|
* |
41 |
|
|
* Monitors then read the data off the queue that they are interested in |
42 |
|
|
* and process the data accordingly. |
43 |
|
|
* |
44 |
tdb |
1.15 |
* @author $Author: tdb $ |
45 |
tdb |
1.18 |
* @version $Id: MonitorManager.java,v 1.17 2002/10/12 22:12:36 tdb Exp $ |
46 |
tdb |
1.1 |
*/ |
47 |
ajm |
1.11 |
public class MonitorManager extends Thread { |
48 |
tdb |
1.1 |
|
49 |
|
|
//---FINAL ATTRIBUTES--- |
50 |
|
|
|
51 |
|
|
/** |
52 |
|
|
* The current CVS revision of this class |
53 |
|
|
*/ |
54 |
tdb |
1.18 |
public static final String REVISION = "$Revision: 1.17 $"; |
55 |
tdb |
1.1 |
|
56 |
|
|
//---STATIC METHODS--- |
57 |
|
|
|
58 |
ajm |
1.3 |
/** |
59 |
|
|
* Return a reference to the single class. |
60 |
|
|
* Construct it if it does not already exist, otherwise just return the reference. |
61 |
|
|
*/ |
62 |
tdb |
1.12 |
public synchronized static MonitorManager getInstance() { |
63 |
ajm |
1.3 |
if (_instance == null){ |
64 |
|
|
_instance = new MonitorManager(); |
65 |
|
|
} |
66 |
|
|
return _instance; |
67 |
|
|
} |
68 |
|
|
|
69 |
tdb |
1.1 |
//---CONSTRUCTORS--- |
70 |
|
|
|
71 |
ajm |
1.13 |
/** |
72 |
|
|
* Constructs a new MonitorManager. |
73 |
|
|
* This initialises all the queues and loads |
74 |
|
|
* all the Monitors that have been specified in the configuration |
75 |
|
|
*/ |
76 |
ajm |
1.3 |
private MonitorManager() { |
77 |
tdb |
1.5 |
// set our name |
78 |
|
|
setName("client.MonitorManager"); |
79 |
|
|
|
80 |
ajm |
1.3 |
_queue = ClientMain._monitorQueue; |
81 |
|
|
_qID = _queue.getQueue(); |
82 |
|
|
_logger.write(toString(), Logger.SYSINIT, "Initialising"); |
83 |
|
|
_logger.write(toString(), Logger.SYSMSG, "Creating monitor pipeline for plugin monitors ..."); |
84 |
|
|
|
85 |
tdb |
1.8 |
// get the config proxy |
86 |
|
|
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
87 |
|
|
|
88 |
tdb |
1.9 |
// get the configuration for our outgoing queue's |
89 |
|
|
|
90 |
|
|
// see if these Queue's need a size limit |
91 |
|
|
try { |
92 |
|
|
int queueSizeLimit = Integer.parseInt(cp.getProperty(_name, "Queue.SizeLimit")); |
93 |
|
|
String queueRemoveAlgorithm = cp.getProperty(_name, "Queue.RemoveAlgorithm"); |
94 |
|
|
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
95 |
|
|
if(algorithm != -1) { |
96 |
tdb |
1.10 |
_logger.write(toString(), Logger.DEBUG, "Starting 4 Queues with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
97 |
tdb |
1.9 |
// we have valid values, so lets start it. |
98 |
|
|
_dataQueue = new Queue(queueSizeLimit, algorithm); |
99 |
|
|
_heartbeatQueue = new Queue(queueSizeLimit, algorithm); |
100 |
|
|
_otherQueue = new Queue(queueSizeLimit, algorithm); |
101 |
tdb |
1.10 |
_allQueue = new Queue(queueSizeLimit, algorithm); |
102 |
tdb |
1.9 |
} |
103 |
|
|
else { |
104 |
|
|
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
105 |
|
|
// just don't activate a limit |
106 |
|
|
_dataQueue = new Queue(); |
107 |
|
|
_heartbeatQueue = new Queue(); |
108 |
|
|
_otherQueue = new Queue(); |
109 |
tdb |
1.10 |
_allQueue = new Queue(); |
110 |
tdb |
1.9 |
} |
111 |
|
|
} catch (PropertyNotFoundException e) { |
112 |
|
|
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
113 |
|
|
// just don't activate a limit |
114 |
|
|
_dataQueue = new Queue(); |
115 |
|
|
_heartbeatQueue = new Queue(); |
116 |
|
|
_otherQueue = new Queue(); |
117 |
tdb |
1.10 |
_allQueue = new Queue(); |
118 |
tdb |
1.9 |
} catch (NumberFormatException e) { |
119 |
|
|
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
120 |
|
|
// just don't activate a limit |
121 |
|
|
_dataQueue = new Queue(); |
122 |
|
|
_heartbeatQueue = new Queue(); |
123 |
|
|
_otherQueue = new Queue(); |
124 |
tdb |
1.10 |
_allQueue = new Queue(); |
125 |
tdb |
1.9 |
} |
126 |
|
|
|
127 |
|
|
// startup monitors on these queues |
128 |
|
|
try { |
129 |
|
|
// try to get the interval, if this fails, we won't start up the monitor |
130 |
|
|
int queueMonitorInterval = Integer.parseInt(cp.getProperty(_name, "Queue.MonitorInterval")); |
131 |
|
|
_dataQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " DataQueue"); |
132 |
|
|
_heartbeatQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " HeartbeatQueue"); |
133 |
|
|
_otherQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " OtherQueue"); |
134 |
tdb |
1.10 |
_allQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " AllQueue"); |
135 |
tdb |
1.9 |
} catch (PropertyNotFoundException e) { |
136 |
|
|
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
137 |
|
|
} |
138 |
|
|
|
139 |
ajm |
1.3 |
// get the configuration for this plug-in setup |
140 |
tdb |
1.8 |
String pluginsPackage, pluginsList; |
141 |
|
|
try { |
142 |
|
|
pluginsPackage = cp.getProperty(_name, "Monitor.PluginsPackage"); |
143 |
|
|
pluginsList = cp.getProperty(_name, "Monitor.Plugins"); |
144 |
|
|
} catch(PropertyNotFoundException e) { |
145 |
|
|
_logger.write(toString(), Logger.WARNING, "Unable to get required configuration, Monitor's will not be activated: "+e); |
146 |
|
|
// setting these will ensure we don't build a pipeline |
147 |
|
|
pluginsPackage = ""; |
148 |
|
|
pluginsList = ""; |
149 |
|
|
} |
150 |
ajm |
1.3 |
|
151 |
|
|
StringTokenizer st = new StringTokenizer(pluginsList, ";"); |
152 |
|
|
|
153 |
|
|
while(st.hasMoreTokens()) { |
154 |
|
|
String className = pluginsPackage + "." + st.nextToken() + _suffix; |
155 |
|
|
_logger.write(toString(), Logger.DEBUG, "Attempting to create plugin: "+className); |
156 |
|
|
|
157 |
|
|
// Create an instance of the specified PluginMonitor to include |
158 |
|
|
// within the monitorPipe. Add it to the monitorPipeline |
159 |
|
|
try { |
160 |
|
|
PluginMonitor pm = (PluginMonitor)ClassLoader.getSystemClassLoader().loadClass(className).newInstance(); |
161 |
|
|
_monitorPipeline.add(pm); |
162 |
|
|
_logger.write(toString(), Logger.DEBUG, "Added monitor: "+className+" ("+pm.getDescription()+")"); |
163 |
|
|
} |
164 |
|
|
catch (InstantiationException e){ |
165 |
|
|
_logger.write(toString(), Logger.ERROR, "Failed to instantiate "+className+" to the plugin monitor pipeline."); |
166 |
|
|
_logger.write(toString(), Logger.ERROR, e.getMessage()); |
167 |
|
|
} |
168 |
|
|
catch (Exception e){ |
169 |
|
|
_logger.write(toString(), Logger.ERROR, "Failed to add "+className+" to the plugin monitor pipeline."); |
170 |
|
|
_logger.write(toString(), Logger.ERROR, e.toString()); |
171 |
|
|
} |
172 |
|
|
} |
173 |
|
|
_logger.write(toString(), Logger.SYSMSG, "The monitor pipeline has been set up with "+_monitorPipeline.size()+" plugin monitors."); |
174 |
tdb |
1.1 |
} |
175 |
|
|
|
176 |
|
|
//---PUBLIC METHODS--- |
177 |
|
|
|
178 |
ajm |
1.13 |
/** |
179 |
|
|
* Runs the MonitorManager. This reads data from the |
180 |
|
|
* inbound queue (from the ClientServant). And passes |
181 |
|
|
* it into the appropriate queue for processing by the monitor |
182 |
|
|
* threads. |
183 |
|
|
*/ |
184 |
tdb |
1.1 |
public void run() { |
185 |
|
|
boolean run=true; |
186 |
tdb |
1.7 |
|
187 |
|
|
// keep these out here, saves recreating the object |
188 |
|
|
String xml = null; |
189 |
tdb |
1.1 |
while(run) { |
190 |
|
|
try { |
191 |
ajm |
1.3 |
xml = (String) _queue.get(_qID); |
192 |
tdb |
1.1 |
} |
193 |
|
|
catch(InvalidQueueException e) { |
194 |
|
|
_logger.write(toString(), Logger.ERROR, "Queue failure: "+e); |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
// make an XML packet |
198 |
tdb |
1.2 |
XMLPacket packet = null; |
199 |
tdb |
1.1 |
|
200 |
tdb |
1.2 |
try { |
201 |
tdb |
1.17 |
packet = _xmlCache.getXMLPacket(xml); |
202 |
tdb |
1.2 |
} catch(InvalidXMLException e) { |
203 |
|
|
_logger.write(toString(), Logger.ERROR, "Invalid XML: "+e); |
204 |
|
|
// skip the rest of this loop iteration |
205 |
|
|
continue; |
206 |
|
|
} |
207 |
tdb |
1.9 |
|
208 |
|
|
// examine the packet and place it in the relevant outgoing queue |
209 |
|
|
if(packet.getParam("packet.attributes.type").equals("data")) { |
210 |
|
|
_dataQueue.add(packet); |
211 |
|
|
} |
212 |
|
|
else if(packet.getParam("packet.attributes.type").equals("heartbeat")) { |
213 |
|
|
_heartbeatQueue.add(packet); |
214 |
|
|
} |
215 |
|
|
else { |
216 |
|
|
_otherQueue.add(packet); |
217 |
tdb |
1.1 |
} |
218 |
tdb |
1.10 |
// always add to all queue |
219 |
|
|
_allQueue.add(packet); |
220 |
tdb |
1.1 |
} |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
/** |
224 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
225 |
|
|
* method to provide clean logging (every class should have this). |
226 |
|
|
* |
227 |
tdb |
1.18 |
* This uses the uk.org.iscream.cms.util.FormatName class |
228 |
tdb |
1.1 |
* to format the toString() |
229 |
|
|
* |
230 |
|
|
* @return the name of this class and its CVS revision |
231 |
|
|
*/ |
232 |
|
|
public String toString() { |
233 |
|
|
return FormatName.getName( |
234 |
|
|
_name, |
235 |
|
|
getClass().getName(), |
236 |
|
|
REVISION); |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
//---PRIVATE METHODS--- |
240 |
|
|
|
241 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
242 |
tdb |
1.9 |
|
243 |
ajm |
1.13 |
/** |
244 |
|
|
* Allows Monitors to obtain |
245 |
|
|
* the queue of data packets |
246 |
|
|
*/ |
247 |
tdb |
1.9 |
public Queue getDataQueue() { |
248 |
|
|
return _dataQueue; |
249 |
|
|
} |
250 |
|
|
|
251 |
ajm |
1.13 |
/** |
252 |
|
|
* Allows Monitors to obtain |
253 |
|
|
* the queue of heatbeat packets |
254 |
|
|
*/ |
255 |
tdb |
1.9 |
public Queue getHeartbeatQueue() { |
256 |
|
|
return _heartbeatQueue; |
257 |
|
|
} |
258 |
|
|
|
259 |
ajm |
1.13 |
/** |
260 |
|
|
* Allows Monitors to obtain |
261 |
|
|
* the queue of all other packets |
262 |
|
|
*/ |
263 |
tdb |
1.9 |
public Queue getOtherQueue() { |
264 |
|
|
return _otherQueue; |
265 |
|
|
} |
266 |
|
|
|
267 |
ajm |
1.13 |
/** |
268 |
|
|
* In case a Monitor wants more |
269 |
|
|
* than one type of packet, |
270 |
|
|
* this queue can be obtained. |
271 |
|
|
*/ |
272 |
tdb |
1.10 |
public Queue getAllQueue() { |
273 |
|
|
return _allQueue; |
274 |
|
|
} |
275 |
|
|
|
276 |
tdb |
1.1 |
//---ATTRIBUTES--- |
277 |
|
|
|
278 |
|
|
/** |
279 |
|
|
* This is the friendly identifier of the |
280 |
|
|
* component this class is running in. |
281 |
|
|
* eg, a Filter may be called "filter1", |
282 |
|
|
* If this class does not have an owning |
283 |
|
|
* component, a name from the configuration |
284 |
|
|
* can be placed here. This name could also |
285 |
|
|
* be changed to null for utility classes. |
286 |
|
|
*/ |
287 |
|
|
private String _name = ClientMain.NAME; |
288 |
|
|
|
289 |
|
|
/** |
290 |
|
|
* This holds a reference to the |
291 |
|
|
* system logger that is being used. |
292 |
|
|
*/ |
293 |
|
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
294 |
|
|
|
295 |
|
|
/** |
296 |
ajm |
1.3 |
* A reference to the reference manager in use |
297 |
|
|
*/ |
298 |
|
|
private ReferenceManager _refman = ReferenceManager.getInstance(); |
299 |
|
|
|
300 |
|
|
/** |
301 |
tdb |
1.9 |
* A reference to our incoming Queue |
302 |
tdb |
1.1 |
*/ |
303 |
|
|
private Queue _queue; |
304 |
ajm |
1.3 |
|
305 |
|
|
/** |
306 |
tdb |
1.9 |
* Our incoming queue ID |
307 |
ajm |
1.3 |
*/ |
308 |
|
|
private int _qID; |
309 |
|
|
|
310 |
|
|
/** |
311 |
|
|
* file name suffix for plugin monitor classes: |
312 |
|
|
*/ |
313 |
|
|
private final String _suffix = "__Monitor"; |
314 |
|
|
|
315 |
|
|
/** |
316 |
|
|
* LinkedList for holding the PluginMonitor objects (the pipeline). |
317 |
|
|
*/ |
318 |
|
|
private LinkedList _monitorPipeline = new LinkedList(); |
319 |
tdb |
1.9 |
|
320 |
|
|
/** |
321 |
|
|
* Outgoing data Queue |
322 |
|
|
*/ |
323 |
|
|
private Queue _dataQueue; |
324 |
|
|
|
325 |
|
|
/** |
326 |
|
|
* Outgoing heartbeat Queue |
327 |
|
|
*/ |
328 |
|
|
private Queue _heartbeatQueue; |
329 |
|
|
|
330 |
|
|
/** |
331 |
|
|
* Outgoing other Queue |
332 |
|
|
*/ |
333 |
|
|
private Queue _otherQueue; |
334 |
tdb |
1.10 |
|
335 |
|
|
/** |
336 |
|
|
* Outgoing ALL Queue |
337 |
|
|
*/ |
338 |
|
|
private Queue _allQueue; |
339 |
tdb |
1.17 |
|
340 |
|
|
/** |
341 |
|
|
* A reference to the XMLCache in use |
342 |
|
|
*/ |
343 |
|
|
private XMLCache _xmlCache = XMLCache.getInstance(); |
344 |
tdb |
1.9 |
|
345 |
tdb |
1.1 |
//---STATIC ATTRIBUTES--- |
346 |
ajm |
1.3 |
|
347 |
|
|
/** |
348 |
|
|
* A reference to the single instance of this class |
349 |
|
|
*/ |
350 |
|
|
private static MonitorManager _instance; |
351 |
tdb |
1.1 |
|
352 |
|
|
} |