Search in sources :

Example 1 with QueueMBean

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);
    }
}
Also used : MotechException(org.motechproject.commons.api.MotechException) QueueMBean(org.motechproject.admin.domain.QueueMBean) ArrayList(java.util.ArrayList) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with QueueMBean

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"));
}
Also used : QueueMBean(org.motechproject.admin.domain.QueueMBean) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 3 with QueueMBean

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\"")));
}
Also used : QueueMBean(org.motechproject.admin.domain.QueueMBean) StringContains(org.hamcrest.text.StringContains) Test(org.junit.Test)

Aggregations

QueueMBean (org.motechproject.admin.domain.QueueMBean)3 ObjectName (javax.management.ObjectName)2 QueueViewMBean (org.apache.activemq.broker.jmx.QueueViewMBean)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StringContains (org.hamcrest.text.StringContains)1 MotechException (org.motechproject.commons.api.MotechException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1