Java Reference
In-Depth Information
You can register this notification listener to the MBean server connection to listen to notifications
emitted from this MBean server.
package com.apress.springenterpriserecipes.replicator;
...
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
public class Client {
public static void main(String[] args) throws Exception {
...
MBeanServerConnection mbeanServerConnection =
(MBeanServerConnection) context.getBean("mbeanServerConnection");
ObjectName mbeanName = new ObjectName(
"bean:name=documentReplicator,type=FileReplicatorImpl");
mbeanServerConnection.addNotificationListener(
mbeanName, new ReplicationNotificationListener(), null, null);
...
}
}
After you run this, check JConsole again under the Notifications node. You'll see the same two
notifications as before and an interesting, new notification of type jmx.attribute.change .
Accessing Remote MBeans Through an MBean Proxy
Another approach that Spring offers for remote MBean access is through MBeanProxy , which can be
created by MBeanProxyFactoryBean .
<beans ...>
<bean id="mbeanServerConnection"
class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
<property name="serviceUrl" value=
"service:jmx: rmi://localhost/jndi/ rmi://localhost:1099/replicator" />
</bean>
<bean id="fileReplicatorProxy"
class="org.springframework.jmx.access.MBeanProxyFactoryBean">
<property name="server" ref="mbeanServerConnection" />
<property name="objectName"
value="bean:name=documentReplicator,type=FileReplicatorImpl" />
<property name="proxyInterface"
value="com.apress.springenterpriserecipes.replicator.FileReplicator" />
</bean>
</beans>
You need to specify the object name and the server connection for the MBean you are going to
proxy. The most important is the proxy interface, whose local method calls will be translated into remote
MBean calls behind the scenes.
Search WWH ::




Custom Search