Awesome, thank you Chris!
On Thu, Oct 24, 2013 at 7:41 PM, Christian Posta <[email protected]>wrote: > I've opened the issue here: https://issues.apache.org/jira/browse/AMQ-4823and > fixed it on origin/trunk. > > > > > On Thu, Oct 24, 2013 at 9:30 AM, Christian Posta > <[email protected]>wrote: > > > Yah, seems like the mbeans aren't registered properly when creating > > through JMX. > > > > The bridge does get created, but it's not visible in jconsole. > > > > Can you create a JIRA for this? > > > > > > On Thu, Oct 24, 2013 at 4:11 AM, Bratislav Stojanovic < > > [email protected]> wrote: > > > >> 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. > >> > > > > > > > > -- > > *Christian Posta* > > http://www.christianposta.com/blog > > twitter: @christianposta > > > > > > -- > *Christian Posta* > http://www.christianposta.com/blog > twitter: @christianposta > -- Bratislav Stojanovic, M.Sc.
