Search in sources :

Example 1 with MessageListener

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

the class LaserComponent method initialize.

public void initialize() {
    this.logger = corbaServer.getLogger();
    defaultTopicConnectionFactory = new ACSJMSTopicConnectionFactory(alSysContSvcs);
    TopicConnection tc;
    TopicSession ts = null;
    try {
        tc = defaultTopicConnectionFactory.createTopicConnection();
        ts = tc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topicAdminCacheLoader = new ACSJMSTopic("CMW.ALARM_SYSTEM.ADMIN_CACHE_LOADER");
        subscriberAdminCacheLoader = ts.createSubscriber(topicAdminCacheLoader);
        subscriberAdminCacheLoader.setMessageListener(new MessageListener() {

            public void onMessage(Message message) {
                if (message instanceof TextMessage) {
                    logger.log(AcsLogLevel.DEBUG, "Received a JMS message");
                } else {
                    logger.log(AcsLogLevel.WARNING, "Received a non text JMS message");
                }
                try {
                    alarmMessageProcessor.process(message);
                } catch (Throwable t) {
                    logger.log(AcsLogLevel.ERROR, "Exception processing a message: " + t.getMessage(), t);
                // There is nothing to do at this level: log the exception
                // and be ready to process the next message
                }
            }
        });
        logger.log(AcsLogLevel.DEBUG, "JMS initialized");
    } catch (Throwable t) {
        System.err.println("Error initing JMS, " + t.getMessage());
        t.printStackTrace(System.err);
        logger.log(AcsLogLevel.ERROR, "Error initializing JMS", t);
        coreAlarms.add(LaserCoreFaultCodes.JMS_INIT);
    }
    ConfigurationAccessor conf = null;
    try {
        conf = ConfigurationAccessorFactory.getInstance(alSysContSvcs);
    } catch (Throwable t) {
        System.err.println("Error getting CDB: " + t.getMessage());
        t.printStackTrace(System.err);
        logger.log(AcsLogLevel.WARNING, "Error getting CDB", t);
        coreAlarms.add(LaserCoreFaultCodes.CDB_UNAVAILABLE);
    }
    adminUserDAO = new ACSAdminUserDAOImpl();
    alarmDAO = new ACSAlarmDAOImpl(logger);
    alarmDAO.setConfAccessor(conf);
    categoryDAO = new ACSCategoryDAOImpl(logger, alarmDAO);
    categoryDAO.setConfAccessor(conf);
    responsiblePersonDAO = new ACSResponsiblePersonDAOImpl();
    try {
        alarmDAO.loadAlarms();
    } catch (Throwable t) {
        System.err.println("Error loading alarms: " + t.getMessage());
        t.printStackTrace(System.err);
        logger.log(AcsLogLevel.CRITICAL, "Error loading alarms from CDB", t);
        coreAlarms.add(LaserCoreFaultCodes.ALARMS_CDB);
    }
    try {
        categoryDAO.loadCategories();
    } catch (Throwable t) {
        System.err.println("Error loading categories: " + t.getMessage());
        t.printStackTrace(System.err);
        logger.log(AcsLogLevel.CRITICAL, "Error loading categories from CDB", t);
        coreAlarms.add(LaserCoreFaultCodes.CATEGORIES_CDB);
    }
    sourceDAO = new ACSSourceDAOImpl(logger, alarmDAO.getSources());
    sourceDAO.setConfAccessor(conf);
    sourceDAO.setLaserSourceId("LASER");
    sourceDAO.setAlarmDAO(alarmDAO);
    sourceDAO.setResponsiblePersonDAO(responsiblePersonDAO);
    adminUserDefinitionService = new AdminUserDefinitionServiceImpl();
    alarmCacheServer = new AlarmCacheServerImpl(logger);
    alarmDefinitionService = new AlarmDefinitionServiceImpl();
    sourcesListener = new AlarmSourcesListenerCached(alSysContSvcs, logger, this);
    statisticsCalculator = new StatsCalculator(this.logger, sourcesListener);
    alarmMessageProcessor = new AlarmMessageProcessorImpl(this, logger, statisticsCalculator);
    alarmPublisher = new AlarmPublisherImpl(logger);
    alarmSourceMonitor = new AlarmSourceMonitorImpl();
    categoryDefinitionService = new CategoryDefinitionServiceImpl();
    coreService = new CoreServiceImpl();
    heartbeat = new HeartbeatImpl();
    mailAndSmsServer = new ACSMailAndSmsServer(logger);
    sourceDefinitionService = new SourceDefinitionServiceImpl();
    alarmCacheListener = new AlarmCacheListenerImpl(alarmCacheServer);
    alarmCache = new ACSAlarmCacheImpl(alarmDAO, categoryDAO, alarmCacheListener, logger);
    statisticsCalculator.start();
    alarmDAO.setSurveillanceAlarmId("SURVEILLANCE:SOURCE:1");
    alarmDAO.setResponsiblePersonDAO(responsiblePersonDAO);
    //		categoryDAO.setCategoryTreeRoot("ACS");
    categoryDAO.setCategoryTreeRoot("ROOT");
    categoryDAO.setSurveillanceCategoryPath("ACS.SURVEILLANCE");
    responsiblePersonDAO.setAlarmDAO(alarmDAO);
    adminUserDefinitionService.setCategoryDAO(categoryDAO);
    adminUserDefinitionService.setAdminUserDAO(adminUserDAO);
    alarmCacheServer.setAlarmDAO(alarmDAO);
    alarmCacheServer.setAlarmPublisher(alarmPublisher);
    alarmCacheServer.setMailAndSmsServer(mailAndSmsServer);
    alarmDefinitionService.setAlarmCache(alarmCache);
    alarmDefinitionService.setAdminUserDAO(adminUserDAO);
    alarmDefinitionService.setAlarmDAO(alarmDAO);
    alarmDefinitionService.setCategoryDAO(categoryDAO);
    alarmDefinitionService.setResponsiblePersonDAO(responsiblePersonDAO);
    alarmDefinitionService.setSourceDAO(sourceDAO);
    alarmDefinitionService.setAlarmMessageProcessor(alarmMessageProcessor);
    alarmDefinitionService.setAlarmPublisher(alarmPublisher);
    alarmMessageProcessor.setAlarmCache(alarmCache);
    alarmMessageProcessor.setSourceDAO(sourceDAO);
    alarmPublisher.setTopicConnectionFactory(defaultTopicConnectionFactory);
    alarmPublisher.setCategoryRootTopic("CMW.ALARM_SYSTEM.CATEGORIES");
    alarmSourceMonitor.setSourceDAO(sourceDAO);
    alarmSourceMonitor.setAlarmMessageProcessor(alarmMessageProcessor);
    alarmSourceMonitor.setSourceMonitorFrequency(60000);
    categoryDefinitionService.setAlarmCache(alarmCache);
    categoryDefinitionService.setAdminUserDAO(adminUserDAO);
    categoryDefinitionService.setAlarmDAO(alarmDAO);
    categoryDefinitionService.setCategoryDAO(categoryDAO);
    coreService.setAlarmCache(alarmCache);
    coreService.setResponsiblePersonDAO(responsiblePersonDAO);
    coreService.setSourceDAO(sourceDAO);
    coreService.setAlarmDAO(alarmDAO);
    coreService.setCategoryDAO(categoryDAO);
    coreService.setAlarmPublisher(alarmPublisher);
    // coreService.setDataSource(defaultDataSource);
    coreService.setClientRootTopic("CMW.ALARM_SYSTEM.CLIENTS");
    coreService.setRootCategoryPK(2064926);
    coreService.setHeartbeatTopic("CMW.ALARM_SYSTEM.HEARTBEAT");
    coreService.setHeartbeatFrequency(60000);
    coreService.setSearchRootTopic("CMW.ALARM_SYSTEM.SEARCH");
    heartbeat.setCoreService(coreService);
    heartbeat.setTopicConnectionFactory(defaultTopicConnectionFactory);
    sourceDefinitionService.setAlarmCache(alarmCache);
    sourceDefinitionService.setAdminUserDAO(adminUserDAO);
    sourceDefinitionService.setAlarmDAO(alarmDAO);
    sourceDefinitionService.setCategoryDAO(categoryDAO);
    sourceDefinitionService.setResponsiblePersonDAO(responsiblePersonDAO);
    sourceDefinitionService.setSourceDAO(sourceDAO);
    sourceDefinitionService.setAlarmDefinitionService(alarmDefinitionService);
    alarmDAO.setAlarmProcessor(alarmMessageProcessor);
    // Subscribe the source listener to all the source NCs
    try {
        sourcesListener.connectSources(sourceDAO.getAllSourceIDs());
        logger.log(AcsLogLevel.DEBUG, "Successfully connected to sources NCs");
    } catch (Throwable t) {
        System.err.println("Error setting source listener: " + t.getMessage());
        t.printStackTrace(System.err);
        logger.log(AcsLogLevel.WARNING, "Error setting the source listener", t);
        coreAlarms.add(LaserCoreFaultCodes.SOURCE_LISTENER);
    }
    sourcesListener.start();
}
Also used : AlarmPublisherImpl(cern.laser.business.pojo.AlarmPublisherImpl) TopicSession(javax.jms.TopicSession) ASIMessage(cern.laser.source.alarmsysteminterface.impl.message.ASIMessage) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageListener(javax.jms.MessageListener) AlarmCacheServerImpl(cern.laser.business.pojo.AlarmCacheServerImpl) ACSCategoryDAOImpl(com.cosylab.acs.laser.dao.ACSCategoryDAOImpl) CoreServiceImpl(cern.laser.business.pojo.CoreServiceImpl) ACSAdminUserDAOImpl(com.cosylab.acs.laser.dao.ACSAdminUserDAOImpl) ACSJMSTopicConnectionFactory(com.cosylab.acs.jms.ACSJMSTopicConnectionFactory) ACSJMSTopic(com.cosylab.acs.jms.ACSJMSTopic) StatsCalculator(alma.alarmsystem.statistics.StatsCalculator) AlarmCacheListenerImpl(cern.laser.business.cache.AlarmCacheListenerImpl) CategoryDefinitionServiceImpl(cern.laser.business.pojo.CategoryDefinitionServiceImpl) Topic(javax.jms.Topic) ACSJMSTopic(com.cosylab.acs.jms.ACSJMSTopic) AlarmDefinitionServiceImpl(cern.laser.business.pojo.AlarmDefinitionServiceImpl) ACSAlarmDAOImpl(com.cosylab.acs.laser.dao.ACSAlarmDAOImpl) SourceDefinitionServiceImpl(cern.laser.business.pojo.SourceDefinitionServiceImpl) ACSAlarmCacheImpl(com.cosylab.acs.laser.dao.ACSAlarmCacheImpl) AdminUserDefinitionServiceImpl(cern.laser.business.pojo.AdminUserDefinitionServiceImpl) TopicConnection(javax.jms.TopicConnection) AlarmMessageProcessorImpl(cern.laser.business.pojo.AlarmMessageProcessorImpl) ConfigurationAccessor(com.cosylab.acs.laser.dao.ConfigurationAccessor) ACSSourceDAOImpl(com.cosylab.acs.laser.dao.ACSSourceDAOImpl) ACSMailAndSmsServer(alma.alarmsystem.core.mail.ACSMailAndSmsServer) AlarmSourceMonitorImpl(cern.laser.business.pojo.AlarmSourceMonitorImpl) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) TextMessage(javax.jms.TextMessage) HeartbeatImpl(cern.laser.business.pojo.HeartbeatImpl) ACSResponsiblePersonDAOImpl(com.cosylab.acs.laser.dao.ACSResponsiblePersonDAOImpl)

