Search in sources :

Example 1 with ASIMessage

use of cern.laser.source.alarmsysteminterface.impl.message.ASIMessage in project ACS by ACS-Community.

the class LaserComponent method buildMessage.

/**
	 * Build the {@link ACSJMSTextMessage} for a given fault state
	 * 
	 * @param state The fault state
	 * @param hostName The host name
	 * 
	 * @see AlarmSystemInterfaceProxy#publish
	 */
private TextMessage buildMessage(cern.laser.source.alarmsysteminterface.impl.message.FaultState state, String hostName, String sourceName) throws Exception {
    if (state == null) {
        throw new IllegalArgumentException("The fault state can't be null");
    }
    if (hostName == null || hostName.isEmpty()) {
        throw new IllegalArgumentException("Invalid host name");
    }
    if (sourceName == null || sourceName.isEmpty()) {
        throw new IllegalArgumentException("Invalid source name");
    }
    Collection<FaultStateImpl> tempStates = new Vector<FaultStateImpl>();
    cern.laser.source.alarmsysteminterface.impl.message.FaultState tempState = new FaultState();
    ASIMessage asi_message = ASIMessageHelper.marshal(tempStates);
    FaultStates states = new FaultStates();
    states.addFaultState(state);
    asi_message.setFaultStates(states);
    asi_message.setSourceName("ALARM_SYSTEM_SOURCES");
    asi_message.setSourceHostname(hostName);
    asi_message.setSourceTimestamp(IsoDateFormat.formatCurrentDate());
    asi_message.setBackup(false);
    Configurator configurator = new Configurator();
    ASIConfiguration configuration = configurator.getConfiguration();
    asi_message.setVersion(configuration.getASIVersion());
    ACSJMSTextMessage tm = new ACSJMSTextMessage(alSysContSvcs);
    tm.setText(XMLMessageHelper.marshal(asi_message));
    tm.setStringProperty(configuration.getSourceNameProperty(), sourceName);
    tm.setStringProperty(configuration.getSourceHostnameProperty(), hostName);
    tm.setStringProperty(configuration.getBackupProperty(), String.valueOf(false));
    tm.setStringProperty(configuration.getAlarmsNumberProperty(), String.valueOf(1));
    return tm;
}
Also used : ASIConfiguration(cern.laser.source.alarmsysteminterface.impl.configuration.ASIConfiguration) FaultStates(cern.laser.source.alarmsysteminterface.impl.message.FaultStates) Configurator(cern.laser.source.alarmsysteminterface.impl.Configurator) ACSFaultState(alma.alarmsystem.source.ACSFaultState) FaultState(cern.laser.source.alarmsysteminterface.impl.message.FaultState) LaserCoreFaultState(alma.alarmsystem.core.alarms.LaserCoreFaultState) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) FaultState(cern.laser.source.alarmsysteminterface.impl.message.FaultState) FaultStateImpl(cern.laser.source.alarmsysteminterface.impl.FaultStateImpl) Vector(java.util.Vector) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 2 with ASIMessage

use of cern.laser.source.alarmsysteminterface.impl.message.ASIMessage in project ACS by ACS-Community.

the class TestAlarmMessageProcessor method createJMSMessage.

private ACSJMSTextMessage createJMSMessage(String ff, String fm, int code, boolean active) throws Exception, JMSException {
    // Create the fault states
    List<FaultState> states = new ArrayList<FaultState>();
    for (int j = 0; j != N_STATE_CHANGES; j++) {
        FaultState faultState = new FaultStateImpl(ff, fm, code);
        faultState.setDescriptor(active ? FaultState.ACTIVE : FaultState.TERMINATE);
        faultState.setUserTimestamp(new Timestamp(System.currentTimeMillis()));
        states.add(faultState);
    }
    // Create the ASIMessage with the fault states
    ASIMessage asiMessage = ASIMessageHelper.marshal(states);
    cern.laser.source.alarmsysteminterface.impl.message.Timestamp timestamp = new cern.laser.source.alarmsysteminterface.impl.message.Timestamp();
    long currentTimeMillis = System.currentTimeMillis();
    timestamp.setMicroseconds(currentTimeMillis % 1000);
    timestamp.setSeconds(currentTimeMillis / 1000);
    asiMessage.setSourceTimestamp(timestamp);
    asiMessage.setSourceHostname(hostname);
    asiMessage.setBackup(false);
    asiMessage.setSourceName("ALARM_SYSTEM_SOURCES");
    // And wrap it inside a JMS text message
    ACSJMSTextMessage message = new ACSJMSTextMessage(new DummyContainerServices("test", m_logger));
    String text = XMLMessageHelper.marshal(asiMessage);
    message.setText(text);
    return message;
}
Also used : ArrayList(java.util.ArrayList) FaultState(cern.laser.source.alarmsysteminterface.FaultState) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) Timestamp(java.sql.Timestamp) DummyContainerServices(alma.acs.container.testsupport.DummyContainerServices) FaultStateImpl(cern.laser.source.alarmsysteminterface.impl.FaultStateImpl) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 3 with ASIMessage

