private JMXServiceURL getJMXServiceURL() throws AttachNotSupportedException, IOException {
    String connectorAddress;
    VirtualMachine vm = VirtualMachine.attach(String.valueOf(pid));
    try {
      Properties agentProps = vm.getAgentProperties();
      connectorAddress = agentProps.getProperty(PROPERTY_LOCAL_CONNECTOR_ADDRESS);

      if (connectorAddress == null) {
        // make sure the local management agent is started and this will ensure
        // localConnectorAddress is present in the agent properties.
        vm.startLocalManagementAgent();
        // get the connector address
        agentProps = vm.getAgentProperties();
        connectorAddress = agentProps.getProperty(PROPERTY_LOCAL_CONNECTOR_ADDRESS);
      }
    } finally {
      vm.detach();
    }

    if (connectorAddress == null) {
      // should never reach here
      throw new IOException("Failed to find address to attach to process");
    }

    return new JMXServiceURL(connectorAddress);
  }
Uses the Attach API to connect to the local process and ensures that it has loaded the JMX
management agent. The JMXServiceURL identifying the local connector address for the JMX agent
in the process is returned.

@return the address of the JMX API connector server for connecting to the local process

@throws AttachNotSupportedException if unable to use the Attach API to connect to the process
@throws IOException if the JDK management agent cannot be found and loaded
geode-core/src/main/java/org/apache/geode/internal/process/MBeanProcessController.java