1 8 9 package mx4j.tools.remote.http; 10 11 import java.io.IOException ; 12 import javax.management.InstanceNotFoundException ; 13 import javax.management.ListenerNotFoundException ; 14 import javax.management.NotificationFilter ; 15 import javax.management.NotificationListener ; 16 import javax.management.ObjectName ; 17 import javax.security.auth.Subject ; 18 19 import mx4j.remote.NotificationTuple; 20 import mx4j.remote.RemoteNotificationClientHandler; 21 import mx4j.tools.remote.JMXConnection; 22 import mx4j.tools.remote.JMXConnectionMBeanServerConnection; 23 24 33 public class HTTPConnectionMBeanServerConnection extends JMXConnectionMBeanServerConnection 34 { 35 private final RemoteNotificationClientHandler notificationHandler; 36 37 public HTTPConnectionMBeanServerConnection(JMXConnection connection, Subject delegate, RemoteNotificationClientHandler notificationHandler) 38 { 39 super(connection, delegate); 40 this.notificationHandler = notificationHandler; 41 } 42 43 public void addNotificationListener(ObjectName observed, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException , IOException 44 { 45 NotificationTuple tuple = new NotificationTuple(observed, listener, filter, handback); 46 tuple.setInvokeFilter(true); 48 if (notificationHandler.contains(tuple)) return; 49 Integer id = ((HTTPConnection)getConnection()).addNotificationListener(observed, null, getDelegateSubject()); 50 notificationHandler.addNotificationListener(id, tuple); 51 } 52 53 public void removeNotificationListener(ObjectName observed, NotificationListener listener) throws InstanceNotFoundException , ListenerNotFoundException , IOException 54 { 55 Integer [] ids = notificationHandler.getNotificationListeners(new NotificationTuple(observed, listener)); 56 if (ids == null) throw new ListenerNotFoundException ("Could not find listener " + listener); 57 try 58 { 59 ((HTTPConnection)getConnection()).removeNotificationListeners(observed, ids, getDelegateSubject()); 60 notificationHandler.removeNotificationListeners(ids); 61 } 62 catch (InstanceNotFoundException x) 63 { 64 notificationHandler.removeNotificationListeners(ids); 65 throw x; 66 } 67 catch (ListenerNotFoundException x) 68 { 69 notificationHandler.removeNotificationListeners(ids); 70 throw x; 71 } 72 } 73 74 public void removeNotificationListener(ObjectName observed, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException , ListenerNotFoundException , IOException 75 { 76 Integer id = notificationHandler.getNotificationListener(new NotificationTuple(observed, listener, filter, handback)); 77 if (id == null) throw new ListenerNotFoundException ("Could not find listener " + listener + " with filter " + filter + " and handback " + handback); 78 Integer [] ids = new Integer []{id}; 79 try 80 { 81 ((HTTPConnection)getConnection()).removeNotificationListeners(observed, ids, getDelegateSubject()); 82 notificationHandler.removeNotificationListeners(ids); 83 } 84 catch (InstanceNotFoundException x) 85 { 86 notificationHandler.removeNotificationListeners(ids); 87 throw x; 88 } 89 catch (ListenerNotFoundException x) 90 { 91 notificationHandler.removeNotificationListeners(ids); 92 throw x; 93 } 94 } 95 } 96 | Popular Tags |