Java Reference
In-Depth Information
package com.apress.springenterpriserecipes.replicator;
import javax.management.Attribute;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Client {
public static void main(String[] args) throws Exception {
ApplicationContext context =
new ClassPathXmlApplicationContext("beans-client.xml");
MBeanServerConnection mbeanServerConnection =
(MBeanServerConnection) context.getBean("mbeanServerConnection");
ObjectName mbeanName = new ObjectName(
"bean:name=documentReplicator,type=FileReplicatorJMXImpl");
String srcDir = (String) mbeanServerConnection.getAttribute(
mbeanName, "SrcDir");
mbeanServerConnection.setAttribute(
mbeanName, new Attribute("DestDir", srcDir + "_1"));
mbeanServerConnection.invoke(
mbeanName, "replicate", new Object[] {}, new String[] {});
}
}
Suppose that you've created the following JMX notification listener, which listens to file replication
notifications:
package com.apress.springenterpriserecipes.replicator;
import javax.management.Notification;
import javax.management.NotificationListener;
public class ReplicationNotificationListener implements NotificationListener {
public void handleNotification(Notification notification, Object handback) {
if (notification.getType().startsWith("replication")) {
System.out.println(
notification.getSource() + " " +
notification.getType() + " #" +
notification.getSequenceNumber());
}
}
}
Search WWH ::




Custom Search