Java Reference
In-Depth Information
{
e.printStackTrace();
}
Notification notif = new Notification(
"ch6.PollingMBean.counter",
this, index++ );
sendNotification( notif );
}//while
}
public MBeanNotificationInfo[] getNotificationInfo()
{
String[] type = { " ch6.PollingMBean.counter " };
String[] attChanges = {
AttributeChangeNotification.ATTRIBUTE_CHANGE };
MBeanNotificationInfo[] info = new MBeanNotificationInfo[ 2 ];
info[ 0 ] = new MBeanNotificationInfo( type,
" javax.management.Notification " ,
" The Polling MBean counter " );
info[ 1 ] = new MBeanNotificationInfo( attChanges,
"javax.management.AttributeChangeNotification",
"The Polling MBean counter" );
return info;
}
Add notification
to management
interface
C
}//class
B
In order to create an AttributeChangeNotification object, you need to store the
old value of the interval class member before changing it. The notification is cre-
ated using the old and new values of the interval member variable. After you cre-
ate the notification, it is sent the same way as the other notification in the main
loop (using the sendNotification() method).
In addition, the revised MBean adds another MBeanNotificationInfo object to the
array return value of the getNotificationInfo() method. This additional object is
the attribute change notification that is available to be received from this MBean.
C
6.4.3
Testing the Polling MBean
In order to round out your exposure to sending notifications, let's run the latest
version of the Polling MBean in the JMXBookAgent agent. Remember from previous
chapters that you created setup classes that registered MBeans in the agent. You
will do the same thing in this chapter. Listing 6.3 shows the PollingSetup class,
which contacts a JMXBookAgent instance and registers a Polling MBean with it.
Search WWH ::




Custom Search