use of org.apache.activemq.broker.jmx.QueueViewMBean in project fabric8 by jboss-fuse.
the class RemoteBrokerFacadeSupport method purgeQueue.
public void purgeQueue(ActiveMQDestination destination) throws Exception {
QueueViewMBean queue = getQueue(destination.getPhysicalName());
queue.purge();
}
use of org.apache.activemq.broker.jmx.QueueViewMBean 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.apache.activemq.broker.jmx.QueueViewMBean 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.apache.activemq.broker.jmx.QueueViewMBean in project motech by motech.
the class MBeanServiceTest method shouldReturnQueues.
@Test
public void shouldReturnQueues() throws IOException {
ObjectName fooQueue = mock(ObjectName.class);
ObjectName[] queues = { fooQueue };
QueueViewMBean queueViewMBean = mock(QueueViewMBean.class);
given(mBeanServer.getQueueViewMBean(any(ObjectName.class))).willReturn(queueViewMBean);
given(mBeanServer.getQueues()).willReturn(queues);
given(fooQueue.getKeyProperty(mBeanServer.getDestinationProperty())).willReturn("foo_queue");
List<QueueMBean> queueStatistics = mBeanService.getQueueStatistics();
assertThat(queueStatistics.size(), Is.is(1));
assertThat(queueStatistics.get(0).getDestination(), Is.is("foo_queue"));
}
Aggregations