Java Reference
In-Depth Information
translate the notification message for each listener. Alternatively, you could leave
the handback object as null.
The last method in the interface,
getNotificationInfo()
, returns an array of
objects of type
MBeanNotificationInfo
. You should recognize this object from
chapter 5; it is a member of the set of metadata objects used to describe the
management interface of an MBean. It is used here separately to ensure that
broadcasters provide information about the types of notifications they emit. We
examine the
MBeanNotificationInfo
class in section 6.2.2.
The NotificationBroadcasterSupport class
The other way to implement the
NotificationBroadcaster
interface is to extend
the
javax.management.NotificationBroadcasterSupport
class. By extending this
class, you inherit an implementation of the interface.
In addition, the
NotificationBroadcasterSupport
class provides an extra
method called
sendNotification()
. The
sendNotification()
method provides a
mechanism for sending a
Notification
object to registered listeners. This
method attempts to send its notification argument to each registered listener
after first applying that listener's filter object. If the filter indicates that the lis-
tener should receive that notification, then it is sent. A drawback of extending
this class is that you don't have the opportunity to interact with the handback
object before sending a notification.
The final method from the
NotificationBroadcaster
interface is
getNotifi-
cationInfo()
. A subclass of the
NotificationBroadcasterSupport
class should
override the
getNotificationInfo()
method to provide information about the
notifications it can broadcast. The return value of this method is an array of
MBean-
NotificationInfo
objects. This class is a member of the metadata classes covered
in chapter 5.
6.2.2
Describing notifications as
part of a management interface
In chapter 5, which discussed Dynamic MBeans, you were introduced to the
MBean metadata classes. These classes are used to describe the management
interfaces of MBeans. One of the metadata classes that we didn't cover in detail
is
MBeanNotificationInfo
. Now that we are discussing notifications, we need to
examine this class.
The
javax.management.MBeanNotificationInfo
class is a metadata class used
by MBeans that are notification broadcasters. MBeans provide this class in the
following two ways: