Search in sources :

Example 1 with ACSJMSTextMessage

use of com.cosylab.acs.jms.ACSJMSTextMessage in project ACS by ACS-Community.

the class MessageTest method testTextMessage.

/**
	 * Test the ACSJMSTextMessage
	 * 
	 * @throws Exception
	 */
public void testTextMessage() throws Exception {
    ContainerServices cs = getContainerServices();
    assertNotNull("ContainerServices is null!", cs);
    ACSJMSTextMessage txtMsg = new ACSJMSTextMessage(cs);
    assertNotNull("Error building the ACSJMSTextMessage", txtMsg);
    String text = "The test of the message";
    txtMsg.setText(text);
    assertEquals("Wrong test returned by the message", text, txtMsg.getText());
}
Also used : ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) ContainerServices(alma.acs.container.ContainerServices)

Example 2 with ACSJMSTextMessage

use of com.cosylab.acs.jms.ACSJMSTextMessage in project ACS by ACS-Community.

the class PubSubTest method testTopicConnection.

public void testTopicConnection() throws Exception {
    TopicConnection topicConnection = factory.createTopicConnection();
    assertNotNull("Error creating the TopicConnection", topicConnection);
    TopicSession topicSession = topicConnection.createTopicSession(true, 0);
    assertNotNull("Error creating the TopicSession", topicSession);
    String chName = "TOPIC.TEST";
    Topic topic = topicSession.createTopic(chName);
    assertNotNull("Error creating Topic", topic);
    assertEquals("Wrong name for the topic", chName, topic.getTopicName());
    TopicPublisher publisher = topicSession.createPublisher(topic);
    assertNotNull("Error creating the TopicPublisher ", publisher);
    TopicSubscriber subscriber = topicSession.createSubscriber(topic);
    assertNotNull("Error creating the TopicSubscriber", subscriber);
    subscriber.setMessageListener(this);
    ACSJMSTextMessage msg = new ACSJMSTextMessage(getContainerServices());
    assertNotNull("Error creating ACSJMSTextMessage", msg);
    msg.setText(msgToSend);
    publisher.publish(msg);
    // Wait for awhile to have enough time to receive the message
    try {
        Thread.sleep(10000);
    } catch (Exception e) {
    }
    publisher.close();
    subscriber.close();
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) TopicPublisher(javax.jms.TopicPublisher) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) Topic(javax.jms.Topic) TopicConnection(javax.jms.TopicConnection)

Example 3 with ACSJMSTextMessage

use of com.cosylab.acs.jms.ACSJMSTextMessage 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 4 with ACSJMSTextMessage

use of com.cosylab.acs.jms.ACSJMSTextMessage 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 5 with ACSJMSTextMessage

use of com.cosylab.acs.jms.ACSJMSTextMessage 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)

Aggregations

ACSJMSTextMessage (com.cosylab.acs.jms.ACSJMSTextMessage)8 ASIMessage (cern.laser.source.alarmsysteminterface.impl.message.ASIMessage)4 FaultState (cern.laser.source.alarmsysteminterface.FaultState)3 FaultStateImpl (cern.laser.source.alarmsysteminterface.impl.FaultStateImpl)3 Vector (java.util.Vector)3 LaserCoreFaultState (alma.alarmsystem.core.alarms.LaserCoreFaultState)2 Timestamp (java.sql.Timestamp)2 JMSException (javax.jms.JMSException)2 ContainerServices (alma.acs.container.ContainerServices)1 DummyContainerServices (alma.acs.container.testsupport.DummyContainerServices)1 ACSFaultState (alma.alarmsystem.source.ACSFaultState)1 MOMException (cern.cmw.mom.pubsub.MOMException)1 LaserConnectionException (cern.laser.client.LaserConnectionException)1 LaserException (cern.laser.client.LaserException)1 LaserTimeOutException (cern.laser.client.LaserTimeOutException)1 AlarmImpl (cern.laser.client.impl.data.AlarmImpl)1 LaserSelectionException (cern.laser.client.services.selection.LaserSelectionException)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