Search in sources :

Example 16 with QueueViewMBean

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();
}
Also used : QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean)

Example 17 with QueueViewMBean

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

Example 18 with QueueViewMBean

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);
    }
}
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 19 with QueueViewMBean

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

Aggregations

QueueViewMBean (org.apache.activemq.broker.jmx.QueueViewMBean)19 ObjectName (javax.management.ObjectName)12 CompositeData (javax.management.openmbean.CompositeData)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MBeanServerConnection (javax.management.MBeanServerConnection)2 JMXConnector (javax.management.remote.JMXConnector)2 JMXServiceURL (javax.management.remote.JMXServiceURL)2 ManagementContext (org.apache.activemq.broker.jmx.ManagementContext)2 QueueMBean (org.motechproject.admin.domain.QueueMBean)2 MotechException (org.motechproject.commons.api.MotechException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 LinkedList (java.util.LinkedList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Connection (javax.jms.Connection)1