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
}
}
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);
}
}
}
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();
}
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());
}
}
}
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...?
}
}
Aggregations