List of usage examples for javax.management MBeanOperationInfo getName
public String getName()
From source file:cc.kune.kunecli.JMXUtils.java
public static Object doOperation(final String objectName, final String operation) { final List<VirtualMachineDescriptor> vms = VirtualMachine.list(); try {//from w w w.j a v a 2 s . c o m for (final VirtualMachineDescriptor vmd : vms) { final String id = vmd.id(); LOG.debug("VM id: " + id); final JMXServiceURL url = getURLForPid(id.trim()); final JMXConnector jmxc = JMXConnectorFactory.connect(url, null); final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); final ObjectName mbeanName = new ObjectName(objectName); MBeanInfo beanInfo; try { beanInfo = mbsc.getMBeanInfo(mbeanName); for (final MBeanOperationInfo currentOp : beanInfo.getOperations()) { if (currentOp.getName().equals(operation)) { LOG.debug("Doing operation '" + operation + "' over mbean: '" + objectName + "' with id: '" + id + "'."); final Object invoke = mbsc.invoke(mbeanName, currentOp.getName(), new Object[] {}, new String[] {}); return invoke; } } } catch (final InstanceNotFoundException e) { // Ok, operation not found in this VM or domain } } throw new RuntimeException("JMX operation not found"); } catch (final Exception e) { LOG.error("Error in jmx connection", e); } throw new RuntimeException("JMX operation failed"); }
From source file:org.jolokia.handler.list.OperationDataUpdater.java
/** {@inheritDoc} */ @Override/*w ww . ja va2s. c o m*/ protected JSONObject extractData(MBeanInfo pMBeanInfo, String pOperation) { JSONObject opMap = new JSONObject(); for (MBeanOperationInfo opInfo : pMBeanInfo.getOperations()) { if (pOperation == null || opInfo.getName().equals(pOperation)) { JSONObject map = new JSONObject(); JSONArray argList = new JSONArray(); for (MBeanParameterInfo paramInfo : opInfo.getSignature()) { JSONObject args = new JSONObject(); args.put(DESCRIPTION.getKey(), paramInfo.getDescription()); args.put(NAME.getKey(), paramInfo.getName()); args.put(TYPE.getKey(), paramInfo.getType()); argList.add(args); } map.put(ARGS.getKey(), argList); map.put(RETURN_TYPE.getKey(), opInfo.getReturnType()); map.put(DESCRIPTION.getKey(), opInfo.getDescription()); Object ops = opMap.get(opInfo.getName()); if (ops != null) { if (ops instanceof List) { // If it is already a list, simply add it to the end ((List) ops).add(map); } else if (ops instanceof Map) { // If it is a map, add a list with two elements // (the old one and the new one) JSONArray opList = new JSONArray(); opList.add(ops); opList.add(map); opMap.put(opInfo.getName(), opList); } else { throw new IllegalArgumentException( "Internal: list, addOperations: Expected Map or List, not " + ops.getClass()); } } else { // No value set yet, simply add the map as plain value opMap.put(opInfo.getName(), map); } } } return opMap; }
From source file:org.cloudfoundry.identity.varz.MBeanMap.java
@Override public Set<java.util.Map.Entry<String, Object>> entrySet() { if (!initialized && info != null) { MBeanAttributeInfo[] attributes = info.getAttributes(); for (MBeanAttributeInfo attribute : attributes) { String key = attribute.getName(); try { Object value = server.getAttribute(name, key); verySafePut(map, key, value); } catch (Exception e) { logger.trace("Cannot extract attribute: " + key); }/* w w w . ja v a 2s . com*/ } MBeanOperationInfo[] operations = info.getOperations(); for (MBeanOperationInfo operation : operations) { String key = operation.getName(); if (key.startsWith("get") && operation.getSignature().length == 0) { String attribute = VarzStringUtils.camelToUnderscore(key.substring(3)); if (map.containsKey(attribute)) { continue; } try { Object value = server.invoke(name, key, null, null); verySafePut(map, attribute, value); } catch (Exception e) { logger.trace("Cannot extract operation: " + key); } } } } return map.entrySet(); }
From source file:org.cloudfoundry.identity.statsd.MBeanMap.java
@Override public Set<java.util.Map.Entry<String, Object>> entrySet() { if (!initialized && info != null) { MBeanAttributeInfo[] attributes = info.getAttributes(); for (MBeanAttributeInfo attribute : attributes) { String key = attribute.getName(); try { Object value = server.getAttribute(name, key); verySafePut(map, key, value); } catch (Exception e) { logger.trace("Cannot extract attribute: " + key); }/*from w ww.j av a2s .c o m*/ } MBeanOperationInfo[] operations = info.getOperations(); for (MBeanOperationInfo operation : operations) { String key = operation.getName(); if (key.startsWith("get") && operation.getSignature().length == 0) { String attribute = StringUtils.camelToUnderscore(key.substring(3)); if (map.containsKey(attribute)) { continue; } try { Object value = server.invoke(name, key, null, null); verySafePut(map, attribute, value); } catch (Exception e) { logger.trace("Cannot extract operation: " + key); } } } } return map.entrySet(); }
From source file:org.cloudfoundry.identity.uaa.varz.MBeanMap.java
@Override public Set<java.util.Map.Entry<String, Object>> entrySet() { if (!initialized && info != null) { MBeanAttributeInfo[] attributes = info.getAttributes(); for (MBeanAttributeInfo attribute : attributes) { String key = attribute.getName(); try { Object value = server.getAttribute(name, key); verySafePut(map, key, value); } catch (Exception e) { logger.trace("Cannot extract attribute: " + key); }/*w ww. j a va 2s. c o m*/ } MBeanOperationInfo[] operations = info.getOperations(); for (MBeanOperationInfo operation : operations) { String key = operation.getName(); if (key.startsWith("get") && operation.getSignature().length == 0) { String attribute = MBeanMap.prettify(key.substring(3)); if (map.containsKey(attribute)) { continue; } try { Object value = server.invoke(name, key, null, null); verySafePut(map, attribute, value); } catch (Exception e) { logger.trace("Cannot extract operation: " + key); } } } } return map.entrySet(); }
From source file:org.jumpmind.symmetric.JmxCommand.java
@Override protected boolean executeWithOptions(final CommandLine line) throws Exception { if (line.hasOption(OPTION_LISTBEANS)) { execute(new IJmxTemplate<Object>() { @Override//from w w w .j av a 2s . c o m public Object execute(String engineName, MBeanServerConnection mbeanConn) throws Exception { Set<ObjectName> beanSet = mbeanConn.queryNames(null, null); for (ObjectName objectName : beanSet) { if (objectName.getDomain().startsWith("org.jumpmind.symmetric." + engineName)) { System.out.println(objectName.toString()); } } return null; } }); } else if (line.hasOption(OPTION_LISTMETHODS) || line.hasOption(OPTION_METHOD)) { if (line.hasOption(OPTION_BEAN)) { execute(new IJmxTemplate<Object>() { @Override public Object execute(String engineName, MBeanServerConnection mbeanConn) throws Exception { String beanName = line.getOptionValue(OPTION_BEAN); MBeanInfo info = mbeanConn.getMBeanInfo(new ObjectName(beanName)); if (info != null) { if (line.hasOption(OPTION_LISTMETHODS)) { MBeanOperationInfo[] operations = info.getOperations(); Map<String, MBeanOperationInfo> orderedMap = new TreeMap<String, MBeanOperationInfo>(); for (MBeanOperationInfo methodInfo : operations) { orderedMap.put(methodInfo.getName(), methodInfo); } for (MBeanOperationInfo methodInfo : orderedMap.values()) { System.out.print(methodInfo.getName() + "("); MBeanParameterInfo[] params = methodInfo.getSignature(); int index = 0; for (MBeanParameterInfo p : params) { if (index > 0) { System.out.print(", "); } System.out.print(p.getType() + " " + p.getName()); index++; } System.out.print(")"); if (methodInfo.getReturnType() != null && !methodInfo.getReturnType().equals("void")) { System.out.print(" : " + methodInfo.getReturnType()); } System.out.println(); } } else if (line.hasOption(OPTION_METHOD)) { String argsDelimiter = line.getOptionValue(OPTION_ARGS_DELIM); if (isBlank(argsDelimiter)) { argsDelimiter = ","; } else { argsDelimiter = argsDelimiter.trim(); } String methodName = line.getOptionValue(OPTION_METHOD); String[] args = null; if (line.hasOption(OPTION_ARGS)) { String argLine = line.getOptionValue(OPTION_ARGS); args = argsDelimiter == "," ? CsvUtils.tokenizeCsvData(argLine) : argLine.split(argsDelimiter); ; } else { args = new String[0]; } MBeanOperationInfo[] operations = info.getOperations(); for (MBeanOperationInfo methodInfo : operations) { MBeanParameterInfo[] paramInfos = methodInfo.getSignature(); if (methodInfo.getName().equals(methodName) && paramInfos.length == args.length) { String[] signature = new String[args.length]; Object[] objArgs = new Object[args.length]; int index = 0; for (MBeanParameterInfo paramInfo : paramInfos) { signature[index] = paramInfo.getType(); if (!paramInfo.getType().equals(String.class.getName())) { Class<?> clazz = Class.forName(paramInfo.getType()); Constructor<?> constructor = clazz.getConstructor(String.class); objArgs[index] = constructor.newInstance(args[index]); } else { objArgs[index] = args[index]; } index++; } Object returnValue = mbeanConn.invoke(new ObjectName(beanName), methodName, objArgs, signature); if (methodInfo.getReturnType() != null && !methodInfo.getReturnType().equals("void")) { System.out.println(returnValue); } System.exit(0); } } System.out.println("ERROR: Could not locate a JMX method named: " + methodName + " with " + args.length + " arguments on bean: " + beanName); System.exit(1); return null; } } else { System.out.println("ERROR: Could not locate a JMX bean with the name of: " + beanName); System.exit(1); } return null; } }); } else { System.out.println("ERROR: Must specifiy the --bean option."); System.exit(1); } } else { return false; } return true; }
From source file:org.rhq.plugins.jslee.ServiceSbbUsageParameterSetComponent.java
@Override public Configuration loadResourceConfiguration() throws Exception { try {//w ww. j av a 2 s . c o m Configuration config = new Configuration(); MBeanServerConnection connection = this.mbeanUtils.getConnection(); this.mbeanUtils.login(); // As an example, if a particular service has the name FooService, vendor FooCompany, and version 1.0, // then the Object Name of a ServiceUsageMBean for that service would be: // javax.slee.management.usage:type=ServiceUsage,serviceName="FooService", serviceVendor="FooCompany",serviceVersion="1.0" ObjectName serviceUsageON = new ObjectName(ServiceUsageMBean.BASE_OBJECT_NAME + ',' + ServiceUsageMBean.SERVICE_NAME_KEY + '=' + ObjectName.quote(serviceId.getName()) + ',' + ServiceUsageMBean.SERVICE_VENDOR_KEY + '=' + ObjectName.quote(serviceId.getVendor()) + ',' + ServiceUsageMBean.SERVICE_VERSION_KEY + '=' + ObjectName.quote(serviceId.getVersion())); ServiceUsageMBean serviceUsageMBean = (ServiceUsageMBean) MBeanServerInvocationHandler.newProxyInstance( connection, serviceUsageON, javax.slee.management.ServiceUsageMBean.class, false); PropertyList columnList = new PropertyList("usageParameter"); ObjectName sbbUsageON = null; if (usageParameterSetName != null && !usageParameterSetName.equals("<default>")) { sbbUsageON = serviceUsageMBean.getSbbUsageMBean(sbbId, usageParameterSetName); } else { sbbUsageON = serviceUsageMBean.getSbbUsageMBean(sbbId); } MBeanInfo usageInfo = connection.getMBeanInfo(sbbUsageON); for (MBeanOperationInfo operation : usageInfo.getOperations()) { String opName = operation.getName(); if (opName.startsWith("get")) { PropertyMap col = new PropertyMap("usageParameterDefinition"); col.put(new PropertySimple("usageParameterName", opName.replaceFirst("get", ""))); boolean isSampleType = operation.getReturnType().equals("javax.slee.usage.SampleStatistics"); col.put(new PropertySimple("usageParameterType", isSampleType ? "Sample" : "Counter")); Object value = connection.invoke(sbbUsageON, opName, new Object[] { false }, new String[] { "boolean" }); col.put(new PropertySimple("usageParameterValue", value)); columnList.add(col); } } config.put(columnList); return config; } finally { try { this.mbeanUtils.logout(); } catch (LoginException e) { if (log.isDebugEnabled()) { log.debug("Failed to logout from secured JMX", e); } } } }
From source file:org.jolokia.jmx.JsonDymamicMBeanImplTest.java
@Test public void checkMBeanInfo() throws Exception { MBeanInfo info = platformServer.getMBeanInfo(testName); MBeanAttributeInfo aInfo[] = info.getAttributes(); Map<String, MBeanAttributeInfo> attributes = new HashMap<String, MBeanAttributeInfo>(); for (MBeanAttributeInfo a : aInfo) { attributes.put(a.getName(), a);//from www. ja v a2s. c o m } assertEquals(attributes.get("Chili").getType(), String.class.getName()); assertEquals(attributes.get("Numbers").getType(), String.class.getName()); assertEquals(attributes.get("User").getType(), String.class.getName()); MBeanOperationInfo oInfo[] = info.getOperations(); Map<String, MBeanOperationInfo> ops = new HashMap<String, MBeanOperationInfo>(); for (MBeanOperationInfo o : oInfo) { ops.put(o.getName(), o); } assertEquals(ops.get("lookup").getReturnType(), String.class.getName()); assertEquals(ops.get("epoch").getReturnType(), "long"); assertEquals(ops.get("charTest").getReturnType(), "char"); MBeanParameterInfo p[] = ops.get("lookup").getSignature(); assertEquals(p[0].getType(), String.class.getName()); assertEquals(p[1].getType(), String.class.getName()); p = ops.get("epoch").getSignature(); assertEquals(p[0].getType(), String.class.getName()); p = ops.get("charTest").getSignature(); assertEquals(p[0].getType(), Character.class.getName()); }
From source file:FullThreadDump.java
private void parseMBeanInfo() throws IOException { try {/* w ww . j a v a 2 s . co m*/ MBeanOperationInfo[] mopis = server.getMBeanInfo(objname).getOperations(); // look for findDeadlockedThreads operations; boolean found = false; for (MBeanOperationInfo op : mopis) { if (op.getName().equals(findDeadlocksMethodName)) { found = true; break; } } if (!found) { // if findDeadlockedThreads operation doesn't exist, // the target VM is running on JDK 5 and details about // synchronizers and locks cannot be dumped. findDeadlocksMethodName = "findMonitorDeadlockedThreads"; canDumpLocks = false; } } catch (IntrospectionException e) { InternalError ie = new InternalError(e.getMessage()); ie.initCause(e); throw ie; } catch (InstanceNotFoundException e) { InternalError ie = new InternalError(e.getMessage()); ie.initCause(e); throw ie; } catch (ReflectionException e) { InternalError ie = new InternalError(e.getMessage()); ie.initCause(e); throw ie; } }
From source file:flens.query.JMXQuery.java
private Map<String, Object> getOpperations(MBeanInfo info) { Map<String, Object> outc = new HashMap<>(); MBeanOperationInfo[] atts = info.getOperations(); for (MBeanOperationInfo att : atts) { Map<String, Object> out = new HashMap<>(); outc.put(att.getName(), out); out.put("description", att.getDescription()); out.put("return-type", att.getReturnType()); out.put("signature", getSig(att.getSignature())); }/*from w w w .j a v a 2 s . c o m*/ return outc; }