
You can connect to an MbeanServer in two ways:: locally and remotely. This procedure describes how you can connect using either of these two approaches.
Connecting to a Local MBeanServer
The local MBeanServer on each cluster element is created by the JMX Adapter Service during startup. A reference is registered in the JNDI. You then look up the MBeanServer from the JNDI. There is no need to create your own MBeanServer instance.
The following example shows the lookup from the JNDI:
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 look up the MBeanServer directly, since it is neither Remote nor Serializable. They have to use an MBeanServerConnection provided by the RMI-P4 JMX Connector. MBeanServerConnection is a super-interface of MBeanServer . The MBeanServerConnection includes 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;
private static MBeanServerConnection getConnection() throws IOException {
// 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. PROTOCOL_ENGINE_P4, connectionProperties);
return mbsc;
}
If you are either accessing a local MBeanServer from an application, or using the RMI-P4 JMX Connector, you have to be logged in as a user who has the required permissions according to the JMX specification. The administrators have these required actions assigned by default.