Example usage for javax.management MBeanAttributeInfo getType

List of usage examples for javax.management MBeanAttributeInfo getType

Introduction

In this page you can find the example usage for javax.management MBeanAttributeInfo getType.

Prototype

public String getType() 

Source Link

Document

Returns the class name of the attribute.

Usage

From source file:flens.query.JMXQuery.java

private Map<String, Object> getAttributes(MBeanInfo info) {
    Map<String, Object> outc = new HashMap<>();
    MBeanAttributeInfo[] atts = info.getAttributes();
    for (MBeanAttributeInfo att : atts) {
        Map<String, Object> out = new HashMap<>();
        outc.put(att.getName(), out);/*from  w  w  w  .  j a v  a  2 s .  com*/
        out.put("description", att.getDescription());
        out.put("type", att.getType());
    }
    return outc;
}

From source file:org.mc4j.ems.impl.jmx.connection.bean.DMBean.java

public List<EmsAttribute> refreshAttributes() {
    if (info == null)
        loadSynchronous();//from   w  w  w.  j av  a 2 s.  c o m

    MBeanAttributeInfo[] infos = new MBeanAttributeInfo[0];
    try {
        infos = this.info.getAttributes();
    } catch (RuntimeException e) {
        // If this throws an exception, there's a good chance our cached
    }

    // MUST be careful to only ask for types that we know we have
    // otherwise the RMI call will fail and we will get no data.
    List<String> nameList = new ArrayList<String>();
    for (MBeanAttributeInfo info : infos) {
        try {
            findType(info.getType());
            // If we know the type, add it to the list
            nameList.add(info.getName());
        } catch (ClassNotFoundException cnfe) {
            log.info("Can't load attribute type of [" + info.getName()
                    + "] because class not locally available");
        }
    }

    return refreshAttributes(nameList);
}

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");
        }//from   www.j  a  v  a 2  s .  com
        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  w w  .  j  a  v 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:org.echocat.jemoni.carbon.jmx.Jmx2CarbonBridge.java

@Nullable
protected AttributeDefinition findDefinitionFor(@Nonnull ObjectName objectName,
        @Nonnull MBeanAttributeInfo info, @Nonnull String name, @Nullable OpenType<?> openType) {
    final AttributeDefinition result;
    if (openType instanceof SimpleType) {
        result = findDefinitionFor(objectName, name, (SimpleType<?>) openType);
    } else if (openType instanceof CompositeType) {
        result = findDefinitionFor(objectName, info, name, (CompositeType) openType);
    } else {//from   w ww.  j  a  v  a2 s.c o m
        final String typeName = info.getType();
        if (typeName != null && typeName.startsWith("java.")) {
            final Class<?> type = tryLoadClassBy(typeName);
            if (type != null && (Number.class.isAssignableFrom(type) || Boolean.class.equals(type)
                    || Character.class.equals(type))) {
                result = new AttributeDefinition(objectName, name, type);
            } else {
                result = null;
            }
        } else {
            result = null;
        }
    }
    return result;
}

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");
    }/*ww w. j av  a2 s.co 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:org.opennms.tools.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection,
        String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans) {

    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: "
            + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans);
    JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig();
    JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection();

    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);/*from   www .j  a  v  a 2  s  . c om*/
    xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection);
    xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans());

    if (runStandardVmBeans) {
        ignores.clear();
    } else {
        ignores.addAll(standardVmBeans);
    }

    try {
        for (String domainName : mBeanServerConnection.getDomains()) {

            // just domains that are relevant for the service
            if (!ignores.contains(domainName)) {
                logger.debug("domain: " + domainName);

                // for all mBeans of the actual domain
                for (ObjectInstance jmxObjectInstance : mBeanServerConnection
                        .queryMBeans(new ObjectName(domainName + ":*"), null)) {
                    Mbean xmlMbean = xmlObjectFactory.createMbean();
                    xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString());
                    String typeAndOthers = StringUtils
                            .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "=");
                    xmlMbean.setName(domainName + "." + typeAndOthers);

                    logger.debug("\t" + jmxObjectInstance.getObjectName());

                    MBeanInfo jmxMbeanInfo;
                    try {
                        jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName());
                    } catch (InstanceNotFoundException e) {
                        logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (IntrospectionException e) {
                        logger.error("IntrospectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (ReflectionException e) {
                        logger.error("ReflectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (Throwable e) {
                        logger.error(
                                "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    }

                    logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName());

                    for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) {

                        // process just readable mbeans
                        if (jmxBeanAttributeInfo.isReadable()) {
                            // precess writable mbeans if run writable mbeans is set
                            if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) {

                                logger.debug("Check mBean: '{}', attribute: '{}'",
                                        jmxObjectInstance.getObjectName().toString(),
                                        jmxBeanAttributeInfo.getName());
                                logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(),
                                        jmxBeanAttributeInfo.getType());

                                // check for CompositeData
                                if ("javax.management.openmbean.CompositeData"
                                        .equals(jmxBeanAttributeInfo.getType())) {
                                    logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName());
                                    CompAttrib compAttrib = createCompAttrib(mBeanServerConnection,
                                            jmxObjectInstance, jmxBeanAttributeInfo);
                                    if (compAttrib != null) {
                                        logger.debug("xmlMbean got CompAttrib");
                                        xmlMbean.getCompAttrib().add(compAttrib);
                                    }
                                }

                                if (numbers.contains(jmxBeanAttributeInfo.getType())) {
                                    Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                                    logger.debug("Added MBean: '{}' Added attribute: '{}'",
                                            xmlMbean.getObjectname(),
                                            xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias());
                                    xmlMbean.getAttrib().add(xmlJmxAttribute);
                                }
                            }
                        }
                    }

                    if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) {
                        xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
                    } else {
                        logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes.");
                    }
                }
            } else {
                logger.debug("ignored: " + domainName);
            }
        }

    } catch (MalformedObjectNameException e) {
        logger.error("MalformedObjectNameException '{}'", e.getMessage());
    } catch (IOException e) {
        logger.error("IOException '{}'", e.getMessage());
    }

    return xmlJmxDatacollectionConfig;
}

