Search in sources :

Example 26 with TextMessage

use of javax.jms.TextMessage in project ACS by ACS-Community.

the class AlarmPublisherImpl method sendInit.

public void sendInit(Collection alarms, String destination) {
    try {
        logger.log(AcsLogLevel.DEBUG, "sending " + alarms.size() + " initial alarm(s) to " + destination + "...");
        Topic topic = getTopicSession().createTopic(destination);
        TextMessage message = getTopicSession().createTextMessage();
        Iterator iterator = alarms.iterator();
        while (iterator.hasNext()) {
            AlarmImpl alarm = (AlarmImpl) iterator.next();
            message.setText(AlarmMessageConversion.getXML(alarm));
            message.clearProperties();
            setMessageProperties(message, alarm);
            message.setObjectProperty("NOT_REDUCED_MASKED_SET", Boolean.TRUE);
            if (!(alarm.getStatus().getMasked().booleanValue() || alarm.getStatus().getReduced().booleanValue())) {
                message.setObjectProperty("REDUCED_MASKED_SET", Boolean.TRUE);
            } else {
                message.setObjectProperty("REDUCED_MASKED_SET", Boolean.FALSE);
            }
            getTopicPublisher().publish(topic, message);
        }
        logger.log(AcsLogLevel.DEBUG, "initial alarm(s) sent to " + destination);
    } catch (Exception e) {
        close();
        throw new LaserRuntimeException("unable to send alarms to " + destination + " : " + e.getMessage());
    }
}
Also used : AlarmImpl(cern.laser.business.data.AlarmImpl) Iterator(java.util.Iterator) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) NamingException(javax.naming.NamingException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserCreateException(cern.laser.business.LaserCreateException) JMSException(javax.jms.JMSException) LaserRuntimeException(cern.laser.business.LaserRuntimeException)

Example 27 with TextMessage

use of javax.jms.TextMessage in project ACS by ACS-Community.

the class AlarmPublisherImpl method sendInit.

public void sendInit(AlarmImpl alarm, String destination) {
    try {
        Topic topic = getTopicSession().createTopic(destination);
        TextMessage message = getTopicSession().createTextMessage();
        message.setText(AlarmMessageConversion.getXML(alarm));
        setMessageProperties(message, alarm);
        message.setObjectProperty("NOT_REDUCED_MASKED_SET", Boolean.TRUE);
        if (!(alarm.getStatus().getMasked().booleanValue() || alarm.getStatus().getReduced().booleanValue())) {
            message.setObjectProperty("REDUCED_MASKED_SET", Boolean.TRUE);
        } else {
            message.setObjectProperty("REDUCED_MASKED_SET", Boolean.FALSE);
        }
        getTopicPublisher().publish(topic, message);
    } catch (Exception e) {
        logger.log(AcsLogLevel.ERROR, "unable to send alarm " + alarm.getAlarmId() + " to destination " + destination, e);
        close();
    //throw new EJBException("unable to send alarm " + alarm.getAlarmId() + " to destination " + destination, e);
    }
}
Also used : Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) NamingException(javax.naming.NamingException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserCreateException(cern.laser.business.LaserCreateException) JMSException(javax.jms.JMSException)

Example 28 with TextMessage

use of javax.jms.TextMessage in project ACS by ACS-Community.

the class AlarmMessageProcessorImpl method process.

public void process(Message alarmMessage) throws Exception {
    if (alarmMessage instanceof TextMessage) {
        TextMessage text_message = (TextMessage) alarmMessage;
    }
    logger.log(AcsLogLevel.DEBUG, "processing message...", true);
    if (alarmMessage instanceof TextMessage) {
        TextMessage text_message = (TextMessage) alarmMessage;
        String xml_message = text_message.getText();
        process(xml_message);
    } else {
        throw new Exception("TextMessage expected");
    }
    logger.log(AcsLogLevel.DEBUG, "message processed");
}
Also used : TextMessage(javax.jms.TextMessage) ParseException(java.text.ParseException) AlarmCacheException(cern.laser.business.cache.AlarmCacheException)

Example 29 with TextMessage

use of javax.jms.TextMessage 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)

Example 30 with TextMessage

use of javax.jms.TextMessage in project javaee7-samples by javaee-samples.

the class MessageReceiverAsync method onMessage.

@Override
public void onMessage(Message message) {
    try {
        TextMessage tm = (TextMessage) message;
        System.out.println("Message received (async): " + tm.getText());
    } catch (JMSException ex) {
        Logger.getLogger(MessageReceiverAsync.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage)

Aggregations

TextMessage (javax.jms.TextMessage)231 Test (org.junit.Test)92 Session (javax.jms.Session)75 MessageProducer (javax.jms.MessageProducer)71 Message (javax.jms.Message)70 JMSException (javax.jms.JMSException)64 Connection (javax.jms.Connection)44 Destination (javax.jms.Destination)44 MessageConsumer (javax.jms.MessageConsumer)44 ObjectMessage (javax.jms.ObjectMessage)25 BytesMessage (javax.jms.BytesMessage)22 Queue (javax.jms.Queue)21 QueueSession (javax.jms.QueueSession)20 StubTextMessage (org.springframework.jms.StubTextMessage)18 ConnectionFactory (javax.jms.ConnectionFactory)13 QueueConnection (javax.jms.QueueConnection)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 MapMessage (javax.jms.MapMessage)11 Topic (javax.jms.Topic)11 JMSContext (javax.jms.JMSContext)9