use of org.motechproject.admin.domain.QueueMBean 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.admin.domain.QueueMBean 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"));
}
use of org.motechproject.admin.domain.QueueMBean in project motech by motech.
the class BrokerStatisticsControllerTest method shouldReturnAllQueueInformation.
@Test
public void shouldReturnAllQueueInformation() throws Exception {
given(mBeanService.getQueueStatistics()).willReturn(Arrays.asList(new QueueMBean("queue-1"), new QueueMBean("queue-2")));
mockMvc.perform(MockMvcRequestBuilders.get("/queues")).andExpect(status().isOk()).andExpect(content().string(new StringContains("\"destination\":\"queue-1\""))).andExpect(content().string(new StringContains("\"destination\":\"queue-2\"")));
}
Aggregations