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:
service:jmx:rmi://[host[:port]][urlPath]
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
/jndi/jndiName
For example, the URL
service:jmx:rmi://myhost/jndi/rmi://myhost:1099/myhost/myjmxconnector
specifies an RMI stub at the location
rmi://myhost:1099/myhost/myjmxconnector
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
service:jmx:rmi://localhost
will generate a client URL of the form
service:jmx:rmi://localhost/stub/rmiStub
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);
connectorServer.start();
// Refresh the JMXServiceURL after the JMXConnectorServer has started
// it is different with the original one with the stub object attached.
jmxServiceURL = connectorServer.getAddress();
See:
JMX Service URL example
JMX remoting API
JMX Service URLs
No comments:
Post a Comment