/** Calls a method. */
  public Object __call(String name, Value values) {
    try {
      int size = values.getSize();

      Object[] args = new Object[values.getSize()];

      for (int i = 0; i < size; i++) {
        args[i] = values.get(LongValue.create(i)).toJavaObject();
      }

      MBeanOperationInfo opInfo = findClosestOperation(name, args);

      if (opInfo != null) {
        String[] mbeanSig = createMBeanSig(opInfo);

        marshall(args, mbeanSig);

        Object value = _server.invoke(_name, name, args, mbeanSig);

        return unmarshall(value);
      } else {
        return _server.invoke(_name, name, args, null);
      }
    } catch (Exception e) {
      log.log(Level.FINE, e.toString(), e);

      return null;
    }
  }
Beispiel #2
0
 @Test
 public void renameViaMBean() throws Exception {
   JMXConnector connector = null;
   try {
     connector = this.getJMXConnector();
     MBeanServerConnection connection = connector.getMBeanServerConnection();
     ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
     connection.invoke(
         name,
         "createInstance",
         new Object[] {"itest5", 0, 0, 0, null, null, null, null},
         new String[] {
           "java.lang.String",
           "int",
           "int",
           "int",
           "java.lang.String",
           "java.lang.String",
           "java.lang.String",
           "java.lang.String"
         });
     connection.invoke(
         name,
         "renameInstance",
         new Object[] {"itest5", "new_itest5"},
         new String[] {"java.lang.String", "java.lang.String"});
   } finally {
     if (connector != null) connector.close();
   }
 }
Beispiel #3
0
  private static void workOnSingletoBean(
      MBeanServerConnection server, String jndiName, int numThreads, int numTimes)
      throws Exception {
    int singletonBeanInstances =
        (Integer)
            server.invoke(
                new ObjectName("jboss:name=ejb3-test,type=service"),
                "lookupSingleton",
                new Object[] {jndiName, numThreads, numTimes},
                new String[] {
                  String.class.getName(), Integer.TYPE.getName(), Integer.TYPE.getName()
                });
    System.out.println("Number of singleton bean instances created is: " + singletonBeanInstances);

    int count =
        (Integer)
            server.invoke(
                new ObjectName("jboss:name=ejb3-test,type=service"),
                "invokeSingleton",
                new Object[] {jndiName, numThreads, numTimes},
                new String[] {
                  String.class.getName(), Integer.TYPE.getName(), Integer.TYPE.getName()
                });
    System.out.println("Count is: " + count);
  }
Beispiel #4
0
 @Test
 public void createDestroyViaMBean() throws Exception {
   JMXConnector connector = null;
   try {
     connector = this.getJMXConnector();
     MBeanServerConnection connection = connector.getMBeanServerConnection();
     ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
     int oldNum = getInstancesNum(connection, name);
     connection.invoke(
         name,
         "createInstance",
         new Object[] {"itest2", 0, 0, 0, null, null, null, null},
         new String[] {
           "java.lang.String",
           "int",
           "int",
           "int",
           "java.lang.String",
           "java.lang.String",
           "java.lang.String",
           "java.lang.String"
         });
     Assert.assertEquals(oldNum + 1, getInstancesNum(connection, name));
     connection.invoke(
         name, "destroyInstance", new Object[] {"itest2"}, new String[] {"java.lang.String"});
     Assert.assertEquals(oldNum, getInstancesNum(connection, name));
   } finally {
     if (connector != null) close(connector);
   }
 }
  private String invokeEndpoint(String operation, String operationPara) throws Exception {
    ObjectName endpointName = null;
    ObjectName queryEndpointName;
    String ret = "";
    Object[] jmxPara = null;
    String[] jmxSig = null;
    if (operationPara != null) {
      jmxPara = new Object[] {operationPara};
      jmxSig = new String[] {String.class.getName()};
    } else {
      jmxPara = new Object[0];
      jmxSig = new String[0];
    }
    queryEndpointName = getEndpointObjectName();
    Set<ObjectName> endpointNames = CastUtils.cast(mbsc.queryNames(queryEndpointName, null));
    // now get the ObjectName with the busId
    Iterator<ObjectName> it = endpointNames.iterator();

    if (it.hasNext()) {
      // only deal with the first endpoint object which return from the list.
      endpointName = it.next();
      ret = (String) mbsc.invoke(endpointName, operation, jmxPara, jmxSig);
      LOG.info("invoke endpoint " + endpointName + " operation " + operation + " succeed!");
    }
    return ret;
  }
Beispiel #6
0
 public Object executeMethod(String bean, String method, Object[] params, String[] signature) {
   MBeanServerConnection server = getMBeanServerConnection();
   try {
     Object value = server.invoke(new ObjectName(bean), method, params, signature);
     if (LOG.isDebugEnabled()) {
       LOG.debug(
           "The bean: "
               + bean
               + " method: "
               + method
               + " params="
               + Arrays.toString(params)
               + " signature="
               + Arrays.toString(signature)
               + " returned: "
               + value);
     }
     return value;
   } catch (IOException e) {
     throw new RuntimeException("Failed to invoke method: " + method + ", for MBean: " + bean, e);
   } catch (InstanceNotFoundException e) {
     throw new RuntimeException("Failed to invoke method: " + method + ", for MBean: " + bean, e);
   } catch (MalformedObjectNameException e) {
     throw new RuntimeException("Failed to invoke method: " + method + ", for MBean: " + bean, e);
   } catch (MBeanException e) {
     throw new RuntimeException("Failed to invoke method: " + method + ", for MBean: " + bean, e);
   } catch (ReflectionException e) {
     throw new RuntimeException("Failed to invoke method: " + method + ", for MBean: " + bean, e);
   } catch (NullPointerException e) {
     throw new RuntimeException("Failed to invoke method: " + method + ", for MBean: " + bean, e);
   }
 }
Beispiel #7
0
 /**
  * connect to org.wso2.carbon to invoke different operations
  *
  * @param userName user name to connect to org.wso2.carbon
  * @param password password to connect to org.wso2.carbon
  * @param connectionType
  * @param operation
  * @throws Exception
  */
 public void connect(String userName, String password, String connectionType, String operation)
     throws Exception {
   try {
     JMXServiceURL url =
         new JMXServiceURL(
             "service:jmx:rmi://"
                 + NetworkUtils.getLocalHostname()
                 + ":"
                 + RMIServerPort
                 + "/jndi/rmi://"
                 + NetworkUtils.getLocalHostname()
                 + ":"
                 + RMIRegistryPort
                 + "/jmxrmi");
     Hashtable<String, String[]> hashT = new Hashtable<String, String[]>();
     String[] credentials = new String[] {userName, password};
     hashT.put("jmx.remote.credentials", credentials);
     jmxc = JMXConnectorFactory.connect(url, hashT);
     mbsc = jmxc.getMBeanServerConnection();
     nodeAgent = new ObjectName(connectionType);
     mbsc.invoke(nodeAgent, operation, null, null);
   } catch (Exception ex) {
     log.error("infoAdminServiceStub Initialization fail ");
     throw new Exception("infoAdminServiceStub Initialization fail " + ex.getMessage());
   }
 }
  @Test(groups = "wso2.esb", description = "JMS Consumer Test after resume")
  public void testJMSResume() throws Exception {

    // redeploy proxy service
    addProxyService(AXIOMUtil.stringToOM(getJMSProxy()));
    // give it max time to deploy
    Thread.sleep(16000);

    // JMS should still be paused.
    assertTrue(!stringExistsInLog(msgAfter));

    // resume JMS Listener from JMXClient
    Set<ObjectInstance> objSet =
        mbsc.queryMBeans(
            new ObjectName("org.apache.axis2:Type=Transport,ConnectorName=jms-listener-*"), null);
    Iterator i = objSet.iterator();
    while (i.hasNext()) {
      ObjectInstance obj = (ObjectInstance) i.next();
      mbsc.invoke(obj.getObjectName(), "resume", null, null);
    }

    Thread.sleep(10000);
    assertTrue(stringExistsInLog("Listener resumed"));
    assertTrue(stringExistsInLog(msgAfter));
  }
 public void close() throws ManagementConsoleException {
   try {
     mbeanServer.invoke(serviceUsageMBean, "close", new Object[] {}, new String[] {});
   } catch (Exception e) {
     e.printStackTrace();
     throw new ManagementConsoleException(SleeManagementMBeanUtils.doMessage(e));
   }
 }