Example 2 with MessageListener

use of javax.jms.MessageListener in project camel by apache.

the class SjmsConsumer method createConsumer.

/**
     * Creates a {@link MessageConsumerResources} with a dedicated
     * {@link Session} required for transacted and InOut consumers.
     */
private MessageConsumerResources createConsumer() throws Exception {
    MessageConsumerResources answer;
    ConnectionResource connectionResource = getOrCreateConnectionResource();
    Connection conn = connectionResource.borrowConnection();
    try {
        Session session = conn.createSession(isTransacted(), isTransacted() ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE);
        MessageConsumer messageConsumer = getEndpoint().getJmsObjectFactory().createMessageConsumer(session, getEndpoint());
        MessageListener handler = createMessageHandler(session);
        messageConsumer.setMessageListener(handler);
        answer = new MessageConsumerResources(session, messageConsumer);
    } catch (Exception e) {
        log.error("Unable to create the MessageConsumer", e);
        throw e;
    } finally {
        connectionResource.returnConnection(conn);
    }
    return answer;
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ConnectionResource(org.apache.camel.component.sjms.jms.ConnectionResource) Connection(javax.jms.Connection) MessageListener(javax.jms.MessageListener) Session(javax.jms.Session)

Example 3 with MessageListener

use of javax.jms.MessageListener in project qpid-broker-j by apache.

the class ConsumerParticipant method startTest.

@Override
public void startTest(String registeredClientName, ResultReporter resultReporter) throws Exception {
    final int acknowledgeMode = _jmsDelegate.getAcknowledgeMode(_command.getSessionName());
    final String providerVersion = _jmsDelegate.getProviderVersion(_command.getSessionName());
    final String protocolVersion = _jmsDelegate.getProtocolVersion(_command.getSessionName());
    if (_command.isSynchronous()) {
        synchronousRun();
    } else {
        LOGGER.debug("Consumer {} registering listener", getName());
        _jmsDelegate.registerListener(_command.getParticipantName(), new MessageListener() {

            @Override
            public void onMessage(Message message) {
                processAsyncMessage(message);
            }
        });
        waitUntilMsgListenerHasFinished();
        rethrowAnyAsyncMessageListenerException();
    }
    Date end = new Date();
    final Date start = new Date(_startTime);
    int numberOfMessagesReceived = _totalNumberOfMessagesReceived.get();
    long totalPayloadSize = _totalPayloadSizeOfAllMessagesReceived.get();
    int payloadSize = getPayloadSizeForResultIfConstantOrZeroOtherwise(_allConsumedPayloadSizes);
    LOGGER.info("Consumer {} finished consuming. Number of messages consumed: {}", getName(), numberOfMessagesReceived);
    ParticipantResult result = _resultFactory.createForConsumer(getName(), registeredClientName, _command, acknowledgeMode, numberOfMessagesReceived, payloadSize, totalPayloadSize, start, end, _messageLatencies, providerVersion, protocolVersion);
    resultReporter.reportResult(result);
}
Also used : ParticipantResult(org.apache.qpid.disttest.message.ParticipantResult) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) Date(java.util.Date)

