Java Reference
In-Depth Information
JMX provides another standard class that implements the NotificationFil-
ter interface: the javax.management.AttributeChangeNotificationFilter class.
This filter class implements the NotificationFilter interface and works simi-
larly to the NotificationFilterSupport class. However, instead of enabling types
of notifications, listeners enable attribute names.
For instance, to indicate to the filter that you are interested in attribute change
notifications coming from the attribute named State , you would invoke the fil-
ter's enableAttribute() method and pass in the String value State .
Broadcasters use this filter just like any other by invoking the isNotifica-
tionEnabled() method, passing in the Notification to be sent, and receiving a
boolean value indicating a listener's interest. The filter checks the notification to
see if it encapsulates an attribute change in which its listener is interested.
6.4.2
Revising the Polling MBean
To further examine the attribute change notification class, let's modify the Poll-
ing MBean to use an AttributeChangeNotification notification. The first pre-
sentation of this MBean had no attributes, so you need to add one. The
following interface declares a new attribute, interval , which indicates how long
to pause between sending notifications. The changes to the interface are in bold:
package jmxbook.ch6;
import javax.management.*;
public interface PollingMBean
{
public void start();
public void stop();
public void setInterval( long time );
}
The new method setInterval() accepts a long parameter used to set the amount
of sleep time between sending notifications in the main loop. Listing 6.2 shows
the new Polling MBean class. To demonstrate AttributeChangeNotification ,
the MBean will emit one notification each time the setInterval() is invoked.
The changes to the class are in bold.
Listing 6.2
Polling.java
package jmxbook.ch6;
import javax.management.*;
public class Polling extends NotificationBroadcasterSupport
implements PollingMBean, Runnable
Search WWH ::




Custom Search