List of usage examples for javax.management MBeanOperationInfo getSignature
public MBeanParameterInfo[] getSignature()
Returns the list of parameters for this operation.
From source file:com.springsource.hq.plugin.tcserver.plugin.appmgmt.TomcatJmxApplicationManager.java
private boolean isTcRuntime250OrLater(String objectName, String operationName, int expected25OrLaterArgumentCount, Properties config) throws PluginException { try {//ww w . j a va 2 s.co m MBeanServerConnection mBeanServer = mxUtil.getMBeanServer(config); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(new ObjectName(objectName)); for (MBeanOperationInfo operationInfo : mBeanInfo.getOperations()) { if (operationName.equals(operationInfo.getName()) && expected25OrLaterArgumentCount == operationInfo.getSignature().length) { return true; } } return false; } catch (Exception e) { throw createPluginException(e); } }
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 w w w. j av a2 s . c om*/ 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:com.tesora.dve.tools.DVEConfigCLI.java
public void cmd_jmx_list_operations() throws PEException { checkJMXConnected();/*w w w . j a va 2 s. 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()); } }
From source file:com.tesora.dve.tools.DVEConfigCLI.java
public void cmd_jmx_invoke(Scanner scanner) throws PEException { checkJMXConnected();/*from ww w . j a v a 2 s . c o m*/ checkJMXDomain(); checkJMXMBean(); final String opName = scan(scanner, "operation"); // First lookup the operation to ensure it exists MBeanOperationInfo found = null; for (final MBeanOperationInfo operation : jmxMBeanInfo.getOperations()) { if (operation.getName().equals(opName)) { found = operation; break; } } if (found == null) { throw new PEException("'" + opName + "' isn't a valid operation on '" + jmxMBean + "'"); } final MBeanParameterInfo[] params = found.getSignature(); final Object[] paramO = params.length == 0 ? null : new Object[params.length]; final String[] paramT = params.length == 0 ? null : new String[params.length]; for (int i = 0; i < params.length; i++) { // For each parameter we expect to have a matching item in the // scanner final String val = scan(scanner, params[i].getName()); paramO[i] = jmxConnector.stringToObject(val, params[i].getType()); paramT[i] = params[i].getType(); } jmxConnector.invokeOperation(jmxMBean, found, paramO, paramT); }
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"); }//from w w w . jav a 2s. c om 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(); }