Search in sources :

Example 11 with ASIMessage

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);
    }
}
Also used : ParseException(java.text.ParseException) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 12 with ASIMessage

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;
}
Also used : FaultStates(cern.laser.source.alarmsysteminterface.impl.message.FaultStates) Iterator(java.util.Iterator) FaultState(cern.laser.source.alarmsysteminterface.FaultState) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 13 with ASIMessage

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");
}
Also used : TextMessage(javax.jms.TextMessage) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Aggregations

ASIMessage (cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)13 FaultState (cern.laser.source.alarmsysteminterface.FaultState)9 ACSFaultState (alma.alarmsystem.source.ACSFaultState)4 FaultStateImpl (cern.laser.source.alarmsysteminterface.impl.FaultStateImpl)4 ACSJMSTextMessage (com.cosylab.acs.jms.ACSJMSTextMessage)4 Vector (java.util.Vector)3 LaserCoreFaultState (alma.alarmsystem.core.alarms.LaserCoreFaultState)2 FaultStates (cern.laser.source.alarmsysteminterface.impl.message.FaultStates)2 Timestamp (java.sql.Timestamp)2 TextMessage (javax.jms.TextMessage)2 DummyContainerServices (alma.acs.container.testsupport.DummyContainerServices)1 Configurator (cern.laser.source.alarmsysteminterface.impl.Configurator)1 ASIConfiguration (cern.laser.source.alarmsysteminterface.impl.configuration.ASIConfiguration)1 FaultState (cern.laser.source.alarmsysteminterface.impl.message.FaultState)1 InetAddress (java.net.InetAddress)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1