Creating a Notification Listener for a Monitor MBean

Using Notifications and Monitor MBeans 7-17

7.5.1.1 Errors and the MonitorNotification Type Property

If an error occurs, all monitors encode one of the following values in the notifications Type property: ■ jmx.monitor.error.mbean , which indicates that the observed MBean is not registered in the MBean Server. The observed object name is provided in the notification. ■ jmx.monitor.error.attribute , which indicates that the observed attribute does not exist in the observed object. The observed object name and observed attribute name are provided in the notification. ■ jmx.monitor.error.type , which indicates that the object instance of the observed attribute value is null or not of the appropriate type for the given monitor. The observed object name and observed attribute name are provided in the notification. ■ jmx.monitor.error.runtime , which contains exceptions that are thrown while trying to get the value of the observed attribute for reasons other than the cases described above. The counter and the gauge monitors can also encode jmx.monitor.error.threshold into the Type property under the following circumstances: ■ For a counter monitor, when the threshold, the offset, or the modulus is not of the same type as the observed counter attribute. ■ For a gauge monitor, when the low threshold or high threshold is not of the same type as the observed gauge attribute.

7.5.2 Creating a Notification Listener for a Monitor MBean

When an observed attributes meets the criteria that you specify, a monitor MBean emits a notification. There are no special requirements for creating a listener for a MonitorNotification . The steps are the same as those described in Section 7.4.1, Creating a Notification Listener, except: ■ You listen for notifications of type MonitorNotification. ■ Optionally, you can import the javax.management.monitor.MonitorNotification class and invoke its methods to retrieve additional information about the event that generated the notification. See Example 7–5 . StringMonitor jmx.monitor.string.matches if the observed attribute value matches the string to compare value. Subsequent matches of the string to compare values do not cause further notifications unless the attribute value differs from the string to compare value. jmx.monitor.string.differs if the attribute value differs from the string to compare value. Subsequent differences from the string to compare value do not cause further notifications unless the attribute value matches the string to compare value. Table 7–4 Cont. Monitor MBeans and the MonitorNotification Type Property A Monitor MBean of This Type Encodes This String in the MonitorNotifications Type Property 7-18 Developing Custom Management Utilities With JMX for Oracle WebLogic Server Example 7–5 Listener for Monitor Notifications import javax.management.Notification; import javax.management.NotificationListener; import javax.management.monitor.MonitorNotification; public class MonitorListener implements NotificationListener { public void handleNotificationNotification notification, Object obj { ifnotification instanceof Notification { Notification notif = Notification notification; System.out.printlnNotification type + notif.getType ; System.out.printlnMessage: + notif.getMessage ; } if notification instanceof MonitorNotification { MonitorNotification mn = MonitorNotification notification; System.out.printlnObserved Attribute: + mn.getObservedAttribute; System.out.printlnTrigger: + mn.getTrigger ; } } }

7.5.3 Registering the Monitor and Listener