String host = hostAddr.getHostAddress();
String urlString = System.getProperty("jmx.service.url", "service:jmx:rmi:///jndi/rmi://" + NetworkUtils.formatPossibleIpv6Address(host) + ":" + port + "/jmxrmi");
try {
if (jmxConnector == null) {
log.debug("Connecting JMXConnector to: " + urlString);
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
}
return jmxConnector.getMBeanServerConnection();
} catch (IOException ex) {
throw new IllegalStateException("Cannot obtain MBeanServerConnection to: " + urlString, ex);