code: public static MBeanServerConnection connectMBeanServer(String server) throws MBeanServerException {
          String url = "service:jmx:rmi://localhost/jndi/rmi://"+server+"/jmxrmi";
          try {
              JMXServiceURL jmxUrl = new JMXServiceURL(url);
              JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl);
              return jmxConnector.getMBeanServerConnection();
          } catch (MalformedURLException e) {
              throw new MBeanServerException(
                      "Problem with JMXServiceURL based on " + url +
                              ": " + e.getMessage());
          } catch (IOException e) {
              throw new MBeanServerException(
                      "Failed to connect to JMX server: " + server +
                              ": " + e.getMessage());
          }  
      }
docs: Attempt to connect to a remote <code>MBeanServer</code>. Fails if no
  <code>MBeanServer</code> connection can be established.