public void DISABLED_testNotificationsJmx() throws Exception {
// Now let's register a Monitor
// We would like to know if we have peaks in activity, so we can use JMX's
// GaugeMonitor
GaugeMonitor monitorMBean = new GaugeMonitor();
ObjectName monitorName = new ObjectName("examples", "monitor", "gauge");
server.registerMBean(monitorMBean, monitorName);
// Setup the monitor: we want to be notified if we have too many clients or too less
monitorMBean.setThresholds(new Integer(8), new Integer(4));
// Setup the monitor: we want to know if a threshold is exceeded
monitorMBean.setNotifyHigh(true);
monitorMBean.setNotifyLow(true);
monitorMBean.setDifferenceMode(false);
// Setup the monitor: link to the service MBean
monitorMBean.addObservedObject(serviceName);
monitorMBean.setObservedAttribute("SimpleCounter");
// Setup the monitor: a short granularity period
monitorMBean.setGranularityPeriod(50L);
// Setup the monitor: register a listener
MBeanServerConnection connection = connector.getMBeanServerConnection();
final AtomicBoolean notificationSet = new AtomicBoolean(false);
//Add a notification listener to the connection - to
//test for notifications across camel
connection.addNotificationListener(monitorName, new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
System.out.println("Notification = " + notification);
synchronized (notificationSet) {
notificationSet.set(true);
notificationSet.notify();
}
}
}, null, null);
service.start();
monitorMBean.start();
synchronized (notificationSet) {
if (!notificationSet.get()) {
notificationSet.wait(5000);
}
}