Example 4 with MessageListener

use of javax.jms.MessageListener in project qpid-broker-j by apache.

the class ControllerJmsDelegate method start.

public void start() {
    try {
        createControllerQueue();
        final MessageConsumer consumer = _controllerQueueListenerSession.createConsumer(_controllerQueue);
        consumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(final Message message) {
                try {
                    String jmsMessageID = message.getJMSMessageID();
                    LOGGER.debug("Received message ID {}", jmsMessageID);
                    final Command command = JmsMessageAdaptor.messageToCommand(message);
                    LOGGER.debug("Converted message ID {} into command {}", jmsMessageID, command);
                    processCommandWithFirstSupportingListener(command);
                    LOGGER.debug("Finished processing command for message ID", jmsMessageID);
                } catch (Exception t) {
                    LOGGER.error("Can't handle JMS message", t);
                }
            }
        });
    } catch (final JMSException e) {
        throw new DistributedTestException(e);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Message(javax.jms.Message) Command(org.apache.qpid.disttest.message.Command) RegisterClientCommand(org.apache.qpid.disttest.message.RegisterClientCommand) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) DistributedTestException(org.apache.qpid.disttest.DistributedTestException)

Example 5 with MessageListener

use of javax.jms.MessageListener in project wso2-axis2-transports by wso2.

