ObjectName listenerName1 = new ObjectName("test:type=listener1");
server.registerMBean(listener1, listenerName1);
// Register the broadcaster
ObjectName broadcasterName = new ObjectName("test:type=broadcaster");
Broadcaster broadcaster = new Broadcaster();
server.registerMBean(broadcaster, broadcasterName);
// Add the listener to the broadcaster
server.addNotificationListener(broadcasterName, listenerName1, null, null);
// Add the listener to the delegate
ObjectName delegateName =
new ObjectName("JMImplementation:type=MBeanServerDelegate");
server.addNotificationListener(delegateName,listenerName1, null, null);
// Remove ourselves from the broadcaster
server.removeNotificationListener(broadcasterName, listener1);
// Test we get a notification from the broadcaster
broadcaster.doSomething();
assertEquals(0, listener1.count);
// Test we get a notification from the delegate
server.registerMBean(new Test(), new ObjectName("Test:foo=bar"));
assertEquals(1, listener1.count);