Which Remote Interface Should I use for the MBeanServer ?
To future proof yourself you should use the javax.management.MBeanServerConnection interface as defined in JMX1.2 rather than the jboss specifc RMIAdaptor interface.
Some of the methods on the RMIAdaptor should never have been exposed remotely, e.g. the classloading
methods and registerMBean().
import javax.management.MBeanServerConnection; ... // Lookup JMX adaptor from JNDI using environment jndi.properties InitialContext ctx = new InitialContext(); MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");
Migrating from 3.2 Proprietary classes
The 3.2 release had serveral jmx connector interfaces such as org.jboss.jmx.connector., org.jboss.jmx.adaptor. that should be migrated to the standard javax.management.MBeanServerConnection using the code fragment shown above.
In AS 6.0 M3 or greater, the RMIAdaptor class should not be used
The above (legacy) lookup code will return a MBeanServerConnection (as long as JBoss client jars are on the classpath). The following lookup code should be used instead:
import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; . . . // replace "localhost" with the target server hostname or ip address String serverURL = "service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi" String username = null; String password = null; HashMap env = new HashMap(); if (username != null && password != null) { String[] creds = new String[2]; creds[0] = username; creds[1] = password; env.put(JMXConnector.CREDENTIALS, creds); } JMXServiceURL url = new JMXServiceURL(serverURL); JMXConnector jmxc = JMXConnectorFactory.connect(url, env); // Remember to call jmxc.close() when done with MbeanServerConnection MbeanServerConnection server = jmxc.getMBeanServerConnection(); // jmxc.close(); // this closes the "server" connection
Comments