1 9 package org.jboss.mx.remoting; 10 11 import java.util.HashMap ; 12 import java.util.Map ; 13 import javax.management.NotificationFilter ; 14 import javax.management.ObjectName ; 15 16 22 public class ClientListener 23 { 24 final ObjectName objectName; 25 final Object listener; 26 final NotificationFilter filter; 27 final Object handback; 28 final String sessionId; 29 30 private static final Map listeners = new HashMap (); 31 32 private ClientListener(String sessionId, ObjectName objectName, Object listener, NotificationFilter filter, Object 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 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 makeId(String sessionId, ObjectName objectName, Object listener) 52 { 53 return sessionId + "/" + objectName + "/" + listener; 54 } 55 56 public static synchronized ClientListener remove(Object id) 57 { 58 return (ClientListener) listeners.remove(id); 59 } 60 61 public static synchronized ClientListener remove(String sessionId, ObjectName objectName, Object listener) 62 { 63 Object 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 register(String sessionId, ObjectName objectName, Object listener, NotificationFilter filter, Object handback) 76 { 77 ClientListener l = new ClientListener(sessionId, objectName, listener, filter, handback); 78 Object id = makeId(sessionId, objectName, listener); 79 listeners.put(id, l); 80 return id; 81 } 82 83 public static synchronized ClientListener get(Object id) 84 { 85 return (ClientListener) listeners.get(id); 86 } 87 88 static synchronized String dump() 89 { 90 return listeners.toString(); 91 } 92 93 } 94 | Popular Tags |