List of usage examples for javax.management MBeanParameterInfo getName
public String getName()
From source file:org.jolokia.handler.list.OperationDataUpdater.java
/** {@inheritDoc} */ @Override/*from w ww . j av a 2 s . co 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:flens.query.JMXQuery.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private List getSig(MBeanParameterInfo[] signature) { List outc = new LinkedList<>(); for (MBeanParameterInfo att : signature) { Map<String, Object> out = new HashMap<>(); outc.add(out);/*from w w w. j a v a2 s . c om*/ out.put("name", att.getName()); out.put("description", att.getDescription()); out.put("type", att.getType()); } return outc; }
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 a v a 2 s . c om 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.fishwife.jrugged.spring.jmx.TestMBeanOperationInvoker.java
@Test public void testInvokeOperation() throws JMException { MBeanParameterInfo mockParameterInfo1 = createMock(MBeanParameterInfo.class); MBeanParameterInfo mockParameterInfo2 = createMock(MBeanParameterInfo.class); MBeanParameterInfo[] parameterInfoArray = new MBeanParameterInfo[] { mockParameterInfo1, mockParameterInfo2 };//w w w. j av a 2 s . c om expect(mockOperationInfo.getSignature()).andReturn(parameterInfoArray); String name1 = "name 1"; String type1 = "type 1"; expect(mockParameterInfo1.getType()).andReturn(type1); expect(mockParameterInfo1.getName()).andReturn(name1); String value1 = "value 1"; expect(mockValueConverter.convertParameterValue(name1, type1)).andReturn(value1); String name2 = "name 2"; String type2 = "type 2"; expect(mockParameterInfo2.getType()).andReturn(type2); expect(mockParameterInfo2.getName()).andReturn(name2); String value2 = "value 2"; expect(mockValueConverter.convertParameterValue(name2, type2)).andReturn(value2); String operationName = "some_operation_name"; expect(mockOperationInfo.getName()).andReturn(operationName); Object value = new Object(); expect(mockMBeanServer.invoke(eq(mockObjectName), eq(operationName), anyObject(String[].class), anyObject(String[].class))).andReturn(value); replay(mockMBeanServer, mockObjectName, mockOperationInfo, mockValueConverter, mockParameterInfo1, mockParameterInfo2); Map<String, String[]> parameterMap = new HashMap<String, String[]>(); parameterMap.put(name1, new String[] { value1 }); parameterMap.put(name2, new String[] { value2 }); Object invokeResult = invoker.invokeOperation(parameterMap); assertEquals(value, invokeResult); verify(mockMBeanServer, mockObjectName, mockOperationInfo, mockValueConverter, mockParameterInfo1, mockParameterInfo2); }
From source file:org.sakaiproject.status.StatusServlet.java
protected void reportAllMBeanDetails(HttpServletResponse response) throws Exception { PrintWriter pw = response.getWriter(); Set<ObjectInstance> allBeans = mbs.queryMBeans(null, null); SortedSet sortedBeanNames = new TreeSet(); for (ObjectInstance bean : allBeans) { sortedBeanNames.add(bean.getObjectName().toString()); }/*from ww w . ja va 2 s . c o m*/ for (Object beanName : sortedBeanNames) { pw.print(beanName.toString() + "\n"); ObjectName beanObjectName = new ObjectName(beanName.toString()); for (MBeanAttributeInfo mbai : mbs.getMBeanInfo(beanObjectName).getAttributes()) { pw.print(" "); pw.print(mbai.getName() + ","); pw.print(mbai.getType() + ","); pw.print(mbai.getDescription() + ","); pw.print(mbs.getAttribute(beanObjectName, mbai.getName()) + "\n"); } pw.print("\n"); for (MBeanOperationInfo mboi : mbs.getMBeanInfo(beanObjectName).getOperations()) { pw.print(" "); pw.print(mboi.getReturnType() + ","); pw.print(mboi.getName() + "("); for (MBeanParameterInfo mbpi : mboi.getSignature()) { pw.print(mbpi.getType() + " " + mbpi.getName() + ","); } pw.print("),"); pw.print(mboi.getDescription() + "\n"); } pw.print("\n-----------------------------\n\n"); } }
From source file:net.sbbi.upnp.jmx.UPNPMBeanService.java
private String getDeviceSSDP(MBeanInfo info) throws IllegalArgumentException { MBeanOperationInfo[] ops = info.getOperations(); MBeanAttributeInfo[] atts = info.getAttributes(); if ((ops == null || ops.length == 0) && (atts == null || atts.length == 0)) { throw new IllegalArgumentException( "MBean has no operation and no attribute and cannot be exposed as an UPNP device, provide at least one attribute"); }/* w ww .jav a 2 s .c o m*/ Set deployedActionNames = new HashSet(); operationsStateVariables = new HashMap(); StringBuffer rtrVal = new StringBuffer(); rtrVal.append("<?xml version=\"1.0\" ?>\r\n"); rtrVal.append("<scpd xmlns=\"urn:schemas-upnp-org:service-1-0\">\r\n"); rtrVal.append("<specVersion><major>1</major><minor>0</minor></specVersion>\r\n"); if (ops != null && ops.length > 0) { rtrVal.append("<actionList>\r\n"); for (int i = 0; i < ops.length; i++) { MBeanOperationInfo op = ops[i]; StringBuffer action = new StringBuffer(); if (deployedActionNames.contains(op.getName())) { log.debug("The " + op.getName() + " is allready deplyoed and cannot be reused, skipping operation deployment"); continue; } action.append("<action>\r\n"); action.append("<name>"); action.append(op.getName()); action.append("</name>\r\n"); action.append("<argumentList>\r\n"); // output argument action.append("<argument>\r\n"); action.append("<name>"); // TODO handle specific output vars String outVarName = op.getName() + "_out"; String actionOutDataType = ServiceStateVariable.getUPNPDataTypeMapping(op.getReturnType()); if (actionOutDataType == null) actionOutDataType = ServiceStateVariableTypes.STRING; action.append(outVarName); action.append("</name>\r\n"); action.append("<direction>out</direction>\r\n"); action.append("<relatedStateVariable>"); action.append(outVarName); action.append("</relatedStateVariable>\r\n"); action.append("</argument>\r\n"); // handle now for all input argument boolean nonPrimitiveInputType = false; boolean duplicatedInputVarname = false; Map operationsInputStateVariables = new HashMap(); if (op.getSignature() != null) { for (int z = 0; z < op.getSignature().length; z++) { MBeanParameterInfo param = op.getSignature()[z]; // do some sanity checks String actionInDataType = ServiceStateVariable.getUPNPDataTypeMapping(param.getType()); if (actionInDataType == null) { nonPrimitiveInputType = true; log.debug("The " + param.getType() + " type is not an UPNP compatible data type, use only primitives"); break; } String inVarName = param.getName(); // check that if the name does allready exists it // has the same type String existing = (String) operationsStateVariables.get(inVarName); if (existing != null && !existing.equals(actionInDataType)) { String msg = "The operation " + op.getName() + " " + inVarName + " parameter already exists for another method with another data type (" + existing + ") either match the data type or change the parameter name" + " in you MBeanParameterInfo object for this operation"; duplicatedInputVarname = true; log.debug(msg); break; } action.append("<argument>\r\n"); action.append("<name>"); operationsInputStateVariables.put(inVarName, actionInDataType); action.append(inVarName); action.append("</name>\r\n"); action.append("<direction>in</direction>\r\n"); action.append("<relatedStateVariable>"); action.append(inVarName); action.append("</relatedStateVariable>\r\n"); action.append("</argument>\r\n"); } } action.append("</argumentList>\r\n"); action.append("</action>\r\n"); // finally the action is only added to the UPNP SSDP if no problems have been detected // with the input parameters type and names. if (!nonPrimitiveInputType && !duplicatedInputVarname) { operationsStateVariables.putAll(operationsInputStateVariables); operationsStateVariables.put(outVarName, actionOutDataType); rtrVal.append(action.toString()); deployedActionNames.add(op.getName()); } } rtrVal.append("</actionList>\r\n"); } else { rtrVal.append("<actionList/>\r\n"); } // now append the operation created state vars rtrVal.append("<serviceStateTable>\r\n"); for (Iterator i = operationsStateVariables.keySet().iterator(); i.hasNext();) { String name = (String) i.next(); String type = (String) operationsStateVariables.get(name); // TODO handle sendevents with mbean notifications ??? // TODO handle defaultValue and allowedValueList values rtrVal.append("<stateVariable sendEvents=\"no\">\r\n"); rtrVal.append("<name>"); rtrVal.append(name); rtrVal.append("</name>\r\n"); rtrVal.append("<dataType>"); rtrVal.append(type); rtrVal.append("</dataType>\r\n"); rtrVal.append("</stateVariable>\r\n"); } if (atts != null && atts.length > 0) { for (int i = 0; i < atts.length; i++) { MBeanAttributeInfo att = atts[i]; if (att.isReadable()) { rtrVal.append("<stateVariable sendEvents=\"no\">\r\n"); rtrVal.append("<name>"); rtrVal.append(att.getName()); rtrVal.append("</name>\r\n"); rtrVal.append("<dataType>"); // TODO check if this works String stateVarType = ServiceStateVariable.getUPNPDataTypeMapping(att.getType()); if (stateVarType == null) stateVarType = ServiceStateVariableTypes.STRING; rtrVal.append(stateVarType); rtrVal.append("</dataType>\r\n"); rtrVal.append("</stateVariable>\r\n"); } } } rtrVal.append("</serviceStateTable>\r\n"); rtrVal.append("</scpd>"); return rtrVal.toString(); }
From source file:com.tesora.dve.tools.DVEConfigCLI.java
public void cmd_jmx_list_operations() throws PEException { checkJMXConnected();/* ww w. j a va 2s . co m*/ checkJMXDomain(); checkJMXMBean(); for (final MBeanOperationInfo operation : jmxMBeanInfo.getOperations()) { final String name = operation.getName(); final StringBuilder sParam = new StringBuilder(); for (final MBeanParameterInfo param : operation.getSignature()) { if (sParam.length() > 0) { sParam.append(", "); } sParam.append(formatType(param.getType())).append(" ").append(param.getName()); } final StringBuilder builder = new StringBuilder(); println(builder.append(name).append("(").append(sParam.toString()).append(")").toString()); } }