Java Reference
In-Depth Information
}//while
}
C
Expose
notifications
public MBeanNotificationInfo[] getNotificationInfo()
{
String[] type = { "ch6.PollingMBean.counter" };
MBeanNotificationInfo[] info = new MBeanNotificationInfo[ 1 ];
info[ 0 ] = new MBeanNotificationInfo( type,
"javax.management.Notification",
"The Polling MBean counter" );
return info;
}
}//class
B
As this MBean passes through its loop, it repeatedly executes these lines of code
that build and send an instance of the Notification class. To build notifications
in this example, you use the constructor of the Notification class that accepts
values for the notification type, source, and sequence number. After constructing
the notification, you send it using the sendNotification() method inherited
from the NotificationBroadcasterSupport super class.
Also inherited from the super class is the getNotificationInfo() method. You
don't necessarily have to override this method, but you need to do so in order
for the MBean to accurately describe the notifications it sends. The super class
has no way of knowing what you intend to emit in the subclass. You must over-
ride this method in order to guarantee you are sending and describing the same
types of notifications.
C
6.4 Capturing MBean attribute changes
After completing the previous example, you should have a good understanding
of how the notification model works within JMX . Now it is time to move on to
more specific notification types that are found throughout JMX . Recall that noti-
fications can serve as events and usually contain information regarding an
MBean event. A common event that occurs in a JMX application is the changing
of MBean attributes.
For example, other components of an application might need to know when a
particular attribute changes in order to perform some related action. Because
attribute changes can be a common occurrence, JMX provides a standard notifi-
cation class to encapsulate attribute changes: the javax.management.Attribute-
ChangeNotification class.
Search WWH ::




Custom Search