the class MockEchoEndpoint method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception {
    Destination destination = channel.getDestination();
    Destination replyDestination = channel.getReplyDestination();
    connection = env.getConnectionFactory().createConnection();
    connection.setExceptionListener(this);
    connection.start();
    replyConnection = env.getConnectionFactory().createConnection();
    replyConnection.setExceptionListener(this);
    final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final MessageProducer producer = replySession.createProducer(replyDestination);
    MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(destination);
    consumer.setMessageListener(new MessageListener() {

        public void onMessage(Message message) {
            try {
                log.info("Message received: ID = " + message.getJMSMessageID());
                Message reply;
                if (message instanceof BytesMessage) {
                    reply = replySession.createBytesMessage();
                    IOUtils.copy(new BytesMessageInputStream((BytesMessage) message), new BytesMessageOutputStream((BytesMessage) reply));
                } else if (message instanceof TextMessage) {
                    reply = replySession.createTextMessage();
                    ((TextMessage) reply).setText(((TextMessage) message).getText());
                } else {
                    // TODO
                    throw new UnsupportedOperationException("Unsupported message type");
                }
                reply.setJMSCorrelationID(message.getJMSMessageID());
                reply.setStringProperty(BaseConstants.CONTENT_TYPE, message.getStringProperty(BaseConstants.CONTENT_TYPE));
                producer.send(reply);
                log.info("Message sent: ID = " + reply.getJMSMessageID());
            } catch (Throwable ex) {
                fireEndpointError(ex);
            }
        }
    });
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) BytesMessage(javax.jms.BytesMessage) BytesMessageOutputStream(org.apache.axis2.transport.jms.iowrappers.BytesMessageOutputStream) MessageProducer(javax.jms.MessageProducer) BytesMessageInputStream(org.apache.axis2.transport.jms.iowrappers.BytesMessageInputStream) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Aggregations

MessageListener (javax.jms.MessageListener)146 Message (javax.jms.Message)128 MessageConsumer (javax.jms.MessageConsumer)103 Session (javax.jms.Session)97 TextMessage (javax.jms.TextMessage)95 CountDownLatch (java.util.concurrent.CountDownLatch)72 Test (org.junit.Test)71 Connection (javax.jms.Connection)60 MessageProducer (javax.jms.MessageProducer)58 JMSException (javax.jms.JMSException)57 Destination (javax.jms.Destination)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)31 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)26 BytesMessage (javax.jms.BytesMessage)22 Queue (javax.jms.Queue)21 ConnectionFactory (javax.jms.ConnectionFactory)16 ScheduledMessage (org.apache.activemq.ScheduledMessage)15 ArrayList (java.util.ArrayList)14 Topic (javax.jms.Topic)13 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)13