Search in sources :

Example 6 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 7 with ASIMessage

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

the class SourceClient method receive.

/**
	 * The method receives all the messages published in the NC
	 * For each message received it check 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 void receive(ACSJMSMessageEntity msg, EventDescription eventDescrip) {
    ASIMessage asiMsg;
    Collection<FaultState> faultStates;
    try {
        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();
        return;
    }
    dispatchXMLASIMessage(msg.text);
    for (FaultState fs : faultStates) {
        dispatchFaultState(fs);
    }
}
Also used : FaultState(cern.laser.source.alarmsysteminterface.FaultState) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 8 with ASIMessage

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

the class SourcesListener method receive.

/**
	 * The method receives all the messages published in the NC by the sources
	 * 
	 *  
	 * @param msg The message received from the NC
	 */
@Override
public void receive(ACSJMSMessageEntity msg, EventDescription eventDescrip) {
    logger.fine("Msg received");
    ASIMessage asiMsg;
    Collection<FaultState> faultStates;
    try {
        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();
        return;
    }
    Iterator<FaultState> iter = faultStates.iterator();
    while (iter.hasNext()) {
        FaultState fs = iter.next();
        StringBuilder str = new StringBuilder("Alarm message received: <");
        str.append(fs.getFamily());
        str.append(",");
        str.append(fs.getMember());
        str.append(",");
        str.append(fs.getCode());
        str.append(">");
        str.append(" Status: ");
        str.append(fs.getDescriptor());
        System.out.println(str.toString());
    }
}
Also used : FaultState(cern.laser.source.alarmsysteminterface.FaultState) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 9 with ASIMessage

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

the class AlarmsDelayCoreAlarmTest method sendAlarm.

/**
	 * Send a alarm to the alarm NC bypassing the ACS API because we want to simulate a delay!
	 * 
	 * @param faultFamily
	 * @param faultMember
	 * @param code
	 * @param active
	 * @param timeStamp
	 * @throws Exception
	 */
private void sendAlarm(String faultFamily, String faultMember, int code, boolean active, long timeStamp) throws Exception {
    FaultState fs = new FaultStateImpl(faultFamily, faultMember, code);
    if (active) {
        fs.setDescriptor(FaultState.ACTIVE);
    } else {
        fs.setDescriptor(FaultState.TERMINATE);
    }
    Timestamp timestamp = new Timestamp(timeStamp);
    fs.setUserTimestamp(timestamp);
    Vector<FaultState> states = new Vector<FaultState>();
    states.add(fs);
    ASIMessage asiMessage = ASIMessageHelper.marshal(states);
    // Set the timestamp by adding a dealy greater then AlarmMessageProcessorImpl.delayThreashold
    String nowStr = IsoDateFormat.formatDate(new Date(timeStamp));
    asiMessage.setSourceTimestamp(nowStr);
    // Set a fake hostname
    asiMessage.setSourceHostname("alma");
    asiMessage.setSourceName("ALARM_SYSTEM_SOURCES");
    ACSJMSTextMessage textMessage = new ACSJMSTextMessage(contSvcs);
    textMessage.setText(XMLMessageHelper.marshal(asiMessage));
    // Finally send the alarm
    sourceNC.publishEvent(textMessage.getEntity());
}
Also used : FaultState(cern.laser.source.alarmsysteminterface.FaultState) LaserCoreFaultState(alma.alarmsystem.core.alarms.LaserCoreFaultState) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) FaultStateImpl(cern.laser.source.alarmsysteminterface.impl.FaultStateImpl) Timestamp(java.sql.Timestamp) Vector(java.util.Vector) Date(java.util.Date) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)

Example 10 with ASIMessage

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

the class LaserCoreFaultState method createJMSMessage.

/**
	 * Create an acs text jms message containing the passed
	 * fault state in form of XML (ASIMessage) in the body.
	 *  
	 * @param fs The <code>FaultState</code> to set in the message
	 * @param cs The <code>ContainerServicesBase</code>
	 * @return The jms text message containing the fault state
	 */
public static ACSJMSTextMessage createJMSMessage(FaultState fs, ContainerServicesBase cs) throws Exception {
    if (fs == null) {
        throw new IllegalArgumentException("The fault state can't be null");
    }
    if (cs == null) {
        throw new IllegalArgumentException("The container services can't be null");
    }
    Vector<FaultState> states = new Vector<FaultState>();
    states.add(fs);
    ASIMessage asiMessage = ASIMessageHelper.marshal(states);
    // Set the timestamp
    String sourceTimestamp = IsoDateFormat.formatCurrentDate();
    asiMessage.setSourceTimestamp(sourceTimestamp);
    // Set the hostname
    if (hostName == null) {
        InetAddress iAddr = InetAddress.getLocalHost();
        hostName = iAddr.getHostName();
    }
    asiMessage.setSourceHostname(hostName);
    asiMessage.setSourceName("ALARM_SYSTEM_SOURCES");
    ACSJMSTextMessage textMessage = new ACSJMSTextMessage(cs);
    textMessage.setText(XMLMessageHelper.marshal(asiMessage));
    return textMessage;
}
Also used : FaultState(cern.laser.source.alarmsysteminterface.FaultState) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) Vector(java.util.Vector) InetAddress(java.net.InetAddress) 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