Search in sources :

Example 6 with FaultState

use of cern.laser.source.alarmsysteminterface.FaultState in project ACS by ACS-Community.

the class FaultStateHelper method unmarshal.

/**
   * Unmarshal a generated FaultState into a FaultState instance.
   * 
   * @param generated The generated FaultState
   * @return The FaultState instance
   */
public static FaultState unmarshal(cern.laser.source.alarmsysteminterface.impl.message.FaultState generated) {
    FaultState state = new FaultStateImpl();
    state.setFamily(generated.getFamily());
    state.setMember(generated.getMember());
    state.setCode(generated.getCode());
    state.setDescriptor(generated.getDescriptor());
    Date timestamp;
    try {
        timestamp = IsoDateFormat.parseIsoTimestamp(generated.getUserTimestamp());
        state.setUserTimestamp(new Timestamp(timestamp.getTime()));
    } catch (ParseException pe) {
        System.err.println("Error paring ISO timestamp from " + generated.getUserTimestamp());
        System.err.println("Setting to surrent time! " + generated.getUserTimestamp());
        pe.printStackTrace(System.err);
        state.setUserTimestamp(new Timestamp(System.currentTimeMillis()));
    }
    Properties properties = new Properties();
    if (generated.getUserProperties() != null) {
        Enumeration property_enum = generated.getUserProperties().enumerateProperty();
        while (property_enum.hasMoreElements()) {
            Property property = (Property) property_enum.nextElement();
            properties.setProperty(property.getName(), property.getValue());
        }
    }
    state.setUserProperties(properties);
    return state;
}
Also used : Enumeration(java.util.Enumeration) FaultState(cern.laser.source.alarmsysteminterface.FaultState) ParseException(java.text.ParseException) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) Property(cern.laser.source.alarmsysteminterface.impl.message.Property) Date(java.util.Date)

Example 7 with FaultState

use of cern.laser.source.alarmsysteminterface.FaultState in project ACS by ACS-Community.

the class MultiSourceStressTest method receive.

@Override
public synchronized void receive(ACSJMSMessageEntity msg, EventDescription eventDescrip) {
    ASIMessage asiMsg = null;
    try {
        asiMsg = XMLMessageHelper.unmarshal(msg.text);
    } catch (Exception ex) {
        // TODO: How to handle this XML parse/validation exception? In the old implementation using NC Consumer
        // the Consumer would have simply logged this exception. Should we take any action instead?
        m_logger.log(Level.INFO, "Failed to parse ASIMessage XML", ex);
    }
    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 8 with FaultState

use of cern.laser.source.alarmsysteminterface.FaultState in project ACS by ACS-Community.

the class LaserCoreFaultState method createFaultState.

/**
	 * Create a <code>FaultState</code> for a given fault code and a given
	 * set of user properties.
	 * 
	 * @param FC The fault code of the alarm
	 * @param props The user properties
	 * @param active <code>true</code> if the alarm is active
	 * @return The <code>FaultState</code> for the passed code
	 */
public static FaultState createFaultState(LaserCoreFaultCodes FC, Properties props, boolean active) {
    FaultState fs = createFaultState(FC, active);
    fs.setUserProperties(props);
    return fs;
}
Also used : FaultState(cern.laser.source.alarmsysteminterface.FaultState)

Example 9 with FaultState

use of cern.laser.source.alarmsysteminterface.FaultState 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 10 with FaultState

use of cern.laser.source.alarmsysteminterface.FaultState 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)

Aggregations

FaultState (cern.laser.source.alarmsysteminterface.FaultState)16 ASIMessage (cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)9 Timestamp (java.sql.Timestamp)6 ACSFaultState (alma.alarmsystem.source.ACSFaultState)3 FaultStateImpl (cern.laser.source.alarmsysteminterface.impl.FaultStateImpl)3 ACSJMSTextMessage (com.cosylab.acs.jms.ACSJMSTextMessage)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Alarm (cern.laser.business.data.Alarm)2 Source (cern.laser.business.data.Source)2 FaultStates (cern.laser.source.alarmsysteminterface.impl.message.FaultStates)2 Property (cern.laser.source.alarmsysteminterface.impl.message.Property)2 ParseException (java.text.ParseException)2 Enumeration (java.util.Enumeration)2 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 Vector (java.util.Vector)2 DummyContainerServices (alma.acs.container.testsupport.DummyContainerServices)1 LaserCoreFaultState (alma.alarmsystem.core.alarms.LaserCoreFaultState)1 LaserRuntimeException (cern.laser.business.LaserRuntimeException)1