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:org.apache.hadoop.hdfs.server.common.MetricsLoggerTask.java

/**
 * Get the list of attributes for the MBean, filtering out a few attribute
 * types.// w ww  .  ja  v a2 s . c om
 */
private static Set<String> getFilteredAttributes(MBeanInfo mBeanInfo) {
    Set<String> attributeNames = new HashSet<>();
    for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) {
        if (!attributeInfo.getType().equals("javax.management.openmbean.TabularData")
                && !attributeInfo.getType().equals("javax.management.openmbean.CompositeData")
                && !attributeInfo.getType().equals("[Ljavax.management.openmbean.CompositeData;")) {
            attributeNames.add(attributeInfo.getName());
        }
    }
    return attributeNames;
}

From source file:com.athena.dolly.console.module.jmx.JmxClientManager.java

public static HashMap<String, Object> getObjectNameInfo(ObjectName objName, String nodeName) {
    JmxClient jmxClient = jmxClientMap.get(nodeName);

    try {/*w  w  w.j  a  va2  s . com*/
        MBeanServerConnection connection = jmxClient.getJmxConnector().getMBeanServerConnection();
        HashMap<String, Object> infoMap = new HashMap<String, Object>();
        Set<ObjectName> names = new TreeSet<ObjectName>(connection.queryNames(objName, null));

        for (ObjectName name : names) {
            logger.info("#######################");
            logger.info("\tObjectName = " + name);

            MBeanInfo info = connection.getMBeanInfo(name);
            MBeanAttributeInfo[] attributes = info.getAttributes();

            for (MBeanAttributeInfo attr : attributes) {
                logger.info("==========================");
                logger.info("attrName = " + attr.getName());
                logger.info("attrType = " + attr.getType());
                logger.info("connection.getAttribute = " + connection.getAttribute(name, attr.getName()));

                infoMap.put(attr.getName(), connection.getAttribute(name, attr.getName()));
            }
        }

        return infoMap;
    } catch (Exception e) {
        logger.error("unhandled exception has errored : ", e);
    }

    return null;
}

