Dashboard > Spring Documentation Sandbox > Spring JMX > Accessing JMX Managed Beans using a Proxy
  Spring Documentation Sandbox Log In View a printable version of the current page.  
  Accessing JMX Managed Beans using a Proxy
Added by Rob Harrop, last edited by Rob Harrop on Aug 10, 2004  (view change)
Labels: 
(None)

Accessing JMX Managed Beans using a Proxy

Accessing MBean resources requires lot of code. You have to interact with the MBeanServer, catching lots of checked exceptions that you can do nothing with. All in all, using JMX is a pain. Thankfully Spring JMX introduces support classes for creating proxies to the JMX resources.

Using the JmxObjectProxyFactory Implementations

There are two implementations of the JmxObjectProxyFactory interface: JdkJmxObjectProxyFactory and CglibJmxObjectProxyFactory. When using the JDK proxy factory, you must specify at least one interface that the proxy class will implement. With the Cglib proxy you can specify interfaces to proxy, but if you don't the proxy will simply subclass the managed resources class. The code below shows a simple usage of the CglibJmxObjectProxyFactory:

protected void useProxy(JmxObjectProxyFactory factory)
            throws Exception {

        ObjectName objectName = ObjectName.getInstance("bean:name=foo");
        factory.setProxyInterfaces(new Class[] { IJmxTestBean.class });
        IJmxTestBean bean = (IJmxTestBean)factory.getProxy(mbeanServer, objectName);
        bean.doSomething()
}

Although it is possible, when using the Cglib proxy, to proxy the class directly, I recommend that you use an interface that corresponds to the managed interface of the managed resource. If the proxy has methods or properties that are not exposed in the managed resource's managed interface, then attempts to invoke them will result in either a no-op or an exception depending on the value of the JmxObjectProxyFactory.ignoreInvalidInvocations property.

Using the JmxProxyFactoryBean

This isn't finished yet, but should be done in the next few days.

Site running on a free Atlassian Confluence Open Source Project License granted to Spring Framework. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators