Example usage for javax.management MBeanAttributeInfo getDescription

List of usage examples for javax.management MBeanAttributeInfo getDescription

Introduction

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

Prototype

public String getDescription() 

Source Link

Document

Returns the human-readable description of the feature.

Usage

From source file:org.apache.hadoop.hbase.util.JSONBean.java

private static void writeAttribute(final JsonGenerator jg, final MBeanServer mBeanServer, ObjectName oname,
        final boolean description, final MBeanAttributeInfo attr) throws IOException {
    if (!attr.isReadable()) {
        return;/*from w w w.j  a va  2  s. c  o m*/
    }
    String attName = attr.getName();
    if ("modelerType".equals(attName)) {
        return;
    }
    if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) {
        return;
    }
    String descriptionStr = description ? attr.getDescription() : null;
    Object value = null;
    try {
        value = mBeanServer.getAttribute(oname, attName);
    } catch (RuntimeMBeanException e) {
        // UnsupportedOperationExceptions happen in the normal course of business,
        // so no need to log them as errors all the time.
        if (e.getCause() instanceof UnsupportedOperationException) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Getting attribute " + attName + " of " + oname + " threw " + e);
            }
        } else {
            LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e);
        }
        return;
    } catch (RuntimeErrorException e) {
        // RuntimeErrorException happens when an unexpected failure occurs in getAttribute
        // for example https://issues.apache.org/jira/browse/DAEMON-120
        LOG.debug("getting attribute " + attName + " of " + oname + " threw an exception", e);
        return;
    } catch (AttributeNotFoundException e) {
        //Ignored the attribute was not found, which should never happen because the bean
        //just told us that it has this attribute, but if this happens just don't output
        //the attribute.
        return;
    } catch (MBeanException e) {
        //The code inside the attribute getter threw an exception so log it, and
        // skip outputting the attribute
        LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e);
        return;
    } catch (RuntimeException e) {
        //For some reason even with an MBeanException available to them Runtime exceptions
        //can still find their way through, so treat them the same as MBeanException
        LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e);
        return;
    } catch (ReflectionException e) {
        //This happens when the code inside the JMX bean (setter?? from the java docs)
        //threw an exception, so log it and skip outputting the attribute
        LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e);
        return;
    } catch (InstanceNotFoundException e) {
        //Ignored the mbean itself was not found, which should never happen because we
        //just accessed it (perhaps something unregistered in-between) but if this
        //happens just don't output the attribute.
        return;
    }

    writeAttribute(jg, attName, descriptionStr, value);
}

From source file:org.jolokia.handler.list.AttributeDataUpdater.java

/** {@inheritDoc} */
@Override//from   ww  w  . j a v  a 2  s . c  o  m
protected JSONObject extractData(MBeanInfo pMBeanInfo, String attribute) {
    JSONObject attrMap = new JSONObject();

    for (MBeanAttributeInfo attrInfo : pMBeanInfo.getAttributes()) {
        if (attribute == null || attrInfo.getName().equals(attribute)) {
            JSONObject map = new JSONObject();
            map.put(TYPE.getKey(), attrInfo.getType());
            map.put(DESCRIPTION.getKey(), attrInfo.getDescription());
            map.put(READ_WRITE.getKey(), Boolean.valueOf(attrInfo.isWritable() && attrInfo.isReadable()));
            attrMap.put(attrInfo.getName(), map);
        }
    }
    return attrMap;
}

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);// ww  w.  ja  v  a2  s.c om
        out.put("description", att.getDescription());
        out.put("type", att.getType());
    }
    return outc;
}

From source file:org.hyperic.hq.product.jmx.MxLiveDataPlugin.java

