Example usage for javax.management MBeanOperationInfo getReturnType

List of usage examples for javax.management MBeanOperationInfo getReturnType

Introduction

In this page you can find the example usage for javax.management MBeanOperationInfo getReturnType.

Prototype

public String getReturnType() 

Source Link

Document

Returns the type of the method's return value.

Usage

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);/*from  w  ww .j a  v  a  2 s  .  c o  m*/
        out.put("description", att.getDescription());
        out.put("return-type", att.getReturnType());
        out.put("signature", getSig(att.getSignature()));

    }
    return outc;
}

From source file:com.clustercontrol.HinemosManagerCli.java

private void printMBeanInfo(MBeanInfo mbeanInfo) {
    MBeanAttributeInfo[] attributeInfos = mbeanInfo.getAttributes();
    System.out.println("Attributes:");
    for (MBeanAttributeInfo attributeInfo : attributeInfos) {
        System.out.println(String.format("\t%s: %s", attributeInfo.getName(), attributeInfo.getType()));
    }/*from w w w.  j  ava  2s  .co  m*/

    MBeanOperationInfo[] operationInfos = mbeanInfo.getOperations();
    System.out.println("Operations:");
    for (MBeanOperationInfo operationInfo : operationInfos) {
        MBeanParameterInfo[] paramInfos = operationInfo.getSignature();

        StringBuffer paramStr = new StringBuffer();
        for (MBeanParameterInfo paramInfo : paramInfos) {
            paramStr.append(paramInfo.getType() + ",");
        }
        if (paramStr.length() != 0) {
            paramStr.append(paramStr.substring(0, paramStr.length() - 1));
        }

        System.out.println(
                String.format("\t%s %s(%s)", operationInfo.getReturnType(), operationInfo.getName(), paramStr));
    }
}

From source file:org.rhq.plugins.jslee.ServiceSbbUsageParameterSetComponent.java

@Override
public Configuration loadResourceConfiguration() throws Exception {
    try {//ww w  .ja v  a2 s . co  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.sakaiproject.status.StatusServlet.java

protected void reportDetailedWebappStatus(HttpServletResponse response) throws Exception {
    PrintWriter pw = response.getWriter();

    for (ObjectName appName : findMBeans("*:j2eeType=WebModule,*")) {
        for (MBeanAttributeInfo mbai : mbs.getMBeanInfo(appName).getAttributes()) {
            pw.print(mbai.getName() + ",");
            pw.print(mbai.getType() + ",");
            pw.print(mbai.getDescription() + ",");
            pw.print(mbs.getAttribute(appName, mbai.getName()) + "\n");
        }/*  ww  w .  j  a  va 2 s . c  o m*/
        pw.print("\n");
        for (MBeanOperationInfo mboi : mbs.getMBeanInfo(appName).getOperations()) {
            pw.print(mboi.getName() + ",");
            pw.print(mboi.getReturnType() + ",");
            pw.print(mboi.getDescription() + "\n");
        }
        pw.print("\n\n");
    }
}

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  ww . j  a va  2s.  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:org.jolokia.handler.list.OperationDataUpdater.java

/** {@inheritDoc} */
@Override//from w w  w . j  a va2 s .  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.jumpmind.symmetric.JmxCommand.java

@Override
protected boolean executeWithOptions(final CommandLine line) throws Exception {
    if (line.hasOption(OPTION_LISTBEANS)) {
        execute(new IJmxTemplate<Object>() {
            @Override// w  w w.  j  a  v a2  s.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: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  ww  . j a  v 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();
}