Beispiel #10
0
 private static void exec(MBeanServerConnection server, Class<? extends Callable<?>> callableClass)
     throws Exception {
   String msg =
       (String)
           server.invoke(
               new ObjectName("jboss:name=ejb3-test,type=service"),
               "exec",
               new Object[] {callableClass},
               new String[] {Class.class.getName()});
   System.out.println(msg);
 }
Beispiel #11
0
 public void deleteInstance(String instanceUID) throws Exception {
   Context context = new InitialContext();
   String icmaaetitle = (String) context.lookup("java:global/ICMAAETITLE");
   LoginContext lctx = new LoginContext(icmaaetitle, null, pacsHandler, conf);
   lctx.login();
   InitialContext ctx = new InitialContext(env);
   MBeanServerConnection mconn = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");
   ObjectName contentEditName = new ObjectName("dcm4chee.archive:service=ContentEditService");
   String[] inst = {instanceUID};
   // mconn.invoke(contentEditName, "moveInstanceToTrash", new Object[] {
   // instanceUID }, new String[] { String.class.getName() });
   mconn.invoke(
       contentEditName,
       "moveInstancesToTrash",
       new Object[] {inst},
       new String[] {String[].class.getName()});
   mconn.invoke(contentEditName, "emptyTrash", null, null);
   lctx.logout();
   // System.out.println("Successfully deleted image "+instanceUID);
 }
 public void resetAllUsageParameters(SbbID sbbID) throws ManagementConsoleException {
   try {
     mbeanServer.invoke(
         serviceUsageMBean,
         "resetAllUsageParameters",
         new Object[] {sbbID},
         new String[] {SbbID.class.getName()});
   } catch (Exception e) {
     e.printStackTrace();
     throw new ManagementConsoleException(SleeManagementMBeanUtils.doMessage(e));
   }
 }
 public void createUsageParameterSet(SbbID sbbID, String name) throws ManagementConsoleException {
   try {
     mbeanServer.invoke(
         serviceUsageMBean,
         "createUsageParameterSet",
         new Object[] {sbbID, name},
         new String[] {SbbID.class.getName(), String.class.getName()});
   } catch (Exception e) {
     e.printStackTrace();
     throw new ManagementConsoleException(SleeManagementMBeanUtils.doMessage(e));
   }
 }
  /**
   * An abstract method that Executes the command
   *
   * @throws CommandException
   */
  public void runCommand() throws CommandException, CommandValidationException {
    if (!validateOptions()) throw new CommandValidationException("Validation is false");

    // use http connector
    MBeanServerConnection mbsc =
        getMBeanServerConnection(
            getHost(), getPort(),
            getUser(), getPassword());
    final String targetName = (String) getOption(TARGET_NAME);

    // if targetName is not null, then try to get the Config ObjectName of the
    // target before creating the resource because we don't want to create
    // the resource if the target does not exist.
    ObjectName scON =
        (targetName != null && !targetName.equals(DOMAIN))
            ? getTargetConfigObjectName(mbsc, targetName)
            : null;

    final Object[] params = getParamsInfo();
    final String operationName = getOperationName();
    final String[] types = getTypesInfo();

    try {
      Object returnValue =
          mbsc.invoke(Util.newObjectName(DOMAIN_CONFIG_OBJECT_NAME), operationName, params, types);
      if (scON != null) {
        // create reference to the target
        mbsc.invoke(
            scON,
            "createResourceRefConfig",
            new Object[] {new String((String) getOperands().get(0))},
            new String[] {"java.lang.String"});
      }
      CLILogger.getInstance()
          .printDetailMessage(getLocalizedString("CommandSuccessful", new Object[] {name}));

    } catch (Exception e) {
      displayExceptionMessage(e);
    }
  }
  protected boolean jmxRmiWebappNotification(
      String action, int version, String pathToWebapp, boolean isRecursive) {
    long start = System.currentTimeMillis();

    if (!verifyJmxRmiConnection()) {
      return false;
    }

    try {
      Boolean result =
          (Boolean)
              mbsc_.invoke(
                  virtWebappRegistry_,
                  action,
                  new Object[] {new Integer(version), pathToWebapp, new Boolean(isRecursive)},
                  new String[] {"java.lang.Integer", "java.lang.String", "java.lang.Boolean"});

      if (!result.booleanValue()) {
        if (log.isErrorEnabled())
          log.error(
              "Action failed: " + action + "  Version: " + version + "  Webapp: " + pathToWebapp);

        return false;
      }
      return true;
    } catch (Exception e) {
      if (log.isErrorEnabled())
        log.error(
            "Could not connect to JMX Server within remote "
                + "virtualization server "
                + "(this may be a transient error.)");

      closeJmxRmiConnection();

      return false;
    } finally {
      if (log.isDebugEnabled()) {
        log.debug(
            "jmxRmiWebappNotification: "
                + action
                + "["
                + version
                + ", "
                + pathToWebapp
                + ","
                + isRecursive
                + " in "
                + (System.currentTimeMillis() - start)
                + " ms");
      }
    }
  }
 private Object getRemoteValue() throws Exception {
   if (TangoConnectionFactory.isMockMode()) {
     // We also send this back to the workbench.
     final MBeanServerConnection client = getRemoteClient();
     return client.invoke(
         RemoteWorkbenchAgent.REMOTE_WORKBENCH,
         "getMockMotorValue",
         new Object[] {getName()},
         new String[] {String.class.getName()});
   } else {
     throw new Exception("Cannot set Mock Values when not in mock mode!");
   }
 }
  static boolean execScript(String process, String script) {
    int vmid = -1;
    try {
      vmid = Integer.parseInt(process);
    } catch (NumberFormatException e) {
      vmid = findVmid(process);
    }
    if (vmid == -1) {
      System.err.println(process + ": Could not find process");
      return false;
    }

    try {
      JMXConnector jmxc;
      MBeanServerConnection server;

      String address = ConnectorAddressLink.importFrom(vmid);
      JMXServiceURL jmxUrl = new JMXServiceURL(address);
      jmxc = JMXConnectorFactory.connect(jmxUrl);
      server = jmxc.getMBeanServerConnection();
      Object[] parameters = {script};
      String[] signature = {"java.lang.String"};
      Object result;
      result =
          server.invoke(
              new ObjectName("net.multiverse:type=Engine"),
              "runPythonScript",
              parameters,
              signature);
      System.out.println(result.toString());
      jmxc.close();
    } catch (IOException e) {
      System.err.println("Unable to attach to " + vmid + ": " + e.getMessage());
      return false;
    } catch (javax.management.MalformedObjectNameException e) {
      System.err.println("Internal error: " + e.getMessage());
      return false;
    } catch (javax.management.InstanceNotFoundException e) {
      System.err.println("Process " + vmid + " is not a Multiverse engine");
      return false;
    } catch (javax.management.MBeanException e) {
      System.err.println("Error: " + e);
      return false;
    } catch (javax.management.ReflectionException e) {
      System.err.println("Error: " + e);
      return false;
    }
    return true;
  }
 public SbbUsageMBeanUtils getSbbUsageMBeanUtils(SbbID sbbID) throws ManagementConsoleException {
   try {
     ObjectName sbbUsageMBean =
         (ObjectName)
             mbeanServer.invoke(
                 serviceUsageMBean,
                 "getSbbUsageMBean",
                 new Object[] {sbbID},
                 new String[] {SbbID.class.getName()});
     return new SbbUsageMBeanUtils(mbeanServer, sbbUsageMBean);
   } catch (Exception e) {
     e.printStackTrace();
     throw new ManagementConsoleException(SleeManagementMBeanUtils.doMessage(e));
   }
 }
Beispiel #19
0
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
   String methodName = method.getName();
   Class[] sigTypes = method.getParameterTypes();
   ArrayList sigStrings = new ArrayList();
   for (int s = 0; s < sigTypes.length; s++) sigStrings.add(sigTypes[s].getName());
   String[] sig = new String[sigTypes.length];
   sigStrings.toArray(sig);
   Object value = null;
   try {
     value = server.invoke(serverName, methodName, args, sig);
   } catch (UndeclaredThrowableException e) {
     System.out.println("getUndeclaredThrowable: " + e.getUndeclaredThrowable());
     throw e.getUndeclaredThrowable();
   }
   return value;
 }
  private void notifyCommand(final String message, final String cmd) throws Exception {
    if (TangoConnectionFactory.isMockMode()) {
      // We also send this back to the workbench.
      final MBeanServerConnection client = getRemoteClient();
      client.invoke(
          RemoteWorkbenchAgent.REMOTE_WORKBENCH,
          "notifyMockCommand",
          new Object[] {getName(), message, cmd},
          new String[] {String.class.getName(), String.class.getName(), String.class.getName()});

      // We also set this in this VM
      if (System.getProperty("eclipse.debug.session") == null)
        TangoConnectionFactory.notifyMockCommand(getName(), message, cmd);
    } else {
      throw new Exception("Cannot set Mock Values when not in mock mode!");
    }
  }
  private void setValue(String name, Object value) throws Exception {

    if (TangoConnectionFactory.isMockMode()) {
      // We also send this back to the workbench.
      final MBeanServerConnection client = getRemoteClient();
      client.invoke(
          RemoteWorkbenchAgent.REMOTE_WORKBENCH,
          "setMockMotorValue",
          new Object[] {name, value},
          new String[] {String.class.getName(), Object.class.getName()});

      // We also set this in this VM
      if (System.getProperty("eclipse.debug.session") == null)
        TangoConnectionFactory.setMockValue(name, value);
    } else {
      throw new Exception("Cannot set Mock Values when not in mock mode!");
    }
  }
  /**
   * Invokes the specified operationInfo in the given connection. The parameters follows the
   * MbeanServerConnection.invoke conventions;
   *
   * @param connectionConfiguration the connection context
   * @param objectName the ObjectName of the MBean
   * @param operationInfo The OperationInfo for this operation
   * @param parameterValues The parameterValues for the operation.
   * @param parameterSignatures The parameter signatures of the operation.
   */
  public void invokeOperation(
      IConnectionConfiguration connectionConfiguration,
      ObjectName objectName,
      MBeanOperationInfo operationInfo,
      List<String> parameterValues,
      List<String> parameterSignatures) {

    JMXExplorerEvent event;
    try {
      List<Object> parameterObjectValues = new ArrayList<Object>();
      for (int t = 0; t < parameterValues.size(); t++) {
        String textValue = parameterValues.get(t);
        Object value = convertStringValueToObjectValue(parameterSignatures.get(t), textValue);
        parameterObjectValues.add(value);
      }

      String[] parameterSignaturesString = new String[parameterSignatures.size()];
      Object result =
          mBeanServerConnection.invoke(
              objectName,
              operationInfo.getName(),
              parameterObjectValues.toArray(),
              parameterSignatures.toArray(parameterSignaturesString));

      event =
          new JMXExplorerEvent(
              connectionConfiguration,
              JMXExplorerEvent.INVOKE_OPERATION_RESULT,
              objectName,
              result,
              operationInfo);
    } catch (Throwable t) {
      Activator.getDefault().error("invokeOperation failed", t);
      event =
          new JMXExplorerEvent(
              connectionConfiguration,
              JMXExplorerEvent.INVOKE_OPERATION_ERROR,
              objectName,
              t,
              operationInfo);
    }
    jmxExplorerMediator.notifyObserversWithJMXEvent(event);
  }
