1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org |
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.clientinterface; |
22 |
> |
package uk.org.iscream.cms.server.clientinterface; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
< |
import uk.ac.ukc.iscream.util.*; |
26 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
27 |
< |
import uk.ac.ukc.iscream.core.*; |
28 |
< |
import java.util.*; |
25 |
> |
import uk.org.iscream.cms.util.*; |
26 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
27 |
> |
import uk.org.iscream.cms.server.core.*; |
28 |
> |
import java.util.HashMap; |
29 |
> |
import java.util.Iterator; |
30 |
> |
import java.util.LinkedList; |
31 |
> |
import java.util.List; |
32 |
> |
import java.util.StringTokenizer; |
33 |
|
|
34 |
|
/** |
35 |
|
* Receives data from the incoming CORBA servant, places |
62 |
|
// set the Thread name |
63 |
|
setName("clientinterface.PacketSorter"); |
64 |
|
|
65 |
< |
_queue = new Queue(); |
65 |
> |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
66 |
> |
String configName = "ClientInterface"; |
67 |
> |
|
68 |
> |
// see if this Queue needs a size limit |
69 |
> |
try { |
70 |
> |
int queueSizeLimit = Integer.parseInt(cp.getProperty(configName, "Queue.SizeLimit")); |
71 |
> |
String queueRemoveAlgorithm = cp.getProperty(configName, "Queue.RemoveAlgorithm"); |
72 |
> |
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
73 |
> |
if(algorithm != -1) { |
74 |
> |
_logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
75 |
> |
// we have valid values, so lets start it. |
76 |
> |
_queue = new Queue(queueSizeLimit, algorithm); |
77 |
> |
} |
78 |
> |
else { |
79 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
80 |
> |
// just don't activate a limit |
81 |
> |
_queue = new Queue(); |
82 |
> |
} |
83 |
> |
|
84 |
> |
} catch (PropertyNotFoundException e) { |
85 |
> |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
86 |
> |
// just don't activate a limit |
87 |
> |
_queue = new Queue(); |
88 |
> |
} catch (NumberFormatException e) { |
89 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
90 |
> |
// just don't activate a limit |
91 |
> |
_queue = new Queue(); |
92 |
> |
} |
93 |
> |
|
94 |
|
// startup a monitor on this queue |
95 |
|
try { |
96 |
|
// try to get the interval, if this fails, we won't start up the monitor |
97 |
< |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
46 |
< |
int queueMonitorInterval = Integer.parseInt(cp.getProperty("ClientInterface", "Queue.MonitorInterval")); |
97 |
> |
int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval")); |
98 |
|
String queueName = _name + " PacketSorterQueue"; |
99 |
|
_queue.startMonitor(queueMonitorInterval*1000, queueName); |
100 |
|
} catch (PropertyNotFoundException e) { |
114 |
|
* loop forever processing and sending data. |
115 |
|
*/ |
116 |
|
public void run() { |
66 |
– |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(); |
117 |
|
int qID = _queue.getQueue(); |
118 |
|
while(true) { |
119 |
|
// attempt to get some data from the Queue |
128 |
|
XMLPacket packet = null; |
129 |
|
|
130 |
|
try { |
131 |
< |
packet = xmlPacketMaker.createXMLPacket(xml); |
131 |
> |
packet = _xmlCache.getXMLPacket(xml); |
132 |
|
} catch(InvalidXMLException e) { |
133 |
|
_logger.write(toString(), Logger.ERROR, "Invalid XML: "+e); |
134 |
|
// skip the rest of this loop iteration |
135 |
|
continue; |
136 |
|
} |
137 |
|
|
138 |
+ |
if(packet == null) { |
139 |
+ |
continue; |
140 |
+ |
} |
141 |
+ |
|
142 |
|
String packetType = packet.getParam("packet.attributes.type"); |
143 |
|
// check if we need to send it regardless |
144 |
< |
if(packetType.equals("data") || packetType.equals("heartbeat")) { |
144 |
> |
if(packetType.equals("data")) { |
145 |
|
String host = packet.getParam("packet.attributes.machine_name"); |
146 |
|
|
147 |
|
// look in the hostMap to see if anyone wants this data |
275 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
276 |
|
* method to provide clean logging (every class should have this). |
277 |
|
* |
278 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
278 |
> |
* This uses the uk.org.iscream.cms.util.NameFormat class |
279 |
|
* to format the toString() |
280 |
|
* |
281 |
|
* @return the name of this class and its CVS revision |
342 |
|
* A list of all hosts. |
343 |
|
*/ |
344 |
|
private LinkedList _allHostsList; |
345 |
+ |
|
346 |
+ |
/** |
347 |
+ |
* A reference to the XMLCache in use |
348 |
+ |
*/ |
349 |
+ |
private XMLCache _xmlCache = XMLCache.getInstance(); |
350 |
|
|
351 |
|
//---STATIC ATTRIBUTES--- |
352 |
|
|