1

I am writing some test cases for the JMX interface in our product. I can access attributes from standard MBeans (following sun tutorial). However, I don't seem to be able to access dynamic MBeans. The attributes are fully (readable/writable) from JConsole.

JMXConnector jmxc = getJMXConnector();  // Takes care of our connection
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

ObjectName mbeanName = new ObjectName("com.xyz.prodname:type=LogManager");

// Up to this point, the logic is the same as the working logic.  In our working logic,
// DynamicMBean is replace with our MBean interface class.
DynamicMBean mbean = (DynamicMBean)JMX.newMBeanProxy(mbsc, mbeanName, DynamicMBean.class);
Object o = mbean.getAttribute("AttributeNameAsItAppearsInJConsole"); 

o should be a Boolean, but it is null. No exceptions are thrown.

I have also tried a few other permutations on the attribute name, but I believe it should be the simple name as I've defined it in the implementation class.

Jim Rush
  • 4,143
  • 3
  • 25
  • 27

2 Answers2

3

I've found that you can get to dynamic MBean attributes directly through the MBeanServerConnection object:

JMXConnector jmxc = getJMXConnector();  // Takes care of our connection
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

ObjectName mbeanName = new ObjectName("com.xyz.prodname:type=LogManager");

// This change demonstrates what must be done
Object result = mbsc.getAttribute(mbeanName, "AttributeNameAsItAppearsInJConsole");
Jim Rush
  • 4,143
  • 3
  • 25
  • 27
1

I should have reloaded the page before answering. I basically posted what the original submitter had discovered in the meantime. JMX.newMBeanProxy is useful if you have a Java interface describing the management interface of your MBean (the Standard MBean pattern), but if your MBean is dynamic then you don't need or want a proxy.

  • When I was was writing the original code, I missed the pattern and focused on the interfaces. Of course, it would have been nice if the tutorial or documentation would have provided a bit more guidance on the usage of the interface :-) – Jim Rush Dec 25 '09 at 15:54
  • Even for dynamic MBeans, seems like proxies are still useful. Some/all of the properties or methods you want to access may be defined on the MBean's interface, assuming there is a separate interface. In that case you pass the interface to JMX.newMBeanProxy and are returned an instance that implements it. Then you can make strongly-typed calls on the MBean, e.g. getAttributeNameAsItAppearsInJConsole() or myMethod(). See the JMX tutorial page on [Creating a Custom JMX Client](http://download.oracle.com/javase/tutorial/jmx/remote/custom.html). – Cincinnati Joe Apr 27 '11 at 19:40