!--a11y-->
Connecting to an MBeanServer 
· The local MBeanServer on each cluster element is created by the JMX Adapter Service during startup. A reference is registered in the JNDI and ObjectRegistry (part of the J2EE Engine services framework). The MBeanServerFactory cannot be used to find this local MBeanServer. You lookup the MBeanServer from either registry mentioned above. There is no need to create your own MBeanServer instance.
The following example shows the lookup from the JNDI. This example can be used by both services and applications.

import javax.naming.InitialContext; import javax.management.MBeanServer; ... // Lookup MBeanServer from the JNDI InitialContext initCtx = new InitialContext(); MBeanServer mbs = (MBeanServer) initCtx.lookup("jmx"); |
· Clients running outside the cluster cannot lookup the MBeanServer directly, since it is neither Remote nor Serializable. They have to use an MBeanServerConnection provided by the RMI-P4 JMX Connector.

If you are either accessing a local MBeanServer from an application, or using the RMI-P4 JMX Connector, you have to be logged in with a user in the default administrator role.
As mentioned above, a client running outside the cluster must use an MBeanServerConnection via RMI-P4, which is connected to the local MBeanServer of an arbitrary server process. MBeanServerConnection is a super-interface of MBeanServer. The MBeanServerConnectionincludes only those MBeanServer methods that make sense in a remote scenario. The following example demonstrates the creation of a connection:

import java.util.Properties; import javax.naming.Context; import com.sap.jmx.remote.JmxConnectionFactory; ... // set the connection properties for the RMI-P4 connection Properties connectionProperties = new Properties(); connectionProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl"); connectionProperties.setProperty(Context.PROVIDER_URL, "<host-name>:<p4-port>"); connectionProperties.setProperty(Context.SECURITY_PRINCIPAL, "<user-name>"); connectionProperties.setProperty(Context.SECURITY_CREDENTIALS, "<password>"); // create the MBeanServerConnection MBeanServerConnection mbsc = JmxConnectionFactory.getMBeanServerConnection(JmxConnectionFactory. |
