Search in sources :

Example 1 with TopicMBean

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

Example 2 with TopicMBean

use of org.motechproject.admin.domain.TopicMBean in project motech by motech.

the class BrokerStatisticsControllerTest method shouldReturnAllTopicInformation.

@Test
public void shouldReturnAllTopicInformation() throws Exception {
    given(mBeanService.getTopicStatistics()).willReturn(Arrays.asList(new TopicMBean("topic-1"), new TopicMBean("topic-2")));
    mockMvc.perform(MockMvcRequestBuilders.get("/topics")).andExpect(status().isOk()).andExpect(content().string(new StringContains("\"destination\":\"topic-1\""))).andExpect(content().string(new StringContains("\"destination\":\"topic-2\"")));
}
Also used : TopicMBean(org.motechproject.admin.domain.TopicMBean) StringContains(org.hamcrest.text.StringContains) Test(org.junit.Test)

Aggregations

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