KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > remoting > ClientListener


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

9 package org.jboss.mx.remoting;
10
11 import java.util.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13 import javax.management.NotificationFilter JavaDoc;
14 import javax.management.ObjectName JavaDoc;
15
16 /**
17  * ClientListener
18  *
19  * @author <a HREF="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
20  * @version $Revision: 30251 $
21  */

22 public class ClientListener
23 {
24    final ObjectName JavaDoc objectName;
25    final Object JavaDoc listener;
26    final NotificationFilter JavaDoc filter;
27    final Object JavaDoc handback;
28    final String JavaDoc sessionId;
29
30    private static final Map JavaDoc listeners = new HashMap JavaDoc();
31
32    private ClientListener(String JavaDoc sessionId, ObjectName JavaDoc objectName, Object JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback)
33    {
34       this.sessionId = sessionId;
35       this.objectName = objectName;
36       this.listener = listener;
37       this.filter = filter;
38       this.handback = handback;
39    }
40
41    public String JavaDoc toString()
42    {
43       return "ClientListener [sessionid:" + sessionId + ",objectName:" + objectName + ",listener:" + listener + ",filter:" + filter + ",handback:" + handback + "]";
44    }
45
46    public static boolean hasListeners()
47    {
48       return listeners.isEmpty() == false;
49    }
50
51    public static Object JavaDoc makeId(String JavaDoc sessionId, ObjectName JavaDoc objectName, Object JavaDoc listener)
52    {
53       return sessionId + "/" + objectName + "/" + listener;
54    }
55
56    public static synchronized ClientListener remove(Object JavaDoc id)
57    {
58       return (ClientListener) listeners.remove(id);
59    }
60
61    public static synchronized ClientListener remove(String JavaDoc sessionId, ObjectName JavaDoc objectName, Object JavaDoc listener)
62    {
63       Object JavaDoc id = null;
64       if(listener instanceof ClientListener)
65       {
66          id = makeId(sessionId, objectName, ((ClientListener) listener).listener);
67       }
68       else
69       {
70          id = makeId(sessionId, objectName, listener);
71       }
72       return (ClientListener) listeners.remove(id);
73    }
74
75    public static synchronized Object JavaDoc register(String JavaDoc sessionId, ObjectName JavaDoc objectName, Object JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback)
76    {
77       ClientListener l = new ClientListener(sessionId, objectName, listener, filter, handback);
78       Object JavaDoc id = makeId(sessionId, objectName, listener);
79       listeners.put(id, l);
80       return id;
81    }
82
83    public static synchronized ClientListener get(Object JavaDoc id)
84    {
85       return (ClientListener) listeners.get(id);
86    }
87
88    static synchronized String JavaDoc dump()
89    {
90       return listeners.toString();
91    }
92
93 }
94
Popular Tags