Example usage for javax.management MBeanInfo getAttributes

List of usage examples for javax.management MBeanInfo getAttributes

Introduction

In this page you can find the example usage for javax.management MBeanInfo getAttributes.

Prototype

public MBeanAttributeInfo[] getAttributes() 

Source Link

Document

Returns the list of attributes exposed for management.

Usage

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

public static OperationParams getAttributeParams(MBeanInfo info, String method, Object args[])
        throws PluginException {

    if (method.startsWith("set") || method.startsWith("get")) {
        method = method.substring(3);//  www  .java  2 s  . c  o  m
    }

    MBeanAttributeInfo[] attrs = info.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
        MBeanAttributeInfo attr = attrs[i];
        if (!attr.getName().equals(method)) {
            continue;
        }

        String sig = attr.getType();
        if (!hasConverter(sig)) {
            String msg = "Cannot convert String argument to " + sig;
            throw new PluginException(msg);
        }

        OperationParams params = new OperationParams();
        Object value = null;
        try {
            if (args.length > 0) {
                value = convert(sig, (String) args[0]);
            }
        } catch (Exception e) {
            String msg = "Exception converting param '" + args[0] + "' to type '" + sig + "'";
            throw new PluginException(msg + ": " + e);
        }
        if (value != null) {
            params.arguments = new Object[] { value };
        }
        params.isAttribute = true;
        return params;
    }

    return null;
}

From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java

/**
 * Dumps the details of a single MBean./*from   w  ww  .  jav a2s .  c o m*/
 * 
 * @param connection
 *            the server connection (or server itself)
 * @param objectName
 *            the object name
 * @param out
 *            PrintWriter to write the output to
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws JMException
 *             Signals a JMX error
 */
public static void printMBeanInfo(MBeanServerConnection connection, ObjectName objectName, PrintWriter out,
        String attributeName) throws IOException, JMException {
    Map<String, Object> attributes = new TreeMap<String, Object>();
    MBeanInfo info = connection.getMBeanInfo(objectName);
    attributes.put("** Object Name", objectName.toString());
    attributes.put("** Object Type", info.getClassName());

    if (StringUtils.isNotBlank(attributeName)) {
        Object value;
        try {
            value = connection.getAttribute(objectName, attributeName);
        } catch (Exception e) {
            value = JmxDumpUtil.UNREADABLE_VALUE;
        }
        outputValue(out, value, 10);
    } else {

        for (MBeanAttributeInfo element : info.getAttributes()) {
            Object value;
            if (element.isReadable()) {
                try {
                    value = connection.getAttribute(objectName, element.getName());
                } catch (Exception e) {
                    value = JmxDumpUtil.UNREADABLE_VALUE;
                }
            } else {
                value = JmxDumpUtil.UNREADABLE_VALUE;
            }
            attributes.put(element.getName(), value);
        }
        tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0);
    }
}

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

/** {@inheritDoc} */
@Override/*from  ww  w .  j a v a2s .  co  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: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 av a2s  . 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:com.ecyrd.jspwiki.ui.admin.SimpleAdminBean.java

/**
 *  By default, this method creates a blob of HTML, listing
 *  all the attributes which can be read or written to.  If the
 *  attribute is read-only, a readonly input widget is created.
 *  The value is determined by the toString() method of the attribute.
 *///  w w w.j  a v a 2 s . co m
public String doGet(WikiContext context) {
    MBeanInfo info = getMBeanInfo();
    MBeanAttributeInfo[] attributes = info.getAttributes();
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < attributes.length; i++) {
        sb.append("<div class='block'>\n");

        sb.append("<label>" + StringUtils.capitalize(attributes[i].getName()) + "</label>\n");

        try {
            Object value = getAttribute(attributes[i].getName());
            if (attributes[i].isWritable()) {
                sb.append("<input type='text' name='question' size='30' value='" + value + "' />\n");
            } else {
                sb.append("<input type='text' class='readonly' readonly='true' size='30' value='" + value
                        + "' />\n");
            }
        } catch (Exception e) {
            sb.append("Exception: " + e.getMessage());
        }

        sb.append("<div class='description'>" + attributes[i].getDescription() + "</div>\n");

        sb.append("</div>\n");
    }
    return sb.toString();
}

