Search in sources :

Example 1 with JMSException

use of javax.jms.JMSException in project opennms by OpenNMS.

the class CollectionJobListener method onMessage.

@Override
public void onMessage(Message message) {
    try {
        // FIXME abstraction between technology and job handling is missing
        CollectionJob collectionJob = (CollectionJob) simpleMessageConverter.fromMessage(message);
        collectionJob = protocolCollectorRegistry.getProtocolCollector(collectionJob.getService()).collect(collectionJob);
        Date finishedTimestamp = new Date();
        collectionJob.setFinishedTimestamp(finishedTimestamp);
        Map<String, MeasurementSet> measurementSets = collectionJob.getMeasurementSetsByDestination();
        int val = counter.incrementAndGet();
        if (val % 1000 == 0) {
            logger.debug("processed job #{}, {} measurement set(s)", val, measurementSets.size());
        } else {
            logger.trace("processed job #{}, {} measurement set(s)", val, measurementSets.size());
        }
        for (String destinationString : measurementSets.keySet()) {
            jmsTemplate.convertAndSend(destinationString, measurementSets.get(destinationString));
            logger.info("** sending msg '{}' to '{}'", measurementSets.get(destinationString), destinationString);
        }
        LightweightMeasurementSet errorMeasurementSet = new LightweightMeasurementSet(collectionJob.getNodeId(), collectionJob.getService(), collectionJob.getNetInterface(), collectionJob.getFinishedTimestamp());
        for (String metricId : collectionJob.getAllMetrics()) {
            if (collectionJob.getMetricValue(metricId) == null) {
                errorMeasurementSet.addMeasurement(metricId, collectionJob.getMetricType(metricId), null, collectionJob.getOnmsLogicMetricId(metricId));
            }
            logger.trace("collected metric of job #{}='{}'", counter + ": " + metricId, collectionJob.getMetricValue(metricId));
        }
        if (errorMeasurementSet.getMeasurements().size() > 0) {
            logger.warn("result set of job #{} contains {} null values", counter, errorMeasurementSet.getMeasurements().size());
            jmsTemplate.convertAndSend("error", errorMeasurementSet);
            logger.trace("** sending to 'error'");
        }
    } catch (JMSException ex) {
        logger.error(ex.getMessage());
    // FIXME react, don't continue
    } catch (MessageConversionException ex) {
        logger.error(ex.getMessage());
    // FIXME react, don't continue
    }
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) CollectionJob(org.opennms.nrtg.api.model.CollectionJob) JMSException(javax.jms.JMSException) Date(java.util.Date) MeasurementSet(org.opennms.nrtg.api.model.MeasurementSet) LightweightMeasurementSet(org.opennms.nrtg.api.model.LightweightMeasurementSet) LightweightMeasurementSet(org.opennms.nrtg.api.model.LightweightMeasurementSet)

Example 2 with JMSException

use of javax.jms.JMSException in project opennms by OpenNMS.

the class JmsNorthbounder method forwardAlarms.

/* (non-Javadoc)
     * @see org.opennms.netmgt.alarmd.api.support.AbstractNorthbounder#forwardAlarms(java.util.List)
     */
@Override
public void forwardAlarms(List<NorthboundAlarm> alarms) throws NorthbounderException {
    for (final NorthboundAlarm alarm : alarms) {
        final Integer count = alarm.getCount();
        LOG.debug("Does destination {} take only first occurances? {} Is new alarm? Has count of {}.", m_jmsDestination.getName(), m_jmsDestination.isFirstOccurrenceOnly(), count);
        if (count > 1 && m_jmsDestination.isFirstOccurrenceOnly()) {
            LOG.debug("Skipping because not new alarm.");
            continue;
        }
        LOG.debug("Attempting to send a message to {} of type {}", m_jmsDestination.getJmsDestination(), m_jmsDestination.getDestinationType());
        try {
            m_template.send(m_jmsDestination.getJmsDestination(), new MessageCreator() {

                @Override
                public Message createMessage(Session session) throws JMSException {
                    if (m_jmsDestination.isSendAsObjectMessageEnabled()) {
                        return session.createObjectMessage(alarm);
                    } else {
                        return session.createTextMessage(convertAlarmToText(alarm));
                    }
                }
            });
            LOG.debug("Sent message");
        } catch (JmsException e) {
            LOG.error("Unable to send alarm to northbound JMS because {}", e.getLocalizedMessage(), e);
        }
    }
}
Also used : Message(javax.jms.Message) JmsException(org.springframework.jms.JmsException) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 3 with JMSException

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

the class AlarmSelectionHelper method subscribe.

