Java Reference
In-Depth Information
6.5.2
Registering with the MBean server
As just mentioned, the other way to register for notifications from an MBean is the
method you used in chapter 2: invoking the addNotificationListener() method
on the MBean server that contains the MBean. This method has the same signa-
ture as the same-named method in the NotificationBroadcaster interface, except
for one additional argument: an instance of the ObjectName class.
This object name argument tells the MBean server the MBean in which to
register the listener. If the MBean does not exist, the method will throw an
InstanceNotFoundException exception. Notifications received after registering in
this manner will contain a source class member variable containing the Object-
Name of the MBean.
6.6 Persisting MBean notifications
You should realize by now that using notifications with your MBeans is not diffi-
cult. Emitting notifications is a powerful tool and can be used for communica-
tion, alerts, and more. Because notifications can contain important information
and valuable data, it is a good idea to keep a record of them. In other words, you
might want to persist your notifications.
Notifications can be persisted by the notification listener or by the broad-
caster. For this chapter, we will consider the case of persisting notifications on the
broadcaster side. By doing it on the agent side, you can create a sort of historical
log of notification activity of MBean notifications. In fact, the next example
shows how to persist notifications at the MBean level. To persist notifications,
you can either create an MBean to act as a listener on every NotificationBroad-
caster in the agent, or you can have each MBean manage its own notification
persistence. We will discuss the latter option. Figure 6.3 illustrates the concept.
Normally, an MBean wanting to emit Notification objects would extend the
NotificationBroadcasterSupport class. Listing 6.4 shows a new broadcaster sup-
port class that MBeans can use to inherit the ability to emit notifications. In
addition, this class has the ability to store each notification sent by the MBean.
This example persists notifications to a database; it assumes a table named Noti-
fications already exists and has a column for each Notification class public
member variable.
Search WWH ::




Custom Search