From source file:org.apache.streams.jackson.DatumStatusCounterDeserializer.java

@Override
public DatumStatusCounterBroadcast deserialize(JsonParser jsonParser,
        DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    try {//  www . ja v  a2s.  com
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();

        DatumStatusCounterBroadcast datumStatusCounterBroadcast = new DatumStatusCounterBroadcast();
        JsonNode attributes = jsonParser.getCodec().readTree(jsonParser);

        ObjectName name = new ObjectName(attributes.get("canonicalName").asText());
        MBeanInfo info = server.getMBeanInfo(name);
        datumStatusCounterBroadcast.setName(name.toString());

        for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) {
            try {
                switch (attribute.getName()) {
                case "Failed":
                    datumStatusCounterBroadcast
                            .setFailed((boolean) server.getAttribute(name, attribute.getName()));
                    break;
                case "Passed":
                    datumStatusCounterBroadcast
                            .setPassed((boolean) server.getAttribute(name, attribute.getName()));
                    break;
                }
            } catch (Exception e) {
                LOGGER.error("Exception trying to deserialize DatumStatusCounterBroadcast object: {}", e);
            }
        }

        return datumStatusCounterBroadcast;
    } catch (Exception e) {
        LOGGER.error("Exception trying to deserialize DatumStatusCounterBroadcast object: {}", e);
        return null;
    }
}

From source file:org.apache.streams.jackson.MemoryUsageDeserializer.java

@Override
public MemoryUsageBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    try {/*ww  w .  ja v a2  s .  c o  m*/
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();

        MemoryUsageBroadcast memoryUsageBroadcast = new MemoryUsageBroadcast();
        JsonNode attributes = jsonParser.getCodec().readTree(jsonParser);

        ObjectName name = new ObjectName(attributes.get("canonicalName").asText());
        MBeanInfo info = server.getMBeanInfo(name);
        memoryUsageBroadcast.setName(name.toString());

        for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) {
            switch (attribute.getName()) {
            case "Verbose":
                memoryUsageBroadcast.setVerbose((boolean) server.getAttribute(name, attribute.getName()));
                break;
            case "ObjectPendingFinalizationCount":
                memoryUsageBroadcast.setObjectPendingFinalizationCount(
                        Long.parseLong(server.getAttribute(name, attribute.getName()).toString()));
                break;
            case "HeapMemoryUsage":
                memoryUsageBroadcast.setHeapMemoryUsage(
                        (Long) ((CompositeDataSupport) server.getAttribute(name, attribute.getName()))
                                .get("used"));
                break;
            case "NonHeapMemoryUsage":
                memoryUsageBroadcast.setNonHeapMemoryUsage(
                        (Long) ((CompositeDataSupport) server.getAttribute(name, attribute.getName()))
                                .get("used"));
                break;
            }
        }

        return memoryUsageBroadcast;
    } catch (Exception e) {
        LOGGER.error("Exception trying to deserialize MemoryUsageDeserializer object: {}", e);
        return null;
    }
}

From source file:com.lmig.cf.metrics.opsmetrics.OpsMetrics.java

private List<String> getAttributeNames(MBeanServerConnection connection, ObjectInstance objectInstance)
        throws Exception {
    MBeanInfo mbeanInfo = connection.getMBeanInfo(objectInstance.getObjectName());
    MBeanAttributeInfo[] attributes = mbeanInfo.getAttributes();
    return Arrays.asList(attributes).stream().map(attr -> attr.getName()).collect(Collectors.toList());
}

