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.MBeanServerConnection ; 15 import javax.management.NotificationListener ; 16 import javax.management.ObjectName ; 17 import javax.management.remote.NotificationResult ; 18 import javax.security.auth.Subject ; 19 20 import mx4j.remote.NotificationTuple; 21 import mx4j.remote.RemoteNotificationServerHandler; 22 import mx4j.tools.remote.AbstractServerInvoker; 23 24 32 public class HTTPServerInvoker extends AbstractServerInvoker implements HTTPConnection 33 { 34 private final RemoteNotificationServerHandler notificationHandler; 35 36 public HTTPServerInvoker(MBeanServerConnection server, RemoteNotificationServerHandler handler) 37 { 38 super(server); 39 this.notificationHandler = handler; 40 } 41 42 public String connect(Object credentials) throws IOException , SecurityException 43 { 44 return null; 45 } 46 47 public void close() throws IOException 48 { 49 NotificationTuple[] tuples = notificationHandler.close(); 50 for (int i = 0; i < tuples.length; ++i) 51 { 52 NotificationTuple tuple = tuples[i]; 53 try 54 { 55 getServer().removeNotificationListener(tuple.getObjectName(), tuple.getNotificationListener(), tuple.getNotificationFilter(), tuple.getHandback()); 56 } 57 catch (InstanceNotFoundException ignored) 58 { 59 } 60 catch (ListenerNotFoundException ignored) 61 { 62 } 63 } 64 } 65 66 public Integer addNotificationListener(ObjectName name, Object filter, Subject delegate) throws InstanceNotFoundException , IOException 67 { 68 Integer id = notificationHandler.generateListenerID(name, null); 69 NotificationListener listener = notificationHandler.getServerNotificationListener(); 70 getServer().addNotificationListener(name, listener, null, id); 71 notificationHandler.addNotificationListener(id, new NotificationTuple(name, listener, null, id)); 72 return id; 73 } 74 75 public void removeNotificationListeners(ObjectName name, Integer [] listenerIDs, Subject delegate) throws InstanceNotFoundException , ListenerNotFoundException , IOException 76 { 77 for (int i = 0; i < listenerIDs.length; ++i) 78 { 79 Integer id = listenerIDs[i]; 80 NotificationTuple tuple = notificationHandler.removeNotificationListener(id); 81 getServer().removeNotificationListener(name, tuple.getNotificationListener(), tuple.getNotificationFilter(), tuple.getHandback()); 82 } 83 } 84 85 public NotificationResult fetchNotifications(long clientSequenceNumber, int maxNotifications, long timeout) throws IOException 86 { 87 return notificationHandler.fetchNotifications(clientSequenceNumber, maxNotifications, timeout); 88 } 89 } 90 | Popular Tags |