Search in sources :

Example 11 with QueueViewMBean

use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.

the class JMXRemoveQueueThenSendIgnoredTest method numberOfMessages.

private int numberOfMessages() throws Exception {
    ObjectName queueViewMBeanName = new ObjectName(domain + ":destinationType=Queue,destinationName=myqueue,type=Broker,brokerName=dev");
    QueueViewMBean queue = (QueueViewMBean) brokerService.getManagementContext().newProxyInstance(queueViewMBeanName, QueueViewMBean.class, true);
    long size = queue.getQueueSize();
    return (int) size;
}
Also used : QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) ObjectName(javax.management.ObjectName)

Example 12 with QueueViewMBean

use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.

the class ConsumeUncompressedCompressedMessageTest method getProxyToQueueViewMBean.

private QueueViewMBean getProxyToQueueViewMBean() throws MalformedObjectNameException, JMSException {
    ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq" + ":destinationType=Queue,destinationName=" + queue.getQueueName() + ",type=Broker,brokerName=localhost");
    QueueViewMBean proxy = (QueueViewMBean) broker.getManagementContext().newProxyInstance(queueViewMBeanName, QueueViewMBean.class, true);
    return proxy;
}
Also used : QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) ObjectName(javax.management.ObjectName)

Example 13 with QueueViewMBean

use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.

the class QueuePurgeTest method testPurgeLargeQueue.

public void testPurgeLargeQueue() throws Exception {
    applyBrokerSpoolingPolicy();
    createProducerAndSendMessages(NUM_TO_SEND);
    QueueViewMBean proxy = getProxyToQueueViewMBean();
    LOG.info("purging..");
    org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.region.Queue.class);
    final AtomicBoolean gotPurgeLogMessage = new AtomicBoolean(false);
    Appender appender = new DefaultTestAppender() {

        @Override
        public void doAppend(LoggingEvent event) {
            if (event.getMessage() instanceof String) {
                String message = (String) event.getMessage();
                if (message.contains("purged of " + NUM_TO_SEND + " messages")) {
                    LOG.info("Received a log message: {} ", event.getMessage());
                    gotPurgeLogMessage.set(true);
                }
            }
        }
    };
    Level level = log4jLogger.getLevel();
    log4jLogger.setLevel(Level.INFO);
    log4jLogger.addAppender(appender);
    try {
        proxy.purge();
    } finally {
        log4jLogger.setLevel(level);
        log4jLogger.removeAppender(appender);
    }
    assertEquals("Queue size is not zero, it's " + proxy.getQueueSize(), 0, proxy.getQueueSize());
    assertTrue("cache is disabled, temp store being used", !proxy.isCacheEnabled());
    assertTrue("got expected info purge log message", gotPurgeLogMessage.get());
}
Also used : Appender(org.apache.log4j.Appender) DefaultTestAppender(org.apache.activemq.util.DefaultTestAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultTestAppender(org.apache.activemq.util.DefaultTestAppender) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) Level(org.apache.log4j.Level)

Example 14 with QueueViewMBean

use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.

the class PurgeCommandTest method testQueueViewMbean.

/**
 * This test ensures that the queueViewMbean will work.
 *
 * @throws Exception
 */
public void testQueueViewMbean() throws Exception {
    try {
        addMessages();
        validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
        List<String> tokens = Arrays.asList(new String[] { "*" });
        for (String token : tokens) {
            List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), "type=Broker,brokerName=localbroker,destinationType=Queue,destinationName=" + token);
            for (ObjectInstance queue : queueList) {
                ObjectName queueName = queue.getObjectName();
                QueueViewMBean proxy = MBeanServerInvocationHandler.newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);
                int removed = proxy.removeMatchingMessages(MSG_SEL_WITH_PROPERTY);
                LOG.info("Removed: " + removed);
            }
        }
        validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);
    } finally {
        purgeAllMessages();
    }
}
Also used : ObjectInstance(javax.management.ObjectInstance) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) ObjectName(javax.management.ObjectName)

Example 15 with QueueViewMBean

use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.

the class SecurityJMXTest method testMoveMessages.

public void testMoveMessages() throws Exception {
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
    JMXConnector connector = JMXConnectorFactory.connect(url, null);
    connector.connect();
    MBeanServerConnection connection = connector.getMBeanServerConnection();
    ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost," + "destinationType=Queue,destinationName=TEST.Q");
    QueueViewMBean queueMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
    String msgId = queueMbean.sendTextMessage("test", "system", "manager");
    queueMbean.moveMessageTo(msgId, "TEST1.Q");
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

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