Search in sources :

Example 6 with Topic

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

the class AlarmPublisherImpl method sendInitFinished.

public void sendInitFinished(String destination) {
    try {
        logger.log(AcsLogLevel.DEBUG, "sending init finished message to " + destination + "...");
        Topic topic = getTopicSession().createTopic(destination);
        Message message = getTopicSession().createMessage();
        message.setObjectProperty(LASER_INIT_PROPERTY, Boolean.TRUE);
        getTopicPublisher().publish(topic, message);
        logger.log(AcsLogLevel.DEBUG, "init finished message sent to " + destination);
    } catch (Exception e) {
        close();
    }
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Topic(javax.jms.Topic) NamingException(javax.naming.NamingException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserCreateException(cern.laser.business.LaserCreateException) JMSException(javax.jms.JMSException)

Example 7 with Topic

use of javax.jms.Topic 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 8 with Topic

use of javax.jms.Topic 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 9 with Topic

use of javax.jms.Topic 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 10 with Topic

use of javax.jms.Topic in project ats-framework by Axway.

the class JmsClient method createTopic.

/**
     * Create a topic
     * 
     * @param topicName the topic name
     */
@PublicAtsApi
public void createTopic(final String topicName) {
    try {
        final Session session = loadSession(false, Session.AUTO_ACKNOWLEDGE);
        final Topic topic = session.createTopic(topicName);
        session.createConsumer(topic).close();
    } catch (JMSException e) {
        throw new JmsMessageException("Could not start listening for messages on topic " + topicName, e);
    } finally {
        releaseSession(false);
    }
}
Also used : JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) JMSException(javax.jms.JMSException) Topic(javax.jms.Topic) Session(javax.jms.Session) ManagedSession(com.axway.ats.action.jms.model.sessions.ManagedSession) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

Topic (javax.jms.Topic)59 Session (javax.jms.Session)36 MessageProducer (javax.jms.MessageProducer)31 JMSException (javax.jms.JMSException)14 NamingException (javax.naming.NamingException)14 TextMessage (javax.jms.TextMessage)9 LaserCreateException (cern.laser.business.LaserCreateException)6 LaserRuntimeException (cern.laser.business.LaserRuntimeException)6 Message (javax.jms.Message)6 Test (org.junit.Test)6 TopicSession (javax.jms.TopicSession)5 AlarmImpl (cern.laser.business.data.AlarmImpl)2 JmsMessageException (com.axway.ats.action.exceptions.JmsMessageException)2 ManagedSession (com.axway.ats.action.jms.model.sessions.ManagedSession)2 PublicAtsApi (com.axway.ats.common.PublicAtsApi)2 ACSJMSTextMessage (com.cosylab.acs.jms.ACSJMSTextMessage)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageListener (javax.jms.MessageListener)2