1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
//---PACKAGE DECLARATION--- |
21 |
< |
package uk.org.iscream.client; |
21 |
> |
package uk.org.iscream.cms.server.client; |
22 |
|
|
23 |
|
//---IMPORTS--- |
24 |
< |
import uk.org.iscream.componentmanager.*; |
25 |
< |
import uk.org.iscream.core.*; |
26 |
< |
import uk.org.iscream.util.*; |
24 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
25 |
> |
import uk.org.iscream.cms.server.core.*; |
26 |
> |
import uk.org.iscream.cms.server.util.*; |
27 |
|
import java.util.*; |
28 |
|
|
29 |
|
/** |
30 |
|
* A manager for the Monitors. |
31 |
|
* |
32 |
+ |
* This class starts by loading all the monitors as specificed in the configuration. |
33 |
+ |
* These monitors should implement the PluginMonitor interface. |
34 |
+ |
* |
35 |
+ |
* This class then takes the feed of data coming in over CORBA from |
36 |
+ |
* the ClientServant queue. This data is then looked at to determine |
37 |
+ |
* type. It then places it into either a data queue, a heartbeat queue or |
38 |
+ |
* an other queue, and all data in the the all queue. |
39 |
+ |
* |
40 |
+ |
* Monitors then read the data off the queue that they are interested in |
41 |
+ |
* and process the data accordingly. |
42 |
+ |
* |
43 |
|
* @author $Author$ |
44 |
|
* @version $Id$ |
45 |
|
*/ |
46 |
< |
class MonitorManager extends Thread { |
46 |
> |
public class MonitorManager extends Thread { |
47 |
|
|
48 |
|
//---FINAL ATTRIBUTES--- |
49 |
|
|
58 |
|
* Return a reference to the single class. |
59 |
|
* Construct it if it does not already exist, otherwise just return the reference. |
60 |
|
*/ |
61 |
< |
public static MonitorManager getInstance() { |
61 |
> |
public synchronized static MonitorManager getInstance() { |
62 |
|
if (_instance == null){ |
63 |
|
_instance = new MonitorManager(); |
64 |
|
} |
67 |
|
|
68 |
|
//---CONSTRUCTORS--- |
69 |
|
|
70 |
+ |
/** |
71 |
+ |
* Constructs a new MonitorManager. |
72 |
+ |
* This initialises all the queues and loads |
73 |
+ |
* all the Monitors that have been specified in the configuration |
74 |
+ |
*/ |
75 |
|
private MonitorManager() { |
76 |
|
// set our name |
77 |
|
setName("client.MonitorManager"); |
81 |
|
_logger.write(toString(), Logger.SYSINIT, "Initialising"); |
82 |
|
_logger.write(toString(), Logger.SYSMSG, "Creating monitor pipeline for plugin monitors ..."); |
83 |
|
|
84 |
+ |
// get the config proxy |
85 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
86 |
+ |
|
87 |
+ |
// get the configuration for our outgoing queue's |
88 |
+ |
|
89 |
+ |
// see if these Queue's need a size limit |
90 |
+ |
try { |
91 |
+ |
int queueSizeLimit = Integer.parseInt(cp.getProperty(_name, "Queue.SizeLimit")); |
92 |
+ |
String queueRemoveAlgorithm = cp.getProperty(_name, "Queue.RemoveAlgorithm"); |
93 |
+ |
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
94 |
+ |
if(algorithm != -1) { |
95 |
+ |
_logger.write(toString(), Logger.DEBUG, "Starting 4 Queues with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
96 |
+ |
// we have valid values, so lets start it. |
97 |
+ |
_dataQueue = new Queue(queueSizeLimit, algorithm); |
98 |
+ |
_heartbeatQueue = new Queue(queueSizeLimit, algorithm); |
99 |
+ |
_otherQueue = new Queue(queueSizeLimit, algorithm); |
100 |
+ |
_allQueue = new Queue(queueSizeLimit, algorithm); |
101 |
+ |
} |
102 |
+ |
else { |
103 |
+ |
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
104 |
+ |
// just don't activate a limit |
105 |
+ |
_dataQueue = new Queue(); |
106 |
+ |
_heartbeatQueue = new Queue(); |
107 |
+ |
_otherQueue = new Queue(); |
108 |
+ |
_allQueue = new Queue(); |
109 |
+ |
} |
110 |
+ |
} catch (PropertyNotFoundException e) { |
111 |
+ |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
112 |
+ |
// just don't activate a limit |
113 |
+ |
_dataQueue = new Queue(); |
114 |
+ |
_heartbeatQueue = new Queue(); |
115 |
+ |
_otherQueue = new Queue(); |
116 |
+ |
_allQueue = new Queue(); |
117 |
+ |
} catch (NumberFormatException e) { |
118 |
+ |
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
119 |
+ |
// just don't activate a limit |
120 |
+ |
_dataQueue = new Queue(); |
121 |
+ |
_heartbeatQueue = new Queue(); |
122 |
+ |
_otherQueue = new Queue(); |
123 |
+ |
_allQueue = new Queue(); |
124 |
+ |
} |
125 |
+ |
|
126 |
+ |
// startup monitors on these queues |
127 |
+ |
try { |
128 |
+ |
// try to get the interval, if this fails, we won't start up the monitor |
129 |
+ |
int queueMonitorInterval = Integer.parseInt(cp.getProperty(_name, "Queue.MonitorInterval")); |
130 |
+ |
_dataQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " DataQueue"); |
131 |
+ |
_heartbeatQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " HeartbeatQueue"); |
132 |
+ |
_otherQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " OtherQueue"); |
133 |
+ |
_allQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " AllQueue"); |
134 |
+ |
} catch (PropertyNotFoundException e) { |
135 |
+ |
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
136 |
+ |
} |
137 |
+ |
|
138 |
|
// get the configuration for this plug-in setup |
139 |
< |
Configuration config = _refman.getCM().getConfiguration(_name); |
140 |
< |
String pluginsPackage = config.getProperty("Monitor.PluginsPackage"); |
141 |
< |
String pluginsList = config.getProperty("Monitor.Plugins"); |
139 |
> |
String pluginsPackage, pluginsList; |
140 |
> |
try { |
141 |
> |
pluginsPackage = cp.getProperty(_name, "Monitor.PluginsPackage"); |
142 |
> |
pluginsList = cp.getProperty(_name, "Monitor.Plugins"); |
143 |
> |
} catch(PropertyNotFoundException e) { |
144 |
> |
_logger.write(toString(), Logger.WARNING, "Unable to get required configuration, Monitor's will not be activated: "+e); |
145 |
> |
// setting these will ensure we don't build a pipeline |
146 |
> |
pluginsPackage = ""; |
147 |
> |
pluginsList = ""; |
148 |
> |
} |
149 |
|
|
150 |
|
StringTokenizer st = new StringTokenizer(pluginsList, ";"); |
151 |
|
|
174 |
|
|
175 |
|
//---PUBLIC METHODS--- |
176 |
|
|
177 |
+ |
/** |
178 |
+ |
* Runs the MonitorManager. This reads data from the |
179 |
+ |
* inbound queue (from the ClientServant). And passes |
180 |
+ |
* it into the appropriate queue for processing by the monitor |
181 |
+ |
* threads. |
182 |
+ |
*/ |
183 |
|
public void run() { |
184 |
|
// construct now, and use multiple times |
185 |
|
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(); |
206 |
|
// skip the rest of this loop iteration |
207 |
|
continue; |
208 |
|
} |
209 |
< |
|
210 |
< |
// for each monitor in the pipeline... |
211 |
< |
Iterator pluginMonitors = _monitorPipeline.iterator(); |
212 |
< |
while (pluginMonitors.hasNext()){ |
111 |
< |
PluginMonitor monitor = (PluginMonitor)pluginMonitors.next(); |
112 |
< |
monitor.analysePacket(packet); |
209 |
> |
|
210 |
> |
// examine the packet and place it in the relevant outgoing queue |
211 |
> |
if(packet.getParam("packet.attributes.type").equals("data")) { |
212 |
> |
_dataQueue.add(packet); |
213 |
|
} |
214 |
+ |
else if(packet.getParam("packet.attributes.type").equals("heartbeat")) { |
215 |
+ |
_heartbeatQueue.add(packet); |
216 |
+ |
} |
217 |
+ |
else { |
218 |
+ |
_otherQueue.add(packet); |
219 |
+ |
} |
220 |
+ |
// always add to all queue |
221 |
+ |
_allQueue.add(packet); |
222 |
|
} |
223 |
|
} |
224 |
|
|
226 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
227 |
|
* method to provide clean logging (every class should have this). |
228 |
|
* |
229 |
< |
* This uses the uk.org.iscream.util.FormatName class |
229 |
> |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
230 |
|
* to format the toString() |
231 |
|
* |
232 |
|
* @return the name of this class and its CVS revision |
241 |
|
//---PRIVATE METHODS--- |
242 |
|
|
243 |
|
//---ACCESSOR/MUTATOR METHODS--- |
244 |
< |
|
244 |
> |
|
245 |
> |
/** |
246 |
> |
* Allows Monitors to obtain |
247 |
> |
* the queue of data packets |
248 |
> |
*/ |
249 |
> |
public Queue getDataQueue() { |
250 |
> |
return _dataQueue; |
251 |
> |
} |
252 |
> |
|
253 |
> |
/** |
254 |
> |
* Allows Monitors to obtain |
255 |
> |
* the queue of heatbeat packets |
256 |
> |
*/ |
257 |
> |
public Queue getHeartbeatQueue() { |
258 |
> |
return _heartbeatQueue; |
259 |
> |
} |
260 |
> |
|
261 |
> |
/** |
262 |
> |
* Allows Monitors to obtain |
263 |
> |
* the queue of all other packets |
264 |
> |
*/ |
265 |
> |
public Queue getOtherQueue() { |
266 |
> |
return _otherQueue; |
267 |
> |
} |
268 |
> |
|
269 |
> |
/** |
270 |
> |
* In case a Monitor wants more |
271 |
> |
* than one type of packet, |
272 |
> |
* this queue can be obtained. |
273 |
> |
*/ |
274 |
> |
public Queue getAllQueue() { |
275 |
> |
return _allQueue; |
276 |
> |
} |
277 |
> |
|
278 |
|
//---ATTRIBUTES--- |
279 |
|
|
280 |
|
/** |
300 |
|
private ReferenceManager _refman = ReferenceManager.getInstance(); |
301 |
|
|
302 |
|
/** |
303 |
< |
* A reference to our Queue |
303 |
> |
* A reference to our incoming Queue |
304 |
|
*/ |
305 |
|
private Queue _queue; |
306 |
|
|
307 |
|
/** |
308 |
< |
* Our queue ID |
308 |
> |
* Our incoming queue ID |
309 |
|
*/ |
310 |
|
private int _qID; |
311 |
|
|
318 |
|
* LinkedList for holding the PluginMonitor objects (the pipeline). |
319 |
|
*/ |
320 |
|
private LinkedList _monitorPipeline = new LinkedList(); |
321 |
< |
|
321 |
> |
|
322 |
> |
/** |
323 |
> |
* Outgoing data Queue |
324 |
> |
*/ |
325 |
> |
private Queue _dataQueue; |
326 |
> |
|
327 |
> |
/** |
328 |
> |
* Outgoing heartbeat Queue |
329 |
> |
*/ |
330 |
> |
private Queue _heartbeatQueue; |
331 |
> |
|
332 |
> |
/** |
333 |
> |
* Outgoing other Queue |
334 |
> |
*/ |
335 |
> |
private Queue _otherQueue; |
336 |
> |
|
337 |
> |
/** |
338 |
> |
* Outgoing ALL Queue |
339 |
> |
*/ |
340 |
> |
private Queue _allQueue; |
341 |
> |
|
342 |
|
//---STATIC ATTRIBUTES--- |
343 |
|
|
344 |
|
/** |