Beispiel #23
0
  private Object invokeJMXMBeanOperation(
      String mBeanName, String operationName, Object[] params, String[] signature) {

    try {
      MBeanServerConnection mBeanServerConnection = getJMXConnection();
      return mBeanServerConnection.invoke(
          new ObjectName(mBeanName), operationName, params, signature);

    } catch (Exception e) {
      throw new RuntimeException(
          JMX_INVOKE_ERROR
              + mBeanName
              + ": "
              + operationName
              + " with arguments : "
              + Arrays.toString(params),
          e);
    }
  }
  public ServiceUsageMBeanUtils(
      MBeanServerConnection mbeanServer, ObjectName serviceManagementMBean, ServiceID serviceID)
      throws ManagementConsoleException {
    super();
    this.mbeanServer = mbeanServer;
    this.serviceID = serviceID;

    try {
      serviceUsageMBean =
          (ObjectName)
              mbeanServer.invoke(
                  serviceManagementMBean,
                  "getServiceUsageMBean",
                  new Object[] {serviceID},
                  new String[] {ServiceID.class.getName()});
    } catch (Exception e) {
      e.printStackTrace();
      throw new ManagementConsoleException(SleeManagementMBeanUtils.doMessage(e));
    }
  }
  @Test(groups = "wso2.esb", description = "JMS Consumer Test after pause")
  public void testJMSPause() throws Exception {

    // pause JMS Listener from JMXClient
    Set<ObjectInstance> objSet =
        mbsc.queryMBeans(
            new ObjectName("org.apache.axis2:Type=Transport,ConnectorName=jms-listener-*"), null);
    Iterator i = objSet.iterator();
    while (i.hasNext()) {
      ObjectInstance obj = (ObjectInstance) i.next();
      mbsc.invoke(obj.getObjectName(), "pause", null, null);
    }

    Thread.sleep(10000);
    assertTrue(stringExistsInLog("Listener paused"));

    // Put message in queue.
    sendMessage(msgAfter);
    Thread.sleep(10000);
    assertTrue(!stringExistsInLog(msgAfter));
  }