From source file:org.apache.streams.jackson.ThroughputQueueDeserializer.java

@Override
public ThroughputQueueBroadcast deserialize(JsonParser jsonParser,
        DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    try {/*from  w ww.ja  va2  s .  c om*/
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();

        ThroughputQueueBroadcast throughputQueueBroadcast = new ThroughputQueueBroadcast();
        JsonNode attributes = jsonParser.getCodec().readTree(jsonParser);

        ObjectName name = new ObjectName(attributes.get("canonicalName").asText());
        MBeanInfo info = server.getMBeanInfo(name);
        throughputQueueBroadcast.setName(name.toString());

        for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) {
            try {
                switch (attribute.getName()) {
                case "CurrentSize":
                    throughputQueueBroadcast
                            .setCurrentSize((long) server.getAttribute(name, attribute.getName()));
                    break;
                case "AvgWait":
                    throughputQueueBroadcast
                            .setAvgWait((double) server.getAttribute(name, attribute.getName()));
                    break;
                case "MaxWait":
                    throughputQueueBroadcast.setMaxWait((long) server.getAttribute(name, attribute.getName()));
                    break;
                case "Removed":
                    throughputQueueBroadcast.setRemoved((long) server.getAttribute(name, attribute.getName()));
                    break;
                case "Added":
                    throughputQueueBroadcast.setAdded((long) server.getAttribute(name, attribute.getName()));
                    break;
                case "Throughput":
                    throughputQueueBroadcast
                            .setThroughput((double) server.getAttribute(name, attribute.getName()));
                    break;
                }
            } catch (Exception e) {
                LOGGER.error("Exception while trying to deserialize ThroughputQueueBroadcast object: {}", e);
            }
        }

        return throughputQueueBroadcast;
    } catch (Exception e) {
        return null;
    }
}

From source file:org.apache.streams.jackson.StreamsTaskCounterDeserializer.java

@Override
public StreamsTaskCounterBroadcast deserialize(JsonParser jsonParser,
        DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    try {//  w  ww .j a  v  a2s . c  o m
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();

        StreamsTaskCounterBroadcast streamsTaskCounterBroadcast = new StreamsTaskCounterBroadcast();
        JsonNode attributes = jsonParser.getCodec().readTree(jsonParser);

        ObjectName name = new ObjectName(attributes.get("canonicalName").asText());
        MBeanInfo info = server.getMBeanInfo(name);
        streamsTaskCounterBroadcast.setName(name.toString());

        for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) {
            try {
                switch (attribute.getName()) {
                case "ErrorRate":
                    streamsTaskCounterBroadcast
                            .setErrorRate((double) server.getAttribute(name, attribute.getName()));
                    break;
                case "NumEmitted":
                    streamsTaskCounterBroadcast
                            .setNumEmitted((long) server.getAttribute(name, attribute.getName()));
                    break;
                case "NumReceived":
                    streamsTaskCounterBroadcast
                            .setNumReceived((long) server.getAttribute(name, attribute.getName()));
                    break;
                case "NumUnhandledErrors":
                    streamsTaskCounterBroadcast
                            .setNumUnhandledErrors((long) server.getAttribute(name, attribute.getName()));
                    break;
                case "AvgTime":
                    streamsTaskCounterBroadcast
                            .setAvgTime((double) server.getAttribute(name, attribute.getName()));
                    break;
                case "MaxTime":
                    streamsTaskCounterBroadcast
                            .setMaxTime((long) server.getAttribute(name, attribute.getName()));
                    break;
                }
            } catch (Exception e) {
                LOGGER.error("Exception while trying to deserialize StreamsTaskCounterBroadcast object: {}", e);
            }
        }

        return streamsTaskCounterBroadcast;
    } catch (Exception e) {
        LOGGER.error("Exception while trying to deserialize StreamsTaskCounterBroadcast object: {}", e);
        return null;
    }
}