| 24 |
|
//---IMPORTS--- |
| 25 |
|
import uk.org.iscream.cms.server.componentmanager.*; |
| 26 |
|
import uk.org.iscream.cms.server.core.*; |
| 27 |
< |
import uk.org.iscream.cms.server.util.*; |
| 27 |
> |
import uk.org.iscream.cms.util.*; |
| 28 |
|
import java.util.*; |
| 29 |
|
|
| 30 |
|
/** |
| 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. |
| 38 |
> |
* type. It then places it into either a data queue, or an other |
| 39 |
> |
* 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. |
| 93 |
|
String queueRemoveAlgorithm = cp.getProperty(_name, "Queue.RemoveAlgorithm"); |
| 94 |
|
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
| 95 |
|
if(algorithm != -1) { |
| 96 |
< |
_logger.write(toString(), Logger.DEBUG, "Starting 4 Queues with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
| 96 |
> |
_logger.write(toString(), Logger.DEBUG, "Starting 3 Queues with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
| 97 |
|
// we have valid values, so lets start it. |
| 98 |
|
_dataQueue = new Queue(queueSizeLimit, algorithm); |
| 99 |
– |
_heartbeatQueue = new Queue(queueSizeLimit, algorithm); |
| 99 |
|
_otherQueue = new Queue(queueSizeLimit, algorithm); |
| 100 |
|
_allQueue = new Queue(queueSizeLimit, algorithm); |
| 101 |
|
} |
| 103 |
|
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
| 104 |
|
// just don't activate a limit |
| 105 |
|
_dataQueue = new Queue(); |
| 107 |
– |
_heartbeatQueue = new Queue(); |
| 106 |
|
_otherQueue = new Queue(); |
| 107 |
|
_allQueue = new Queue(); |
| 108 |
|
} |
| 110 |
|
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
| 111 |
|
// just don't activate a limit |
| 112 |
|
_dataQueue = new Queue(); |
| 115 |
– |
_heartbeatQueue = new Queue(); |
| 113 |
|
_otherQueue = new Queue(); |
| 114 |
|
_allQueue = new Queue(); |
| 115 |
|
} catch (NumberFormatException e) { |
| 116 |
|
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
| 117 |
|
// just don't activate a limit |
| 118 |
|
_dataQueue = new Queue(); |
| 122 |
– |
_heartbeatQueue = new Queue(); |
| 119 |
|
_otherQueue = new Queue(); |
| 120 |
|
_allQueue = new Queue(); |
| 121 |
|
} |
| 125 |
|
// try to get the interval, if this fails, we won't start up the monitor |
| 126 |
|
int queueMonitorInterval = Integer.parseInt(cp.getProperty(_name, "Queue.MonitorInterval")); |
| 127 |
|
_dataQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " DataQueue"); |
| 132 |
– |
_heartbeatQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " HeartbeatQueue"); |
| 128 |
|
_otherQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " OtherQueue"); |
| 129 |
|
_allQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " AllQueue"); |
| 130 |
|
} catch (PropertyNotFoundException e) { |
| 177 |
|
* threads. |
| 178 |
|
*/ |
| 179 |
|
public void run() { |
| 185 |
– |
// construct now, and use multiple times |
| 186 |
– |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(); |
| 187 |
– |
|
| 180 |
|
boolean run=true; |
| 181 |
|
|
| 182 |
|
// keep these out here, saves recreating the object |
| 193 |
|
XMLPacket packet = null; |
| 194 |
|
|
| 195 |
|
try { |
| 196 |
< |
packet = xmlPacketMaker.createXMLPacket(xml); |
| 196 |
> |
packet = _xmlCache.getXMLPacket(xml); |
| 197 |
|
} catch(InvalidXMLException e) { |
| 198 |
|
_logger.write(toString(), Logger.ERROR, "Invalid XML: "+e); |
| 199 |
|
// skip the rest of this loop iteration |
| 200 |
|
continue; |
| 201 |
|
} |
| 202 |
+ |
|
| 203 |
+ |
if(packet == null) { |
| 204 |
+ |
_logger.write(toString(), Logger.WARNING, "Got a null packet when parsing: "+xml); |
| 205 |
+ |
// skip to next packet |
| 206 |
+ |
continue; |
| 207 |
+ |
} |
| 208 |
|
|
| 209 |
|
// examine the packet and place it in the relevant outgoing queue |
| 210 |
< |
if(packet.getParam("packet.attributes.type").equals("data")) { |
| 210 |
> |
if(packet.getParam("packet.attributes.type") != null && |
| 211 |
> |
packet.getParam("packet.attributes.type").equals("data")) { |
| 212 |
|
_dataQueue.add(packet); |
| 213 |
|
} |
| 215 |
– |
else if(packet.getParam("packet.attributes.type").equals("heartbeat")) { |
| 216 |
– |
_heartbeatQueue.add(packet); |
| 217 |
– |
} |
| 214 |
|
else { |
| 215 |
|
_otherQueue.add(packet); |
| 216 |
|
} |
| 223 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
| 224 |
|
* method to provide clean logging (every class should have this). |
| 225 |
|
* |
| 226 |
< |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
| 226 |
> |
* This uses the uk.org.iscream.cms.util.FormatName class |
| 227 |
|
* to format the toString() |
| 228 |
|
* |
| 229 |
|
* @return the name of this class and its CVS revision |
| 249 |
|
|
| 250 |
|
/** |
| 251 |
|
* Allows Monitors to obtain |
| 256 |
– |
* the queue of heatbeat packets |
| 257 |
– |
*/ |
| 258 |
– |
public Queue getHeartbeatQueue() { |
| 259 |
– |
return _heartbeatQueue; |
| 260 |
– |
} |
| 261 |
– |
|
| 262 |
– |
/** |
| 263 |
– |
* Allows Monitors to obtain |
| 252 |
|
* the queue of all other packets |
| 253 |
|
*/ |
| 254 |
|
public Queue getOtherQueue() { |
| 314 |
|
private Queue _dataQueue; |
| 315 |
|
|
| 316 |
|
/** |
| 329 |
– |
* Outgoing heartbeat Queue |
| 330 |
– |
*/ |
| 331 |
– |
private Queue _heartbeatQueue; |
| 332 |
– |
|
| 333 |
– |
/** |
| 317 |
|
* Outgoing other Queue |
| 318 |
|
*/ |
| 319 |
|
private Queue _otherQueue; |
| 322 |
|
* Outgoing ALL Queue |
| 323 |
|
*/ |
| 324 |
|
private Queue _allQueue; |
| 325 |
+ |
|
| 326 |
+ |
/** |
| 327 |
+ |
* A reference to the XMLCache in use |
| 328 |
+ |
*/ |
| 329 |
+ |
private XMLCache _xmlCache = XMLCache.getInstance(); |
| 330 |
|
|
| 331 |
|
//---STATIC ATTRIBUTES--- |
| 332 |
|
|