activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bratislav Stojanovic <bratislav1...@gmail.com>
Subject Add network connector dynamically over JMX
Date Thu, 24 Oct 2013 11:11:21 GMT
Hi all,

Does anybody know how to do this? Here's the code I've tried, but it
doesn't work :

JMXServiceURL url = new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root");
 Map env = new HashMap();
String[] creds = {"...", "..."};
env.put(JMXConnector.CREDENTIALS, creds);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, env);

    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    // Get domains from MBeanServer
    System.out.println("\nDomains:");
        String domains[] = mbsc.getDomains();
        Arrays.sort(domains);
        for (String domain : domains) {
        System.out.println("\tDomain = " + domain);
        }

    // Get MBeanServer's default domain
        System.out.println("\nMBeanServer default domain = " +
mbsc.getDefaultDomain());

        // Get MBean count
        //
        System.out.println("\nMBean count = " + mbsc.getMBeanCount());

        // Query MBean names
        //
        System.out.println("\nQuery MBeanServer MBeans:");
        Set<ObjectName> names =
            new TreeSet<ObjectName>(mbsc.queryNames(null, null));
        for (ObjectName name : names) {
        System.out.println("\tObjectName = " + name);
        }


        // find mbean
        ObjectName mbeanName = null;
        for (ObjectName name : names) {
        if
(name.toString().equals("org.apache.activemq:type=Broker,brokerName=broker"))
{
        mbeanName = name;
        }
        }

        if (mbeanName == null) {
        System.err.println("No mbean found");
        return;
        }

        BrokerViewMBean mbeanProxy =JMX.newMBeanProxy(mbsc, mbeanName,
BrokerViewMBean.class, true);


System.out.println(mbeanProxy.addNetworkConnector("static:failover:(tcp://localhost:61617)"));

        ObjectName mbeanName2 = new
ObjectName("org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC");
        NetworkConnectorViewMBean mbeanProxy2 =JMX.newMBeanProxy(mbsc,
mbeanName2, NetworkConnectorViewMBean.class, true);

        mbeanProxy2.start();  // start NC
        jmxc.close();

It will fail on the second proxy with the message :

Exception in thread "main" javax.management.InstanceNotFoundException:
org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC

I'm using activemq 5.9.0 running inside karaf 2.3.3.

Please help!

-- 
Bratislav Stojanovic, M.Sc.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message