Wednesday, November 3, 2010

JMX Service URL

JMX service URL could be in either JNDI form or encoded form.

JNDI form: the RMI stub is acquired from external such as RMI registry

Encoded form: the generated stub is encoded and attached in service url itself. So no RMI registry is required.

The JMX service URL has the following syntax:


Although host and port may be included, they are ignored by the RMI protocol. If urlPath is specified, it gives the Java Naming and Directory Interface (JNDI) location of an RMI stub (typically a location within an RMI registry) in the form


For example, the URL


specifies an RMI stub at the location


which is an RMI registry running at location myhost/myjmxconnector on port 1099 of host myhost.

Alternatively, if urlPath is omitted from the service URL, the JMX connector server will generate a client URL containing the actual RMI stub embedded within it in encoded and serialized form. For example, the service URL


will generate a client URL of the form


where rmiStub is an encoded and serialized representation of the RMI stub itself.

// Get the platform MBeanServer
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();

// Attach a JMXConnectorServer to the platform MBeanServer
JMXServiceURL jmxServiceURL = new JMXServiceURL("service:jmx:rmi:///");
JMXConnectorServer connectorServer =
JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceURL, null, mbeanServer);

// Refresh the JMXServiceURL after the JMXConnectorServer has started
// it is different with the original one with the stub object attached.
jmxServiceURL = connectorServer.getAddress();

JMX Service URL example
JMX remoting API
JMX Service URLs

No comments: