use of cern.laser.source.alarmsysteminterface.impl.message.ASIMessage in project ACS by ACS-Community.
the class AlarmMessageProcessorImpl method process.
/**
* Process a message
*
* @param xml the XML message to unmarshall into a <code>ASIMessage</code>
*/
public void process(String xml) throws Exception {
ASIMessage asi_message = XMLMessageHelper.unmarshal(xml);
logger.log(AcsLogLevel.DEBUG, "message from " + asi_message.getSourceName() + "@" + asi_message.getSourceHostname());
if (asi_message.getBackup()) {
logger.log(AcsLogLevel.DEBUG, "processing backup...");
processBackup(asi_message);
logger.log(AcsLogLevel.DEBUG, "backup processed");
} else {
logger.log(AcsLogLevel.DEBUG, "processing change...");
processChanges(asi_message);
logger.log(AcsLogLevel.DEBUG, "change processed");
}
// One alarm more has been processed!
alarmsProcessed.incrementAndGet();
// of the processed message
try {
long timestamp = IsoDateFormat.parseIsoTimestamp(asi_message.getSourceTimestamp()).getTime();
alarmsDelayHelper.updateDelay(timestamp);
} catch (ParseException pe) {
logger.log(AcsLogLevel.ERROR, "Error parsing a ISO timestamp: " + asi_message.getSourceTimestamp(), pe);
}
}
use of cern.laser.source.alarmsysteminterface.impl.message.ASIMessage in project ACS by ACS-Community.
the class ASIMessageHelper method marshal.
/**
* DOCUMENT ME!
*
* @param states DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public static ASIMessage marshal(Collection states) {
if (states == null) {
throw (new IllegalArgumentException("states collection is null"));
}
ASIMessage asi_message = new ASIMessage();
Iterator iterator = states.iterator();
FaultStates fault_states = new FaultStates();
while (iterator.hasNext()) {
Object ref = iterator.next();
if (ref instanceof FaultState) {
fault_states.addFaultState(FaultStateHelper.marshal((FaultState) ref));
} else {
throw new IllegalArgumentException("collection does not contain FaultState instances");
}
}
asi_message.setFaultStates(fault_states);
return asi_message;
}
use of cern.laser.source.alarmsysteminterface.impl.message.ASIMessage in project ACS by ACS-Community.
the class AlarmSystemInterfaceProxy method publish.
/** Publish a collection of fault states.
* @param states the fault states collection to publish
* @param backup the type of fault states to publish (backup or not)
* @throw Exception if publishing fails
*/
private void publish(Collection states, boolean backup) throws Exception {
cat.debug("publishing " + states.size() + " fault state(s)");
cat.debug("content :\n" + states.toString());
ASIMessage asi_message = ASIMessageHelper.marshal(states);
asi_message.setSourceName(getSourceName());
asi_message.setSourceHostname(hostName);
asi_message.setSourceTimestamp(IsoDateFormat.formatCurrentDate());
asi_message.setBackup(backup);
asi_message.setVersion(configuration.getASIVersion());
TextMessage alarm_message = publisher.createTextMessage();
alarm_message.setText(XMLMessageHelper.marshal(asi_message));
alarm_message.setStringProperty(configuration.getSourceNameProperty(), getSourceName());
alarm_message.setStringProperty(configuration.getSourceHostnameProperty(), hostName);
alarm_message.setStringProperty(configuration.getBackupProperty(), String.valueOf(backup));
alarm_message.setStringProperty(configuration.getAlarmsNumberProperty(), String.valueOf(states.size()));
StringBuffer topic = new StringBuffer(configuration.getAlarmsTopic());
topic.append(".");
topic.append(getSourceName());
if (backup) {
publisher.publish(topic.toString(), alarm_message, configuration.getBackupDeliveryMode(), configuration.getBackupPriority(), configuration.getBackupTimeToLive());
} else {
publisher.publish(topic.toString(), alarm_message, configuration.getChangesDeliveryMode(), configuration.getChangesPriority(), configuration.getChangesTimeToLive());
}
cat.debug("published");
}
Aggregations