1 package com.freemindcafe.jmx.sample3;
3 import javax.management.MBeanServerConnection;
4 import javax.management.MBeanServerInvocationHandler;
5 import javax.management.ObjectName;
6 import javax.management.remote.JMXConnector;
7 import javax.management.remote.JMXConnectorFactory;
8 import javax.management.remote.JMXServiceURL;
10 import org.
apache.activemq.broker.jmx.BrokerViewMBean;
11 import org.
apache.activemq.broker.jmx.QueueViewMBean;
12 import org.junit.Test;
17 public void connect_to_activemq_mbean_objects()
throws Exception{
18 JMXServiceURL url =
new JMXServiceURL(
"service:jmx:rmi:///jndi/rmi://nikhil-vm.emeter.com:1099/jmxrmi");
19 JMXConnector jmxc = JMXConnectorFactory.connect(url);
20 MBeanServerConnection conn = jmxc.getMBeanServerConnection();
21 ObjectName activeMQ =
new ObjectName(
"org.apache.activemq:type=Broker,brokerName=localhost");
23 BrokerViewMBean mbean = (BrokerViewMBean) MBeanServerInvocationHandler
24 .newProxyInstance(conn, activeMQ,
25 BrokerViewMBean.class,
true);
26 for (ObjectName name : mbean.getQueues()) {
27 QueueViewMBean queueViewMBean = (QueueViewMBean) MBeanServerInvocationHandler
28 .newProxyInstance(conn, name, QueueViewMBean.class,
31 queueViewMBean.purge();
32 }
catch (Exception e) {