From source file:org.opennms.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection,
        String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans,
        Map<String, String> dictionary) {

    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: "
            + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans + "\n dictionary" + dictionary);
    nameCutter.setDictionary(dictionary);
    JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig();
    JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection();

    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);//from w  ww.j  ava  2s.co  m
    xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection);
    xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans());

    if (runStandardVmBeans) {
        ignores.clear();
    } else {
        ignores.addAll(standardVmBeans);
    }

    try {
        for (String domainName : mBeanServerConnection.getDomains()) {

            // just domains that are relevant for the service
            if (!ignores.contains(domainName)) {
                logger.debug("domain: " + domainName);

                // for all mBeans of the actual domain
                for (ObjectInstance jmxObjectInstance : mBeanServerConnection
                        .queryMBeans(new ObjectName(domainName + ":*"), null)) {
                    Mbean xmlMbean = xmlObjectFactory.createMbean();
                    xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString());
                    String typeAndOthers = StringUtils
                            .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "=");
                    xmlMbean.setName(domainName + "." + typeAndOthers);

                    logger.debug("\t" + jmxObjectInstance.getObjectName());

                    MBeanInfo jmxMbeanInfo;
                    try {
                        jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName());
                    } catch (InstanceNotFoundException e) {
                        logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (IntrospectionException e) {
                        logger.error("IntrospectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (ReflectionException e) {
                        logger.error("ReflectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (Throwable e) {
                        logger.error(
                                "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    }

                    logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName());

                    for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) {

                        // process just readable mbeans
                        if (jmxBeanAttributeInfo.isReadable()) {
                            // precess writable mbeans if run writable mbeans is set
                            if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) {

                                logger.debug("Check mBean: '{}', attribute: '{}'",
                                        jmxObjectInstance.getObjectName().toString(),
                                        jmxBeanAttributeInfo.getName());
                                logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(),
                                        jmxBeanAttributeInfo.getType());

                                // check for CompositeData
                                if ("javax.management.openmbean.CompositeData"
                                        .equals(jmxBeanAttributeInfo.getType())) {
                                    logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName());
                                    CompAttrib compAttrib = createCompAttrib(mBeanServerConnection,
                                            jmxObjectInstance, jmxBeanAttributeInfo);
                                    if (compAttrib != null) {
                                        logger.debug("xmlMbean got CompAttrib");
                                        xmlMbean.getCompAttrib().add(compAttrib);
                                    }
                                }

                                if (numbers.contains(jmxBeanAttributeInfo.getType())) {
                                    Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                                    logger.debug("Added MBean: '{}' Added attribute: '{}'",
                                            xmlMbean.getObjectname(),
                                            xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias());
                                    xmlMbean.getAttrib().add(xmlJmxAttribute);
                                }
                            }
                        }
                    }

                    if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) {
                        xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
                    } else {
                        logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes.");
                    }
                }
            } else {
                logger.debug("ignored: " + domainName);
            }
        }

    } catch (MalformedObjectNameException e) {
        logger.error("MalformedObjectNameException '{}'", e.getMessage());
    } catch (IOException e) {
        logger.error("IOException '{}'", e.getMessage());
    }

    return xmlJmxDatacollectionConfig;
}

