use of org.motechproject.commons.api.MotechException in project motech by motech.
the class MBeanService method getQueueMessages.
/**
* Retrieves a list of messages for the given JMS queue.
*
* @param queueName The name of the queue for which messages should be retrieved.
* @return {@link List} of messages for the given queue.
*/
@PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ)
public List<QueueMessage> getQueueMessages(String queueName) {
try {
ArrayList<QueueMessage> queueMessages = new ArrayList<>();
QueueViewMBean queueViewMBean = mBeanServer.getQueueViewMBean(queueName);
for (CompositeData compositeData : queueViewMBean.browse()) {
if (compositeData != null) {
String messageId = (String) compositeData.get(JMS_MESSAGE_ID);
Boolean redelivered = (Boolean) compositeData.get(JMS_REDELIVERED);
Date timestamp = (Date) compositeData.get(JMS_TIMESTAMP);
queueMessages.add(new QueueMessage(messageId, redelivered, DateUtil.newDateTime(timestamp)));
}
}
return queueMessages;
} catch (OpenDataException openDataException) {
throw new MotechException(String.format("Could not Browse MBean for queue %s", queueName), openDataException);
} catch (IOException ioException) {
throw new MotechException(String.format("Could not access MBean for queue %s", queueName), ioException);
}
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class MBeanService method getTopicStatistics.
/**
* Returns topic statistics for the JMS topics.
*
* @return {@link List} of {@link TopicMBean}. One for each topic.
*/
@PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ)
public List<TopicMBean> getTopicStatistics() {
try {
List<TopicMBean> topics = new ArrayList<>();
for (ObjectName name : mBeanServer.getTopics()) {
String destination = name.getKeyProperty(mBeanServer.getDestinationProperty());
TopicViewMBean topicView = mBeanServer.getTopicViewMBean(name);
TopicMBean topic = new TopicMBean(destination);
topic.setEnqueueCount(topicView.getEnqueueCount());
topic.setDequeueCount(topicView.getDequeueCount());
topic.setExpiredCount(topicView.getExpiredCount());
topic.setConsumerCount(topicView.getConsumerCount());
topics.add(topic);
}
return topics;
} catch (IOException ex) {
throw new MotechException("Could not access MBeans ", ex);
}
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class MBeanService method getQueueStatistics.
/**
* Returns queue statistics for the JMS queues.
*
* @return {@link List} of {@link QueueMBean}. One for each queue belonging.
*/
@PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ)
public List<QueueMBean> getQueueStatistics() {
try {
List<QueueMBean> queues = new ArrayList<>();
for (ObjectName name : mBeanServer.getQueues()) {
String destination = name.getKeyProperty(mBeanServer.getDestinationProperty());
QueueViewMBean queueView = mBeanServer.getQueueViewMBean(name);
QueueMBean queue = new QueueMBean(destination);
queue.setEnqueueCount(queueView.getEnqueueCount());
queue.setDequeueCount(queueView.getDequeueCount());
queue.setExpiredCount(queueView.getExpiredCount());
queue.setConsumerCount(queueView.getConsumerCount());
queue.setQueueSize(queueView.getQueueSize());
queues.add(queue);
}
return queues;
} catch (IOException ex) {
throw new MotechException("Could not access MBeans ", ex);
}
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class SettingsServiceImpl method loadMultipartFileIntoProperties.
private Properties loadMultipartFileIntoProperties(MultipartFile configFile) {
if (configFile == null) {
throw new IllegalArgumentException("Config file cannot be null");
}
InputStream is = null;
Properties settings = new Properties();
try {
is = configFile.getInputStream();
settings.load(is);
} catch (IOException e) {
throw new MotechException("Error saving config file", e);
} finally {
IOUtils.closeQuietly(is);
}
return settings;
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class SettingsServiceImpl method saveRawFile.
@Override
public void saveRawFile(MultipartFile file, String filename, long bundleId) {
InputStream is = null;
try {
is = file.getInputStream();
configurationService.saveRawConfig(getBundleSymbolicName(bundleId), getVersion(bundleId), filename, is);
} catch (IOException e) {
throw new MotechException("Error reading uploaded file", e);
} finally {
IOUtils.closeQuietly(is);
}
}
Aggregations