In order to invoke a management operation on a MBean, the caller must access to the MBean server.
When the caller is located in the same JVM as the MBean Server, it can use the javax.management.MBeanServerFactory class to obtain a reference to the MBean Server:
List mbeanServers = MBeanServerFactory.findMBeanServer(null); if (mbeanServers != null && mbeanServers.size() > 0) { return (MBeanServer) mbeanServers.get(0); } |
When the caller is remote, it can use a JMX remote connector to establish a connection with the MBean Server and obtain a javax.management.MBeanServerConnection object.
Suppose that the connector server has the following address: service:jmx:jrmp://host/jndi/jrmp://host:1099/jrmpconnector_jonas, which is the default for a JOnAS server called jonas.
JMXServiceURL connURL = new JMXServiceURL( "service:jmx:jrmp://host/jndi/jrmp://host:1099/jrmpconnector_jonas"); JMXConnector connector = JMXConnectorFactory.newJMXConnector(connURL, null); connector.connect(null); MBeanServerConnection conn = connector.getMBeanServerConnection(); return conn; |
A remote caller can also use the MEJB provided by the JOnAS distribution. A Management EJB implementation, compliant to the JSR 77, is packed in the mejb.ear installed in the JONAS_ROOT/ejbjars/autoload directory. Thus, the MEJB is automatically deployed at JOnAS start-up. Its Home is registered in JNDI under the name ejb/mgmt/MEJB. The JOnAS distribution also contains an example using the MEJB in a J2EE application, the j2eemanagement sample.
A remote caller can use the Management Web Service endpoint that is packaged as a part of the mejb.ear, which is installed in the JONAS_ROOT/ejbjars/autoload directory. Thus, the management endpoint is automatically deployed at JOnAS start-up. Check http://<hostname>:<port>/mejb/ManagementEndpoint/ManagementEndpoint?wsdl on a running JOnAS instance for the WSDL file. The endpoint allows light-weight clients to query JOnAS MBeans from virtually any platform by leveraging the platform-independant nature of Web Services.