KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > Listener


1 package example;
2
3 import java.util.logging.Logger JavaDoc;
4
5 import javax.management.NotificationListener JavaDoc;
6 import javax.management.Notification JavaDoc;
7
8 /**
9  * Implements an MBean event listener.
10  */

11 public class Listener implements NotificationListener JavaDoc, ListenerMBean {
12   private static final Logger JavaDoc log =
13     Logger.getLogger(Listener.class.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   {
24     return _notificationCount;
25   }
26
27   /**
28    * Handles the notification.
29    *
30    * @param notif the notification sent by the event's MBean
31    * @param handback an opaque object configured when the listener
32    * was configured.
33    */

34   public void handleNotification(Notification JavaDoc notif, Object JavaDoc handback)
35   {
36     _notificationCount++;
37     
38     if (handback != null)
39       log.info("notification(type=" + notif.getType() + ",handback=" + handback + ")");
40     else
41       log.info("notification(type=" + notif.getType() + ")");
42   }
43   
44
45   /**
46    * Returns a printable version of the resource.
47    */

48   public String JavaDoc toString()
49   {
50     return "Listener[" + _notificationCount + "]";
51   }
52 }
53
Popular Tags