KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > notification > support > Listener


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package test.compliance.notification.support;
8
9 import java.util.ArrayList;
10 import java.util.HashMap;
11
12 import javax.management.Notification;
13 import javax.management.NotificationListener;
14
15 /**
16  * A listener
17  *
18  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
19  */

20 public class Listener
21    implements NotificationListener
22 {
23    // Attributes ----------------------------------------------------------------
24

25    /**
26     * The notifications received by handback object
27     */

28    public HashMap notifications = new HashMap();
29
30    // Constructor ---------------------------------------------------------------
31

32    /**
33     * Constructor
34     */

35    public Listener()
36    {
37    }
38
39    // Notification Listener Implementation --------------------------------------
40

41    /**
42     * Handle the notification
43     */

44    public void handleNotification(Notification notification, Object handback)
45    {
46       synchronized(notifications)
47       {
48          ArrayList received = (ArrayList) notifications.get(handback);
49          if (received == null)
50          {
51             received = new ArrayList();
52             notifications.put(handback, received);
53          }
54          received.add(notification);
55       }
56    }
57 }
58
Popular Tags