Beispiel #26
0
  /**
   * Stops the list of brokers.
   *
   * @param jmxConnection - connection to the mbean server
   * @param brokerBeans - broker mbeans to stop @throws Exception
   */
  protected void stopBrokers(MBeanServerConnection jmxConnection, Collection brokerBeans)
      throws Exception {
    ObjectName brokerObjName;
    for (Iterator i = brokerBeans.iterator(); i.hasNext(); ) {
      brokerObjName = ((ObjectInstance) i.next()).getObjectName();

      String brokerName = brokerObjName.getKeyProperty("brokerName");
      context.print("Stopping broker: " + brokerName);

      try {
        jmxConnection.invoke(
            brokerObjName, "terminateJVM", new Object[] {Integer.valueOf(0)}, new String[] {"int"});
        context.print("Succesfully stopped broker: " + brokerName);
      } catch (Exception e) {
        // TODO: Check exceptions throwned
        // System.out.println("Failed to stop broker: [ " + brokerName +
        // " ]. Reason: " + e.getMessage());
      }
    }

    closeJmxConnection();
  }
Beispiel #27
0
  public Object invokeMethod(String method, Object arguments) {
    Object[] argArray;
    if (arguments instanceof Object[]) {
      argArray = (Object[]) arguments;
    } else {
      argArray = new Object[] {arguments};
    }
    // Locate the specific method based on the name and number of parameters
    String operationKey = createOperationKey(method, argArray.length);
    String[] signature = operations.get(operationKey);

    if (signature != null) {
      try {
        return server.invoke(name, method, argArray, signature);
      } catch (MBeanException e) {
        throwExceptionWithTarget("Could not invoke method: " + method + ". Reason: ", e);
      } catch (Exception e) {
        throwException("Could not invoke method: " + method + ". Reason: ", e);
      }
      return null;
    } else {
      return super.invokeMethod(method, arguments);
    }
  }