From source file:org.hyperic.hq.plugin.jboss.MBeanUtil.java

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

    if (method.startsWith("set")) {
        method = method.substring(3);/*from ww  w . j  av a  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;
        }
        if (!attr.isWritable()) {
            throw new PluginException("Attribute '" + method + "' is not writable");
        }

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

        if (args.length != 1) {
            String msg = "setAttribute(" + method + ") takes [1] argument, [" + args.length + "] given";
            throw new PluginException(msg);
        }

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

    return null;
}

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);//from  w w w. j  a  v a  2  s . c  om
    }

    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:com.boundary.plugin.sdk.jmx.MBeansTransformer.java

/**
 * Iterates over the attributes of an MBean
 * @param name {@link ObjectName}/*  ww w .j av a  2 s  .c  om*/
 */
private void traverseAttributes(ObjectName name) {
    MBeanServerConnection connection = this.client.getMBeanServerConnection();
    MBeanInfo info;
    HashSet<String> checkTypes = new HashSet<String>();
    checkTypes.add("long");
    checkTypes.add("int");
    checkTypes.add("javax.management.openmbean.CompositeData");
    checkTypes.add("[Ljavax.management.openmbean.CompositeData;");
    try {
        info = connection.getMBeanInfo(name);
        MBeanAttributeInfo[] attributes = info.getAttributes();
        for (MBeanAttributeInfo attrInfo : attributes) {
            if (checkTypes.contains(attrInfo.getType())) {
                transform.beginAttribute(name, attrInfo);
                transform.endAttribute();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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  ww w .  ja  v a  2 s  .  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.jolokia.handler.list.AttributeDataUpdater.java

/** {@inheritDoc} */
@Override// w  ww.  java  2s.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:org.jminix.console.resource.AttributeResource.java

@Override
public void acceptRepresentation(Representation entity) throws ResourceException {
    String value = new Form(entity).getFirstValue("value");

    String domain = getRequest().getAttributes().get("domain").toString();

    String mbean = new EncoderBean().decode(getRequest().getAttributes().get("mbean").toString());

    String attributeName = new EncoderBean().decode(getRequest().getAttributes().get("attribute").toString());

    MBeanServerConnection server = getServer();

    try {/*  w w  w . j  a  v  a 2s  .c  o m*/

        String type = "java.lang.String";
        for (MBeanAttributeInfo info : server.getMBeanInfo(new ObjectName(domain + ":" + mbean))
                .getAttributes()) {
            if (info.getName().equals(attributeName)) {
                type = info.getType();
            }
        }

        Object attribute = new ValueParser().parse(value, type);

        if (attribute != null) {
            server.setAttribute(new ObjectName(domain + ":" + mbean), new Attribute(attributeName, attribute));
        }

        String queryString = getQueryString();
        if (queryString == null) {
            queryString = "?";
        }
        queryString += "ok=1";
        getResponse().redirectPermanent(new EncoderBean().encode(attributeName) + queryString);
    } catch (InstanceNotFoundException e) {
        throw new RuntimeException(e);
    } catch (AttributeNotFoundException e) {
        throw new RuntimeException(e);
    } catch (InvalidAttributeValueException e) {
        throw new RuntimeException(e);
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException(e);
    } catch (MBeanException e) {
        throw new RuntimeException(e);
    } catch (ReflectionException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e);
    }

}

From source file:org.apache.synapse.commons.snmp.SNMPAgent.java

@Override
protected void registerManagedObjects() {
    log.info("Initializing Synapse SNMP MIB");
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectInstance> instances = mbs.queryMBeans(null, null);

    try {/* www.  j a va  2 s. c om*/
        for (ObjectInstance instance : instances) {
            ObjectName objectName = instance.getObjectName();
            if (objectName.getDomain().equals("org.apache.synapse")) {
                String oidString = SynapseMIBUtils.getOID(objectName);
                if (oidString == null) {
                    continue;
                }

                MBeanInfo info = mbs.getMBeanInfo(objectName);
                MBeanAttributeInfo[] attributes = info.getAttributes();
                List<String> attributeNames = new ArrayList<String>();
                List<String> mapAttributes = new ArrayList<String>();
                for (MBeanAttributeInfo attributeInfo : attributes) {
                    attributeNames.add(attributeInfo.getName());
                    if (Map.class.getName().equals(attributeInfo.getType())) {
                        mapAttributes.add(attributeInfo.getName());
                    }
                }
                Collections.sort(attributeNames);

                doRegister(attributeNames, mapAttributes, oidString, objectName);
            }
        }
    } catch (Exception e) {
        log.error("Error while initializing the SNMP MIB", e);
    }
}

From source file:com.stumbleupon.hbaseadmin.JMXQuery.java

protected Object doAttributeOperation(MBeanServerConnection mbsc, ObjectInstance instance, String command,
        MBeanAttributeInfo[] infos) throws Exception {
    final CommandParse parse = new CommandParse(command);

    if ((parse.getArgs() == null) || (parse.getArgs().length == 0)) {
        return mbsc.getAttribute(instance.getObjectName(), parse.getCmd());
    }/*from  w  w  w  .  jav  a2  s .com*/

    if (parse.getArgs().length != 1) {
        throw new IllegalArgumentException("One only argument setting attribute values: " + parse.getArgs());
    }

    final MBeanAttributeInfo info = (MBeanAttributeInfo) getFeatureInfo(infos, parse.getCmd());

    final Constructor c = getResolvedClass(info.getType()).getConstructor(new Class[] { String.class });

    final Attribute a = new Attribute(parse.getCmd(), c.newInstance(new Object[] { parse.getArgs()[0] }));

    mbsc.setAttribute(instance.getObjectName(), a);
    return null;
}