//
// -- PUBLIC METHODS ----------------------------------------------
//
public Map subscribe(Selection selection) throws LaserConnectionException, LaserException, LaserTimeOutException {
    String sql_filter = buildSQLFilter(selection);
    Collection category_ids = setupCategorySubscriptions(selection, sql_filter);
    // start init subscription
    setInitialized(false);
    String console_id = "";
    String host_name = "";
    try {
        console_id = UUIDGenerator.getInstance().getUUID().toString();
        host_name = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        throw new LaserException("unable to get a unique id for the console", e);
    }
    String init_topic = getClientRootTopic() + "." + console_id;
    String init_sql_filter = buildInitSQLFilter(sql_filter);
    long init_subscription;
    try {
        init_subscription = getSubscriber().subscribe(init_topic, getInitialSelectionListener(), init_sql_filter);
    } catch (Exception e) {
        LOGGER.error("unable to subscribe to topic " + init_topic, e);
        throw new LaserException("unable to subscribe to topic " + init_topic, e);
    }
    try {
        if (m_laser != null) {
            int[] cis = new int[category_ids.size()];
            int pos = 0;
            for (Iterator iter = category_ids.iterator(); iter.hasNext(); ) {
                cis[pos++] = ((Integer) iter.next()).intValue();
            }
            m_laser.select(cis, console_id);
        } else {
            throw new NullPointerException("AlarmSystem component is null");
        }
    } catch (alma.alarmsystem.LaserProcessingException lpe) {
        try {
            getSubscriber().unSubscribe(init_subscription);
        } catch (JMSException e1) {
        // Intentionally left blank
        } catch (LaserException e1) {
        // Intentionally left blank
        }
        LOGGER.error("server is initializing");
        throw new LaserConnectionException("server is initializing", lpe);
    } catch (Exception e3) {
        throw new LaserException("unable to perform initial selection at host " + host_name, e3);
    }
    resetInitWaitTime();
    waitForInit();
    try {
        // stop init subscription
        getSubscriber().unSubscribe(init_subscription);
    } catch (Exception e) {
        LOGGER.info("exception when unsubscribing", e);
    }
    if (isInitialized()) {
        return getInitialSelection();
    } else {
    //throw new LaserTimeOutException("initial selection timed out");
    }
    return getInitialSelection();
}
Also used : UnknownHostException(java.net.UnknownHostException) JMSException(javax.jms.JMSException) LaserConnectionException(cern.laser.client.LaserConnectionException) LaserConnectionException(cern.laser.client.LaserConnectionException) LaserException(cern.laser.client.LaserException) UnknownHostException(java.net.UnknownHostException) JMSException(javax.jms.JMSException) MOMException(cern.cmw.mom.pubsub.MOMException) LaserSelectionException(cern.laser.client.services.selection.LaserSelectionException) LaserTimeOutException(cern.laser.client.LaserTimeOutException) Iterator(java.util.Iterator) Collection(java.util.Collection) LaserException(cern.laser.client.LaserException)

Example 4 with JMSException

use of javax.jms.JMSException in project perun by CESNET.

the class TaskStatusManagerImpl method onTaskDestinationError.

@Override
public void onTaskDestinationError(Task task, Destination destination, TaskResult result) {
    if (result != null) {
        try {
            jmsQueueManager.reportFinishedDestination(task, destination, result);
        } catch (JMSException e) {
            log.error("Failed to report finished task " + task.toString() + ": " + e.getMessage());
        }
    }
    if (task.getExecService().getExecServiceType().equals(ExecServiceType.GENERATE)) {
        task.setEndTime(new Date(System.currentTimeMillis()));
        schedulingPool.setTaskStatus(task, cz.metacentrum.perun.taskslib.model.Task.TaskStatus.ERROR);
    } else {
        TaskStatus taskStatus = this.getTaskStatus(task);
        try {
            taskStatus.setDestinationStatus(destination, TaskDestinationStatus.ERROR);
            taskStatus.setDestinationResult(destination, result);
        } catch (InternalErrorException e) {
            log.error("Error setting ERROR status for task " + task.toString() + ": " + e.getMessage());
        }
        if (taskStatus.isTaskFinished()) {
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, taskStatus.getTaskStatus());
        }
    }
}
Also used : JMSException(javax.jms.JMSException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) TaskStatus(cz.metacentrum.perun.engine.scheduling.TaskStatus) Date(java.util.Date)

Example 5 with JMSException

use of javax.jms.JMSException in project perun by CESNET.

the class DispatcherQueue method sendMessage.

/**
	 * Send message This method does not block. It is going to be executed
	 * asynchronously.
	 * 
	 * @param text
	 */
@Async
public void sendMessage(String text) {
    try {
        // Step 7. Create a Text Message
        TextMessage message = session.createTextMessage("task|" + clientID + "|" + text);
        // Step 8. Send...
        producer.send(message);
        if (log.isDebugEnabled()) {
            log.debug("Sent message (queue:" + queueName + "): " + message.getText());
        }
    } catch (JMSException e) {
        log.error(e.toString(), e);
    } catch (Exception e) {
        log.error(e.toString(), e);
    // TODO:Restart connection...?
    }
}
Also used : JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException) Async(org.springframework.scheduling.annotation.Async)

Aggregations

JMSException (javax.jms.JMSException)1090 Message (javax.jms.Message)355 Test (org.junit.Test)333 Session (javax.jms.Session)309 TextMessage (javax.jms.TextMessage)301 Connection (javax.jms.Connection)271 MessageProducer (javax.jms.MessageProducer)169 MessageConsumer (javax.jms.MessageConsumer)156 Destination (javax.jms.Destination)105 ObjectMessage (javax.jms.ObjectMessage)100 Queue (javax.jms.Queue)100 MapMessage (javax.jms.MapMessage)70 ConnectionFactory (javax.jms.ConnectionFactory)68 CountDownLatch (java.util.concurrent.CountDownLatch)64 IOException (java.io.IOException)62 BytesMessage (javax.jms.BytesMessage)59 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)53 MessageListener (javax.jms.MessageListener)49 NamingException (javax.naming.NamingException)44 MessageFormatException (javax.jms.MessageFormatException)43