Emil Lundberg
Emil Lundberg

Reputation: 7380

In JMX, can I get a specific MBeanAttributeInfo directly?

Is there any way to, without additional libraries, get the MBeanAttributeInfo of a specific attribute directly, as opposed to using MBeanInfo.getAttributes() and doing a linear search through it?

Example scenario: check whether a given attribute - jboss:service=Mail.State in the example - is writable.

MBeanServer server; // Assume this is initialized somewhere else

MBeanAttributeInfo[] infos = server.getMBeanInfo(new ObjectName("jboss:service=Mail"));
for(MBeanAttributeInfo info : infos) {
    if(info.getName().equals("State")) {
        if(info.isWritable()) {
            //do something
        }
        break;
    }
}

What I'm hoping to find is something like a getAttributeInfo(ObjectName name, String attribute) method in the MBeanServer.

Upvotes: 0

Views: 894

Answers (1)

user1768906
user1768906

Reputation:

You can get it by:

server.getAttribute(new ObjectName("jboss:service=Mail"), "State")

where server is a MBeanServerConnection and "State" is the attribute name.

Upvotes: 1

Related Questions