private Object queryMBeans(String pattern, Properties props) throws PluginException {

    MBeanServerConnection mServer;
    try {//from  www .j ava  2 s .c  om
        mServer = MxUtil.getMBeanServer(props);
    } catch (Exception e) {
        throw new PluginException("getMBeanServer(" + props.getProperty(MxUtil.PROP_JMX_URL) + "): " + e, e);
    }
    ObjectName query;
    try {
        query = new ObjectName(pattern);
    } catch (Exception e) {
        throw new PluginException("Invalid query '" + pattern + "': " + e);
    }
    Map res = new HashMap();
    try {
        Iterator beans = mServer.queryNames(query, null).iterator();
        while (beans.hasNext()) {
            ObjectName obj = (ObjectName) beans.next();
            Map bean = new HashMap();
            Map attrs = new LinkedHashMap();
            bean.put(PROP_ATTRIBUTE + "s", attrs);
            res.put(obj.toString(), bean);

            MBeanInfo info = mServer.getMBeanInfo(obj);
            MBeanAttributeInfo[] attrInfo = info.getAttributes();
            for (int i = 0; i < attrInfo.length; i++) {
                MBeanAttributeInfo mia = attrInfo[i];
                String name = mia.getName();
                Map attr = new HashMap();
                Object val;
                try {
                    val = mServer.getAttribute(obj, name);
                } catch (Exception e) {
                    continue; //XXX
                }

                if (val == null) {
                    val = "-";
                }
                attr.put("Value", val);
                attr.put("Description", mia.getDescription());
                attr.put("isWritable", new Boolean(mia.isWritable()));
                attrs.put(name, attr);
            }

            bean.put(PROP_METHOD + "s", info.getOperations());
        }
    } catch (Exception e) {
        throw new PluginException("Error in query '" + pattern + "': " + e, e);
    }

    return res;
}

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  ww  w  . j  a va2 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   ww  w. j  av  a  2 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.zabbix.gateway.JMXItemChecker.java

@Override
protected String getStringValue(String key) throws Exception {
    ZabbixItem item = new ZabbixItem(key);

    if (item.getKeyId().equals("jmx")) {
        if (2 != item.getArgumentCount())
            throw new ZabbixException("required key format: jmx[<object name>,<attribute name>]");

        ObjectName objectName = new ObjectName(item.getArgument(1));
        String attributeName = item.getArgument(2);
        String realAttributeName;
        String fieldNames = "";

        // Attribute name and composite data field names are separated by dots. On the other hand the
        // name may contain a dot too. In this case user needs to escape it with a backslash. Also the
        // backslash symbols in the name must be escaped. So a real separator is unescaped dot and
        // separatorIndex() is used to locate it.

        int sep = HelperFunctionChest.separatorIndex(attributeName);

        if (-1 != sep) {
            logger.trace("'{}' contains composite data", attributeName);

            realAttributeName = attributeName.substring(0, sep);
            fieldNames = attributeName.substring(sep + 1);
        } else//from  ww w .j a  v a  2s  .  co  m
            realAttributeName = attributeName;

        // unescape possible dots or backslashes that were escaped by user
        realAttributeName = HelperFunctionChest.unescapeUserInput(realAttributeName);

        logger.trace("attributeName:'{}'", realAttributeName);
        logger.trace("fieldNames:'{}'", fieldNames);

        return getPrimitiveAttributeValue(mbsc.getAttribute(objectName, realAttributeName), fieldNames);
    } else if (item.getKeyId().equals("jmx.discovery")) {
        ObjectName objectName = null;
        String attributeName = null;
        if (item.getArgumentCount() >= 1) {
            objectName = new ObjectName(item.getArgument(1));
        }

        if (item.getArgumentCount() >= 2) {
            attributeName = item.getArgument(2);
        }

        JSONArray counters = new JSONArray();

        logger.trace("attributeName = {}, item.getArgumentCount() = " + item.getArgumentCount(), attributeName);

        for (ObjectName name : mbsc.queryNames(objectName, null)) {
            logger.trace("discovered object '{}'", name);

            for (MBeanAttributeInfo attrInfo : mbsc.getMBeanInfo(name).getAttributes()) {
                logger.trace("discovered attribute '{}'", attrInfo.getName());

                if (!attrInfo.isReadable()) {
                    logger.trace("attribute not readable, skipping");
                    continue;
                }

                try {
                    if (null == attributeName || attrInfo.getName().equals(attributeName)) {
                        logger.trace("looking for attributes of primitive types");
                        String descr = (attrInfo.getName().equals(attrInfo.getDescription()) ? null
                                : attrInfo.getDescription());
                        findPrimitiveAttributes(counters, name, descr, attrInfo.getName(),
                                mbsc.getAttribute(name, attrInfo.getName()));
                    }
                } catch (Exception e) {
                    Object[] logInfo = { name, attrInfo.getName(), e };
                    logger.trace("processing '{},{}' failed", logInfo);
                }
            }
        }

        JSONObject mapping = new JSONObject();
        mapping.put(ItemChecker.JSON_TAG_DATA, counters);
        return mapping.toString(2);
    } else
        throw new ZabbixException("key ID '%s' is not supported", item.getKeyId());
}