Java Utililty Methods MBean

List of utility methods to do MBean

Description

The list of methods to do MBean are organized into topic(s).

Method

voiddumpOperations(MBeanOperationInfo[] operations)
dump Operations
System.out.println("");
System.out.println("Operations:");
for (int i = 0; i < operations.length; i++) {
    StringBuffer dump = new StringBuffer();
    MBeanOperationInfo operation = operations[i];
    dump.append("name=").append(operation.getName());
    dump.append(",impact=").append(decodeImpact(operation.getImpact()));
    dump.append(",returnType=").append(operation.getReturnType());
...
MBeanAttributeInfofindAttribute(MBeanAttributeInfo[] attributes, String name)
find Attribute
for (int i = 0; i < attributes.length; i++) {
    if (attributes[i].getName().equals(name)) {
        return attributes[i];
return null;
MBeanServerfindFirstMBeanServer()
Retrieve the first MBeanServer found.
return findMBeanServerForAgentId(null);
ObjectNamefindMBean(MBeanServer mbs, ObjectName queryName)
find M Bean
Iterator<ObjectName> it = mbs.queryNames(queryName, null).iterator();
if (it.hasNext()) {
    ObjectName name = it.next();
    if (it.hasNext()) {
        throw new JMException("Found more than one MBean matching " + queryName);
    } else {
        return name;
} else {
    throw new JMException("Failed to locate " + queryName);
ArrayListfindMBeanServer(String agentId)
Return a list of registered MBeanServers.
return MBeanServerFactory.findMBeanServer(agentId);
MBeanServerfindMBeanServerForAgentId(String agentId)
Find a MBeanServer given an agent id.
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(agentId);
if (servers == null || servers.isEmpty()) {
    return null;
return servers.get(0);
MBeanAttributeInfogetAttribute(MBeanInfo info, String attrName)
Returns the attribute with the specified name.
MBeanAttributeInfo[] attrs = info.getAttributes();
for (int i = 0; i < attrs.length; i++) {
    if (attrs[i].getName().equals(attrName))
        return attrs[i];
return null;
ObjectgetAttribute(MBeanServer mbeanServer, ObjectName objectName, String attributeName)
get Attribute
try {
    return mbeanServer.getAttribute(objectName, attributeName);
} catch (AttributeNotFoundException nsa) {
    return null;
} catch (Exception ex) {
    throw new RuntimeException(String.format("failed to retrieve attribute '%s' from objectName '%s'",
            attributeName, objectName), ex);
TgetAttribute(MBeanServerConnection connection, ObjectName objectName, String attribute)
get Attribute
return (T) connection.getAttribute(objectName, attribute);
ObjectgetAttribute(ObjectName on, MBeanServerConnection server, String name)
Gets an attribute value from an mbean.
try {
    return server.getAttribute(on, name);
} catch (Exception e) {
    throw new RuntimeException("Failed to get attribute", e);