5.6 Notifications

In Chapter 3 we described the JMX notification model from an MBean perspective. In particular we showed how to "activate" an MBean by implementing the NotificationBroadcaster interface. Now it's time to look at notifications from the MBeanServer perspective. There are four MBeanServer methods that deal with notifications:

 public void addNotificationListener(ObjectName name,                                      NotificationListener listener,                                     NotificationFilter filter,                                     Object handback) public void addNotificationListener(ObjectName name,                                     ObjectName listener,                                     NotificationFilter filter,                                     Object handback) public void removeNotificationListener(ObjectName name,     NotificationListener listener) public void removeNotificationListener(ObjectName name,     ObjectName listener) 

The first two methods add notification listeners to the MBean designated by the first parameter. The only difference between the two methods is whether the listener is a Java object that implements the NotificationListener interface or the object name of an MBean that implements the NotificationListener interface in addition to its management interface. As explained in Chapter 3, the NotificationFilter interface determines whether or not the listener receives a given notification.

The handback parameter is a reference to a Java object that is delivered to the listener's handleNotification() method by NotificationBroadcaster . Handbacks make it possible to reuse a NotificationListener instance; the same listener can be added multiple times, each time with a different handback object, to a given MBean. When the MBean sends a notification, the listener's handleNotification() method will be invoked, with the appropriate handback ”once for each time it was added.

The removeNotificationListener() methods remove a listener, identified by its object reference or object name, from the set of listeners associated with the MBean designated by the object name in the first parameter. Note that neither of the removeNotificationListener() methods takes a handback object. This is an unfortunate asymmetry in the 1.0 version of the JMX specification. It is unfortunate because it means that when a listener has been added multiple times, the MBeanServer has no way to distinguish which of the additions is being removed, so it removes all of them.



Java and JMX. Building Manageable Systems
Javaв„ў and JMX: Building Manageable Systems
ISBN: 0672324083
EAN: 2147483647
Year: 2000
Pages: 115

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net