01: package example;
02:
03: import java.util.logging.Logger;
04:
05: import javax.management.NotificationListener;
06: import javax.management.Notification;
07:
08: /**
09: * Implements an MBean event listener.
10: */
11: public class Listener implements NotificationListener, ListenerMBean {
12: private static final Logger log = Logger.getLogger(Listener.class
13: .getName());
14: /**
15: * Count of the notifications received.
16: */
17: private int _notificationCount;
18:
19: /**
20: * Returns the count of notifications received.
21: */
22: public int getNotificationCount() {
23: return _notificationCount;
24: }
25:
26: /**
27: * Handles the notification.
28: *
29: * @param notif the notification sent by the event's MBean
30: * @param handback an opaque object configured when the listener
31: * was configured.
32: */
33: public void handleNotification(Notification notif, Object handback) {
34: _notificationCount++;
35:
36: if (handback != null)
37: log.info("notification(type=" + notif.getType()
38: + ",handback=" + handback + ")");
39: else
40: log.info("notification(type=" + notif.getType() + ")");
41: }
42:
43: /**
44: * Returns a printable version of the resource.
45: */
46: public String toString() {
47: return "Listener[" + _notificationCount + "]";
48: }
49: }
|