1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.org.iscream.client; |
2 |
> |
package uk.org.iscream.cms.server.client; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.org.iscream.componentmanager.*; |
6 |
< |
import uk.org.iscream.core.*; |
7 |
< |
import uk.org.iscream.util.*; |
5 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
6 |
> |
import uk.org.iscream.cms.server.core.*; |
7 |
> |
import uk.org.iscream.cms.server.util.*; |
8 |
|
import java.util.*; |
9 |
|
|
10 |
|
/** |
11 |
|
* A manager for the Monitors. |
12 |
|
* |
13 |
+ |
* This class starts by loading all the monitors as specificed in the configuration. |
14 |
+ |
* These monitors should implement the PluginMonitor interface. |
15 |
+ |
* |
16 |
+ |
* This class then takes the feed of data coming in over CORBA from |
17 |
+ |
* the ClientServant queue. This data is then looked at to determine |
18 |
+ |
* type. It then places it into either a data queue, a heartbeat queue or |
19 |
+ |
* an other queue, and all data in the the all queue. |
20 |
+ |
* |
21 |
+ |
* Monitors then read the data off the queue that they are interested in |
22 |
+ |
* and process the data accordingly. |
23 |
+ |
* |
24 |
|
* @author $Author$ |
25 |
|
* @version $Id$ |
26 |
|
*/ |
27 |
< |
class MonitorManager extends Thread { |
27 |
> |
public class MonitorManager extends Thread { |
28 |
|
|
29 |
|
//---FINAL ATTRIBUTES--- |
30 |
|
|
39 |
|
* Return a reference to the single class. |
40 |
|
* Construct it if it does not already exist, otherwise just return the reference. |
41 |
|
*/ |
42 |
< |
public static MonitorManager getInstance() { |
42 |
> |
public synchronized static MonitorManager getInstance() { |
43 |
|
if (_instance == null){ |
44 |
|
_instance = new MonitorManager(); |
45 |
|
} |
48 |
|
|
49 |
|
//---CONSTRUCTORS--- |
50 |
|
|
51 |
+ |
/** |
52 |
+ |
* Constructs a new MonitorManager. |
53 |
+ |
* This initialises all the queues and loads |
54 |
+ |
* all the Monitors that have been specified in the configuration |
55 |
+ |
*/ |
56 |
|
private MonitorManager() { |
57 |
|
// set our name |
58 |
|
setName("client.MonitorManager"); |
62 |
|
_logger.write(toString(), Logger.SYSINIT, "Initialising"); |
63 |
|
_logger.write(toString(), Logger.SYSMSG, "Creating monitor pipeline for plugin monitors ..."); |
64 |
|
|
65 |
+ |
// get the config proxy |
66 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
67 |
+ |
|
68 |
+ |
// get the configuration for our outgoing queue's |
69 |
+ |
|
70 |
+ |
// see if these Queue's need a size limit |
71 |
+ |
try { |
72 |
+ |
int queueSizeLimit = Integer.parseInt(cp.getProperty(_name, "Queue.SizeLimit")); |
73 |
+ |
String queueRemoveAlgorithm = cp.getProperty(_name, "Queue.RemoveAlgorithm"); |
74 |
+ |
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
75 |
+ |
if(algorithm != -1) { |
76 |
+ |
_logger.write(toString(), Logger.DEBUG, "Starting 4 Queues with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
77 |
+ |
// we have valid values, so lets start it. |
78 |
+ |
_dataQueue = new Queue(queueSizeLimit, algorithm); |
79 |
+ |
_heartbeatQueue = new Queue(queueSizeLimit, algorithm); |
80 |
+ |
_otherQueue = new Queue(queueSizeLimit, algorithm); |
81 |
+ |
_allQueue = new Queue(queueSizeLimit, algorithm); |
82 |
+ |
} |
83 |
+ |
else { |
84 |
+ |
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
85 |
+ |
// just don't activate a limit |
86 |
+ |
_dataQueue = new Queue(); |
87 |
+ |
_heartbeatQueue = new Queue(); |
88 |
+ |
_otherQueue = new Queue(); |
89 |
+ |
_allQueue = new Queue(); |
90 |
+ |
} |
91 |
+ |
} catch (PropertyNotFoundException e) { |
92 |
+ |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
93 |
+ |
// just don't activate a limit |
94 |
+ |
_dataQueue = new Queue(); |
95 |
+ |
_heartbeatQueue = new Queue(); |
96 |
+ |
_otherQueue = new Queue(); |
97 |
+ |
_allQueue = new Queue(); |
98 |
+ |
} catch (NumberFormatException e) { |
99 |
+ |
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
100 |
+ |
// just don't activate a limit |
101 |
+ |
_dataQueue = new Queue(); |
102 |
+ |
_heartbeatQueue = new Queue(); |
103 |
+ |
_otherQueue = new Queue(); |
104 |
+ |
_allQueue = new Queue(); |
105 |
+ |
} |
106 |
+ |
|
107 |
+ |
// startup monitors on these queues |
108 |
+ |
try { |
109 |
+ |
// try to get the interval, if this fails, we won't start up the monitor |
110 |
+ |
int queueMonitorInterval = Integer.parseInt(cp.getProperty(_name, "Queue.MonitorInterval")); |
111 |
+ |
_dataQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " DataQueue"); |
112 |
+ |
_heartbeatQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " HeartbeatQueue"); |
113 |
+ |
_otherQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " OtherQueue"); |
114 |
+ |
_allQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " AllQueue"); |
115 |
+ |
} catch (PropertyNotFoundException e) { |
116 |
+ |
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
117 |
+ |
} |
118 |
+ |
|
119 |
|
// get the configuration for this plug-in setup |
120 |
< |
Configuration config = _refman.getCM().getConfiguration(_name); |
121 |
< |
String pluginsPackage = config.getProperty("Monitor.PluginsPackage"); |
122 |
< |
String pluginsList = config.getProperty("Monitor.Plugins"); |
120 |
> |
String pluginsPackage, pluginsList; |
121 |
> |
try { |
122 |
> |
pluginsPackage = cp.getProperty(_name, "Monitor.PluginsPackage"); |
123 |
> |
pluginsList = cp.getProperty(_name, "Monitor.Plugins"); |
124 |
> |
} catch(PropertyNotFoundException e) { |
125 |
> |
_logger.write(toString(), Logger.WARNING, "Unable to get required configuration, Monitor's will not be activated: "+e); |
126 |
> |
// setting these will ensure we don't build a pipeline |
127 |
> |
pluginsPackage = ""; |
128 |
> |
pluginsList = ""; |
129 |
> |
} |
130 |
|
|
131 |
|
StringTokenizer st = new StringTokenizer(pluginsList, ";"); |
132 |
|
|
155 |
|
|
156 |
|
//---PUBLIC METHODS--- |
157 |
|
|
158 |
+ |
/** |
159 |
+ |
* Runs the MonitorManager. This reads data from the |
160 |
+ |
* inbound queue (from the ClientServant). And passes |
161 |
+ |
* it into the appropriate queue for processing by the monitor |
162 |
+ |
* threads. |
163 |
+ |
*/ |
164 |
|
public void run() { |
165 |
|
// construct now, and use multiple times |
166 |
|
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(); |
187 |
|
// skip the rest of this loop iteration |
188 |
|
continue; |
189 |
|
} |
190 |
< |
|
191 |
< |
// for each monitor in the pipeline... |
192 |
< |
Iterator pluginMonitors = _monitorPipeline.iterator(); |
193 |
< |
while (pluginMonitors.hasNext()){ |
111 |
< |
PluginMonitor monitor = (PluginMonitor)pluginMonitors.next(); |
112 |
< |
monitor.analysePacket(packet); |
190 |
> |
|
191 |
> |
// examine the packet and place it in the relevant outgoing queue |
192 |
> |
if(packet.getParam("packet.attributes.type").equals("data")) { |
193 |
> |
_dataQueue.add(packet); |
194 |
|
} |
195 |
+ |
else if(packet.getParam("packet.attributes.type").equals("heartbeat")) { |
196 |
+ |
_heartbeatQueue.add(packet); |
197 |
+ |
} |
198 |
+ |
else { |
199 |
+ |
_otherQueue.add(packet); |
200 |
+ |
} |
201 |
+ |
// always add to all queue |
202 |
+ |
_allQueue.add(packet); |
203 |
|
} |
204 |
|
} |
205 |
|
|
207 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
208 |
|
* method to provide clean logging (every class should have this). |
209 |
|
* |
210 |
< |
* This uses the uk.org.iscream.util.FormatName class |
210 |
> |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
211 |
|
* to format the toString() |
212 |
|
* |
213 |
|
* @return the name of this class and its CVS revision |
222 |
|
//---PRIVATE METHODS--- |
223 |
|
|
224 |
|
//---ACCESSOR/MUTATOR METHODS--- |
225 |
< |
|
225 |
> |
|
226 |
> |
/** |
227 |
> |
* Allows Monitors to obtain |
228 |
> |
* the queue of data packets |
229 |
> |
*/ |
230 |
> |
public Queue getDataQueue() { |
231 |
> |
return _dataQueue; |
232 |
> |
} |
233 |
> |
|
234 |
> |
/** |
235 |
> |
* Allows Monitors to obtain |
236 |
> |
* the queue of heatbeat packets |
237 |
> |
*/ |
238 |
> |
public Queue getHeartbeatQueue() { |
239 |
> |
return _heartbeatQueue; |
240 |
> |
} |
241 |
> |
|
242 |
> |
/** |
243 |
> |
* Allows Monitors to obtain |
244 |
> |
* the queue of all other packets |
245 |
> |
*/ |
246 |
> |
public Queue getOtherQueue() { |
247 |
> |
return _otherQueue; |
248 |
> |
} |
249 |
> |
|
250 |
> |
/** |
251 |
> |
* In case a Monitor wants more |
252 |
> |
* than one type of packet, |
253 |
> |
* this queue can be obtained. |
254 |
> |
*/ |
255 |
> |
public Queue getAllQueue() { |
256 |
> |
return _allQueue; |
257 |
> |
} |
258 |
> |
|
259 |
|
//---ATTRIBUTES--- |
260 |
|
|
261 |
|
/** |
281 |
|
private ReferenceManager _refman = ReferenceManager.getInstance(); |
282 |
|
|
283 |
|
/** |
284 |
< |
* A reference to our Queue |
284 |
> |
* A reference to our incoming Queue |
285 |
|
*/ |
286 |
|
private Queue _queue; |
287 |
|
|
288 |
|
/** |
289 |
< |
* Our queue ID |
289 |
> |
* Our incoming queue ID |
290 |
|
*/ |
291 |
|
private int _qID; |
292 |
|
|
299 |
|
* LinkedList for holding the PluginMonitor objects (the pipeline). |
300 |
|
*/ |
301 |
|
private LinkedList _monitorPipeline = new LinkedList(); |
302 |
< |
|
302 |
> |
|
303 |
> |
/** |
304 |
> |
* Outgoing data Queue |
305 |
> |
*/ |
306 |
> |
private Queue _dataQueue; |
307 |
> |
|
308 |
> |
/** |
309 |
> |
* Outgoing heartbeat Queue |
310 |
> |
*/ |
311 |
> |
private Queue _heartbeatQueue; |
312 |
> |
|
313 |
> |
/** |
314 |
> |
* Outgoing other Queue |
315 |
> |
*/ |
316 |
> |
private Queue _otherQueue; |
317 |
> |
|
318 |
> |
/** |
319 |
> |
* Outgoing ALL Queue |
320 |
> |
*/ |
321 |
> |
private Queue _allQueue; |
322 |
> |
|
323 |
|
//---STATIC ATTRIBUTES--- |
324 |
|
|
325 |
|
/** |