use of cern.laser.source.alarmsysteminterface.impl.message.ASIMessage in project ACS by ACS-Community.

the class SendTest method receive.

/**
	 * The method receives all the messages published in the NC
	 * For each message received it checks if its content is right
	 * i.e. the name of the class, the member and the code contains the 
	 * number of the message in the sequence. In this way it also checks
	 * if the messages are received in the same order they were sent.
	 * The method also checks if all the messages have been received
	 * and prints a message if receives more messages then the messages 
	 * pushed
	 *  
	 * @param msg The message received from the NC
	 * @see alma.acs.nc.Consumer
	 */
@Override
public synchronized void receive(ACSJMSMessageEntity msg, EventDescription eventDescrip) {
    Collection<FaultState> faultStates;
    try {
        ASIMessage asiMsg = XMLMessageHelper.unmarshal(msg.text);
        faultStates = ASIMessageHelper.unmarshal(asiMsg);
    } catch (Exception e) {
        System.out.println("Exception caught while unmarshalling the msg " + e.getMessage());
        e.printStackTrace();
        receiverError = e;
        return;
    }
    Iterator<FaultState> iter = faultStates.iterator();
    while (iter.hasNext()) {
        FaultStateImpl fs = (FaultStateImpl) iter.next();
        if (!isValidFSMessage(fs, nMsgReceived)) {
            receiverError = "Invalid FaultState received as #" + nMsgReceived;
        }
        nMsgReceived++;
        if (nMsgReceived == ITERATIONS) {
            System.out.println("All alarms sent and received");
        } else if (nMsgReceived > ITERATIONS) {
            System.out.println("Received an alarm that has never been sent");
        }
    }
}
Also used : ACSFaultState(alma.alarmsystem.source.ACSFaultState) FaultState(cern.laser.source.alarmsysteminterface.FaultState) FaultStateImpl(cern.laser.source.alarmsysteminterface.impl.FaultStateImpl) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 4 with ASIMessage

use of cern.laser.source.alarmsysteminterface.impl.message.ASIMessage in project ACS by ACS-Community.

the class SourceStressTest method receive.

@Override
public synchronized void receive(ACSJMSMessageEntity msg, EventDescription eventDescrip) {
    ASIMessage asiMsg = null;
    try {
        asiMsg = XMLMessageHelper.unmarshal(msg.text);
    } catch (Exception e) {
        System.out.println("Exception caught while unmarshalling the msg " + e.getMessage());
        e.printStackTrace();
        //			receiverError = e; // SendTest works with checking these errors in the test..
        return;
    }
    Collection<FaultState> faultStates = ASIMessageHelper.unmarshal(asiMsg);
    assertNotNull(faultStates);
    for (FaultState fs : faultStates) {
        assertNotNull(fs);
        receivedFS.add(new FaultStateReceived(fs));
    }
}
Also used : ACSFaultState(alma.alarmsystem.source.ACSFaultState) FaultState(cern.laser.source.alarmsysteminterface.FaultState) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 5 with ASIMessage

use of cern.laser.source.alarmsysteminterface.impl.message.ASIMessage in project ACS by ACS-Community.

the class ASISubscriptionListener method onMessage.

/**
   * Callback method implementation.
   * @param message the JMS message received.
   */
public void onMessage(Message message) {
    cat.debug("got a message");
    if (message instanceof TextMessage) {
        try {
            TextMessage text_message = (TextMessage) message;
            String xml_message = text_message.getText();
            ASIMessage asi_message = XMLMessageHelper.unmarshal(xml_message);
            String source_name = asi_message.getSourceName();
            String source_hostname = asi_message.getSourceHostname();
            boolean backup = asi_message.getBackup();
            // ISO format
            String source_timestamp = asi_message.getSourceTimestamp();
            Collection states = ASIMessageHelper.unmarshal(asi_message);
            listener.onMessage(source_name, source_hostname, source_timestamp, backup, states);
        } catch (Exception e) {
            cat.error("exception caught : " + e.getMessage(), e);
        }
    }
}
Also used : Collection(java.util.Collection) 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