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;
}
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));
}
}
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;
}
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;
}
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);
}
}
Aggregations