Search in sources :

Example 1 with QueueViewMBean

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

the class SecurityJMXTest method testBrowseExpiredMessages.

public void testBrowseExpiredMessages() 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);
    HashMap<String, String> headers = new HashMap<>();
    headers.put("timeToLive", Long.toString(2000));
    headers.put("JMSDeliveryMode", Integer.toString(DeliveryMode.PERSISTENT));
    queueMbean.sendTextMessage(headers, "test", "system", "manager");
    // allow message to expire on the queue
    TimeUnit.SECONDS.sleep(4);
    Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection("system", "manager");
    c.start();
    // browser consumer will force expiration check on addConsumer
    QueueBrowser browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("TEST.Q"));
    assertTrue("no message in the q", !browser.getEnumeration().hasMoreElements());
    // verify dlq got the message, no security exception as brokers context is now used
    browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("ActiveMQ.DLQ"));
    assertTrue("one message in the dlq", browser.getEnumeration().hasMoreElements());
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) HashMap(java.util.HashMap) JMXConnector(javax.management.remote.JMXConnector) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) Connection(javax.jms.Connection) MBeanServerConnection(javax.management.MBeanServerConnection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MBeanServerConnection(javax.management.MBeanServerConnection) QueueBrowser(javax.jms.QueueBrowser) ObjectName(javax.management.ObjectName)

Example 2 with QueueViewMBean

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

the class VerifyNetworkConsumersDisconnectTest method assertExactConsumersConnect.

protected void assertExactConsumersConnect(final String brokerName, final int count, final int numChecks, long timeout) throws Exception {
    final ManagementContext context = brokers.get(brokerName).broker.getManagementContext();
    final AtomicInteger stability = new AtomicInteger(0);
    assertTrue("Expected consumers count: " + count + " on: " + brokerName, Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            try {
                QueueViewMBean queueViewMBean = (QueueViewMBean) context.newProxyInstance(brokers.get(brokerName).broker.getAdminView().getQueues()[0], QueueViewMBean.class, false);
                long currentCount = queueViewMBean.getConsumerCount();
                LOG.info("On " + brokerName + " current consumer count for " + queueViewMBean + ", " + currentCount);
                LinkedList<String> consumerIds = new LinkedList<>();
                for (ObjectName objectName : queueViewMBean.getSubscriptions()) {
                    consumerIds.add(objectName.getKeyProperty("consumerId"));
                }
                LOG.info("Sub IDs: " + consumerIds);
                if (currentCount == count) {
                    stability.incrementAndGet();
                } else {
                    stability.set(0);
                }
                return stability.get() > numChecks;
            } catch (Exception e) {
                LOG.warn(": ", e);
                return false;
            }
        }
    }, timeout));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) ManagementContext(org.apache.activemq.broker.jmx.ManagementContext) LinkedList(java.util.LinkedList) ObjectName(javax.management.ObjectName)

Example 3 with QueueViewMBean

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

the class OpenTypeSupportTest method getProxyToQueueViewMBean.

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

Example 4 with QueueViewMBean

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

the class QueuePurgeTest method testPurgeLargeQueueWithConsumer.

public void testPurgeLargeQueueWithConsumer() throws Exception {
    applyBrokerSpoolingPolicy();
    createProducerAndSendMessages(NUM_TO_SEND);
    QueueViewMBean proxy = getProxyToQueueViewMBean();
    createConsumer();
    long start = System.currentTimeMillis();
    LOG.info("purging..");
    proxy.purge();
    LOG.info("purge done: " + (System.currentTimeMillis() - start) + "ms");
    assertEquals("Queue size is not zero, it's " + proxy.getQueueSize(), 0, proxy.getQueueSize());
    assertEquals("usage goes to duck", 0, proxy.getMemoryPercentUsage());
    Message msg;
    do {
        msg = consumer.receive(1000);
        if (msg != null) {
            msg.acknowledge();
        }
    } while (msg != null);
    assertEquals("Queue size not valid", 0, proxy.getQueueSize());
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean)

Example 5 with QueueViewMBean

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

the class QueuePurgeTest method testRepeatedExpiryProcessingOfLargeQueue.

public void testRepeatedExpiryProcessingOfLargeQueue() throws Exception {
    applyBrokerSpoolingPolicy();
    final int expiryPeriod = 500;
    applyExpiryDuration(expiryPeriod);
    createProducerAndSendMessages(NUM_TO_SEND);
    QueueViewMBean proxy = getProxyToQueueViewMBean();
    LOG.info("waiting for expiry to kick in a bunch of times to verify it does not blow mem");
    Thread.sleep(5000);
    assertEquals("Queue size is has not changed " + proxy.getQueueSize(), NUM_TO_SEND, proxy.getQueueSize());
}
Also used : QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean)

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