Beispiel #28
0
  private static String invokeJmx(
      String ip,
      String port,
      String newPort,
      String objectName,
      String methodName,
      String[] arguments)
      throws MalformedURLException, IOException, MalformedObjectNameException,
          InstanceNotFoundException, IntrospectionException, ReflectionException, MBeanException {

    try {
      if ("other".equals(port)) {
        port = newPort;
      }

      JMXServiceURL address =
          new JMXServiceURL(
              "service:jmx:rmi://" + ip + "/jndi/rmi://" + ip + ":" + port + "/defaultConnector");
      JMXConnector connector = JMXConnectorFactory.connect(address);
      MBeanServerConnection mbs = connector.getMBeanServerConnection();

      ObjectName mxbeanName =
          new ObjectName(objectName); // com.taobao.wlb:id=testJmxMBean,type=mywlb

      MBeanInfo mbeanInfo = mbs.getMBeanInfo(mxbeanName);
      MBeanOperationInfo[] opeInfos = mbeanInfo.getOperations();
      for (MBeanOperationInfo o : opeInfos) {
        if (o.getName().equals(methodName)) {
          int length = o.getSignature().length;
          Object[] params = new Object[length];
          String[] typeNames = new String[length];
          for (int i = 0; i < length; i++) {
            if ("boolean".equals(o.getSignature()[i].getType())) {
              params[i] = Boolean.valueOf(arguments[i]);
            } else if ("int".equals(o.getSignature()[i].getType())) {
              params[i] = Integer.valueOf(arguments[i]);
            } else if ("java.lang.Integer".equals(o.getSignature()[i].getType())) {
              params[i] = Integer.valueOf(arguments[i]);
            } else if ("long".equals(o.getSignature()[i].getType())) {
              params[i] = Long.valueOf(arguments[i]);
            } else if ("java.lang.Long".equals(o.getSignature()[i].getType())) {
              params[i] = Long.valueOf(arguments[i]);
            } else if ("double".equals(o.getSignature()[i].getType())) {
              params[i] = Double.valueOf(arguments[i]);
            } else if ("java.lang.Double".equals(o.getSignature()[i].getType())) {
              params[i] = Double.valueOf(arguments[i]);
            } else {
              params[i] = arguments[i];
            }
            typeNames[i] = o.getSignature()[i].getType();
          }

          Object result = mbs.invoke(mxbeanName, methodName, params, typeNames);
          if (result == null) return null;
          return result.toString();
        }
      }

      return "Jmx对象中没有该方法";
    } catch (Exception e) {
      e.printStackTrace();

      return "执行JMX异常:" + e.getMessage();
    }
  }
 @Override
 public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature)
     throws InstanceNotFoundException, MBeanException, ReflectionException, IOException {
   checkConnection();
   return connection.invoke(name, operationName, params, signature);
 }
  @Nullable
  public Result invokeOperation(
      @Nonnull MBeanServerConnection mBeanServer,
      @Nonnull ObjectName on,
      @Nonnull String operationName,
      @Nonnull String... arguments)
      throws JMException, IOException {

    logger.debug("invokeOperation({},{}, {}, {})...", on, operationName, Arrays.asList(arguments));
    MBeanInfo mbeanInfo = mBeanServer.getMBeanInfo(on);

    List<MBeanOperationInfo> candidates = new ArrayList<MBeanOperationInfo>();
    for (MBeanOperationInfo mbeanOperationInfo : mbeanInfo.getOperations()) {
      if (mbeanOperationInfo.getName().equals(operationName)
          && mbeanOperationInfo.getSignature().length == arguments.length) {
        candidates.add(mbeanOperationInfo);
        logger.debug("Select matching operation {}", mbeanOperationInfo);
      } else {
        logger.trace("Ignore non matching operation {}", mbeanOperationInfo);
      }
    }
    if (candidates.isEmpty()) {
      throw new IllegalArgumentException(
          "Operation '"
              + operationName
              + "("
              + Strings2.join(arguments, ", ")
              + ")' NOT found on "
              + on);
    } else if (candidates.size() > 1) {
      throw new IllegalArgumentException(
          "More than 1 ("
              + candidates.size()
              + ") operation '"
              + operationName
              + "("
              + Strings2.join(arguments, ", ")
              + ")' found on '"
              + on
              + "': "
              + candidates);
    }
    MBeanOperationInfo beanOperationInfo = candidates.get(0);

    MBeanParameterInfo[] mbeanParameterInfos = beanOperationInfo.getSignature();

    List<String> signature = new ArrayList<String>();
    for (MBeanParameterInfo mbeanParameterInfo : mbeanParameterInfos) {
      signature.add(mbeanParameterInfo.getType());
    }

    Object[] convertedArguments = convertValues(arguments, signature);

    logger.debug("Invoke {}:{}({}) ...", on, operationName, Arrays.asList(convertedArguments));

    Object result =
        mBeanServer.invoke(on, operationName, convertedArguments, signature.toArray(new String[0]));

    if ("void".equals(beanOperationInfo.getReturnType()) && result == null) {
      result = "void";
    }

    logger.info(
        "Invoke {}:{}({}): {}", on, operationName, Arrays.asList(convertedArguments), result);

    String description =
        "Invoke operation "
            + on
            + ":"
            + operationName
            + "("
            + Strings2.join(convertedArguments, ", ")
            + "): "
            + Strings2.toString(result);
    return new Result(on, result, description);
  }