From source file:org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection,
        String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans,
        Map<String, String> dictionary) {

    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: "
            + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans + "\n dictionary" + dictionary);
    nameCutter.setDictionary(dictionary);
    JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig();
    JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection();

    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);/*from  w  w  w . j a v a 2 s .c  o m*/
    xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection);
    xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans());

    if (runStandardVmBeans) {
        ignores.clear();
    } else {
        ignores.addAll(standardVmBeans);
    }

    try {
        String[] domains = mBeanServerConnection.getDomains();
        logger.info("Found " + domains.length + " domains");
        logger.info("domains: " + Arrays.toString(domains));
        for (String domainName : domains) {

            // just domains that are relevant for the service
            if (!ignores.contains(domainName)) {
                logger.info("domain: " + domainName);

                // for all mBeans of the actual domain
                for (ObjectInstance jmxObjectInstance : mBeanServerConnection
                        .queryMBeans(new ObjectName(domainName + ":*"), null)) {
                    Mbean xmlMbean = xmlObjectFactory.createMbean();
                    xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString());
                    String typeAndOthers = StringUtils
                            .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "=");
                    xmlMbean.setName(domainName + "." + typeAndOthers);

                    logger.debug("\t" + jmxObjectInstance.getObjectName());

                    MBeanInfo jmxMbeanInfo;
                    try {
                        jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName());
                    } catch (InstanceNotFoundException e) {
                        logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (IntrospectionException e) {
                        logger.error("IntrospectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (ReflectionException e) {
                        logger.error("ReflectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (Throwable e) {
                        logger.error(
                                "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    }

                    logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName());

                    for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) {

                        // process just readable mbeans
                        if (jmxBeanAttributeInfo.isReadable()) {
                            // precess writable mbeans if run writable
                            // mbeans is set
                            if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) {

                                logger.debug("Check mBean: '{}', attribute: '{}'",
                                        jmxObjectInstance.getObjectName().toString(),
                                        jmxBeanAttributeInfo.getName());
                                logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(),
                                        jmxBeanAttributeInfo.getType());

                                // check for CompositeData
                                if ("javax.management.openmbean.CompositeData"
                                        .equals(jmxBeanAttributeInfo.getType())) {
                                    logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName());
                                    CompAttrib compAttrib = createCompAttrib(mBeanServerConnection,
                                            jmxObjectInstance, jmxBeanAttributeInfo);
                                    if (compAttrib != null) {
                                        logger.debug("xmlMbean got CompAttrib");
                                        xmlMbean.getCompAttrib().add(compAttrib);
                                    }
                                }

                                if (numbers.contains(jmxBeanAttributeInfo.getType())) {
                                    Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                                    logger.debug("Added MBean: '{}' Added attribute: '{}'",
                                            xmlMbean.getObjectname(),
                                            xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias());
                                    xmlMbean.getAttrib().add(xmlJmxAttribute);
                                }
                            }
                        }
                    }

                    if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) {
                        xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
                    } else {
                        logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes.");
                    }
                }
            } else {
                logger.debug("ignored: " + domainName);
            }
        }

    } catch (MalformedObjectNameException e) {
        logger.error("MalformedObjectNameException '{}'", e.getMessage());
    } catch (IOException e) {
        logger.error("IOException '{}'", e.getMessage());
    }
    logger.debug("finish collection!");
    return xmlJmxDatacollectionConfig;
}

From source file:com.cyberway.issue.crawler.admin.CrawlJob.java

protected Object getCrawlOrderAttribute(final String attribute_name, final ComplexType ct)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    String subName = attribute_name.startsWith("/") ? attribute_name.substring(1) : attribute_name;
    int index = subName.indexOf("/");
    if (index <= 0) {
        MBeanAttributeInfo info = ct.getAttributeInfo(subName);
        // Special handling for TextField.
        return info.getType().equals(TextField.class.getName()) ? ct.getAttribute(subName).toString()
                : ct.getAttribute(subName);
    }/*  w  w  w. ja v a  2  s  .co m*/
    return getCrawlOrderAttribute(subName.substring(index + 1),
            (ComplexType) ct.getAttribute(subName.substring(0, index)));
}