Java Reference
In-Depth Information
that. You provide this object with acceptable notification types by invoking its
enableType() method and passing it a String value notification type.
When you use filters, you usually assume that notification listeners have some
knowledge of the notification meanings for a particular MBean, because filters
must be able to decide whether they should accept a notification. In addition,
the filter argument of the addNotificationListener() method can be left null,
thereby indicating to the NotificationBroadcaster that a listener wants to
receive all notifications.
NOTE
If you don't want to create a filter object that depends on having knowl-
edge of notification types, you can alternatively have the isNotifica-
tionEnabled() method be a callback to the notification listener. The
listener can decide whether it wants a notification to be sent.
6.3 A notification polling example
Now that you have an understanding of all the components involved in the noti-
fication model, let's put it all together in a short example. For this example, you
will create a Standard MBean. (Remember that a Standard MBean is an MBean
that implements an MBean interface that explicitly declares the MBean's man-
agement interface.)
The MBean for this example runs in a loop in its own thread. With every
pass through the loop, it sends a notification. The following is the Polling-
MBean interface:
package jmxbook.ch6;
import javax.management.*;
public interface PollingMBean
{
public void start();
public void stop();
}
You can see that this MBean exposes only two operations— start() and stop() —
and no attributes. These operations will start or stop a loop that sends a notifica-
tion with each pass. Listing 6.1 shows the MBean that implements this interface;
it creates the class Polling . In addition, the Polling class extends Notification-
BroadcasterSupport in order to inherit an implementation of the Notification-
Broadcaster interface.
Search WWH ::




Custom Search