private Object invokeOperationOnTargetMBean(final ObjectName namePattern,
      final String pidAttribute, final String methodName, final String[] attributes,
      final Object[] values)
      throws ConnectionFailedException, IOException, MBeanInvocationFailedException {
    ObjectName objectName = namePattern;
    connect();
    try {
      QueryExp constraint = buildQueryExp(pidAttribute, attributes, values);
      Set<ObjectName> mbeanNames = server.queryNames(namePattern, constraint);

      if (mbeanNames.isEmpty()) {
        throw new MBeanInvocationFailedException("Failed to find mbean matching '" + namePattern
            + "' with attribute '" + pidAttribute + "' of value '" + pid + "'");
      }
      if (mbeanNames.size() > 1) {
        throw new MBeanInvocationFailedException("Found more than one mbean matching '"
            + namePattern + "' with attribute '" + pidAttribute + "' of value '" + pid + "'");
      }

      objectName = mbeanNames.iterator().next();
      return invoke(objectName, methodName);
    } catch (InstanceNotFoundException | MBeanException | ReflectionException e) {
      throw new MBeanInvocationFailedException(
          "Failed to invoke " + methodName + " on " + objectName, e);
    } finally {
      disconnect();
    }
  }
Connects to the process and use its MBean to stop it.

@param namePattern the name pattern of the MBean to use for stopping
@param pidAttribute the name of the MBean attribute with the process id to compare against
@param methodName the name of the MBean operation to invoke
@param attributes the names of the MBean attributes to compare with expected values
@param values the expected values of the specified MBean attributes

@throws ConnectionFailedException if there was a failure to connect to the local JMX connector
        in the process
@throws IOException if a communication problem occurred when talking to the MBean server
@throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason
geode-core/src/main/java/org/apache/geode/internal/process/MBeanProcessController.java