MD6380 MD6380 - 1 year ago 123
Java Question

How to programmatically check JMX MBean operations and attributes?

Suppose we have a MBean that has the following attributes and operations.



Is there a way to programmatically check for the attributes and operations? I've been working with the IBM WebSphere MBeans and their documentation isn't very good.

For example, if you go to IBMs Infocenter and navigate to Network Deployment -> Reference -> Programming interfaces -> Mbean interfaces -> ThreadPool. They only have attributes listed and no operations.

Using the WebSphere wsadmin tool, I can actually check to see the operations and attributes. I'd like to know if there's a way to do this with all MBeans.

wsadmin>print Help.attributes(object)
Attribute Type Access
name java.lang.String RO
maximumSize int RW
minimumSize int RW
inactivityTimeout long RW
growable boolean RW
stats RO

wsadmin>print Help.operations(object)
java.lang.String getName()
int getMaximumPoolSize()
void setMaximumPoolSize(int)
int getMinimumPoolSize()
void setMinimumPoolSize(int)
long getKeepAliveTime()
void setKeepAliveTime(long)
boolean isGrowAsNeeded()
void setGrowAsNeeded(boolean) getStats()

Answer Source

I can't quite tell if you are talking about programmatically finding the MBeans from inside the current JVM or remotely from a client. There are a number of JMX client libraries. The one I wrote is available here:

With my code you can do something like:

JmxClient client = new JmxClient(hostName, port);
Set<ObjectName> objectNames = getBeanNames() 
for (ObjectName name : objectNames) {
    MBeanAttributeInfo[] attributes = getAttributesInfo(name);
    MBeanOperationInfo[] operations = getOperationsInfo(name);

If you are asking about the current JVM then you should be able to get bean information from the internal beans this way:

MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = server.queryNames(null, null);
for (ObjectName name : objectNames) {
    MBeanInfo info = server.getMBeanInfo(name);