Example usage for javax.management AttributeList addAll

List of usage examples for javax.management AttributeList addAll

Introduction

In this page you can find the example usage for javax.management AttributeList addAll.

Prototype

@Override
public boolean addAll(Collection<?> c) 

Source Link

Usage

From source file:org.wso2.carbon.as.monitoring.collector.jmx.clients.MBeanClient.java

/**
 * Read the possible attribute values from the MBean
 *
 * @return List of Result objects//from w  ww.java2  s. co  m
 */
public List<Result> readPossibleAttributeValues() throws MalformedObjectNameException {
    ObjectName name = new ObjectName(getObjectNameQuery());
    Set<ObjectInstance> instances = server.queryMBeans(name, null);

    List<Result> results = new ArrayList<Result>();
    for (ObjectInstance instance : instances) {
        ObjectName objectName = instance.getObjectName();

        AttributeList attributes = null;
        try {
            attributes = server.getAttributes(objectName, getAttributeNames());
        } catch (InstanceNotFoundException ignored) {
            // Here we put best-effort to grab any attributes.
            // Missing objects are ignored. We need whatever possible.
            if (LOG.isDebugEnabled()) {
                LOG.debug(objectName + " MBean not found : " + ignored.getMessage(), ignored);
            }
        } catch (ReflectionException ignored) {
            // Here we put best-effort to grab any attributes.
            // erroneous attributes are ignored. We need whatever possible.
            if (LOG.isDebugEnabled()) {
                LOG.debug("Exception occurred while reading the attributes from " + objectName, ignored);
            }
        }

        if (attributes != null) {
            attributes.addAll(getPropertiesFromKey(objectName));
        }

        Result result = new Result(getCorrelationKey(objectName), attributes);
        results.add(result);
    }

    return results;
}