Java Reference
In-Depth Information
B
You change the declaration of the HelloWorld class by extending the Notifica-
tionBroadcasterSupport class. This super class provides the MBean with meth-
ods that allow other objects to register as notification listeners and allow the
MBean to send notifications. The super class implements the javax.manage-
ment.NotificationBroadcaster interface examined after this code discussion.
For this example, you are sending only basic notifications. At this step in the
code, you create a Notification object with the constructor
public Notification(java.lang.String type, java.lang.Object source,
long sequenceNumber,long timeStamp,
java.lang.String message )
The parameters of this constructor are listed in table 2.4.
C
Table 2.4
The Notification constructor parameters
Parameter
Description
java.lang.String type
Dot-separated String value used to identify the notification. Used as
a short description of the purpose and meaning for the notification.
java.lang.Object source
The MBean that generated this notification. This will be either the
object reference or the ObjectName of an MBean.
A number that identifies this notification in a possible sequence of
notifications.
long sequenceNumber
A timestamp of the creation of the notification.
long timestamp
java.lang.String message
A String value containing a message from the notification source.
D
By extending the NotificationBroadcasterSupport class, you not only gain the
implementation of the NotificationBroadcaster interface, but also inherit the
sendNotification() method. Your HelloWorld MBean can use this convenience
method when it needs to send a notification, and the super class will send it to all
appropriate listeners. Appropriate listeners are those that have registered with
the MBean and whose filter object accepts the particular type of notification.
Examination of the NotificationBroadcaster interface
The previous example used the NotificationBroadcasterSupport class. This
class provides subclasses with an implementation of the NotificationBroad-
caster interface. The super class implements the NotificationBroadcaster
interface shown next:
public interface NotificationBroadcaster
{
public void addNotificationListener(
NotificationListener listener,
Search WWH ::




Custom Search