1 8 9 package mx4j.remote.rmi; 10 11 import java.io.IOException ; 12 import java.security.AccessController ; 13 import java.security.PrivilegedAction ; 14 import java.util.Map ; 15 16 import javax.management.remote.NotificationResult ; 17 import javax.management.remote.rmi.RMIConnection ; 18 19 import mx4j.remote.AbstractRemoteNotificationClientHandler; 20 import mx4j.remote.ConnectionNotificationEmitter; 21 import mx4j.remote.HeartBeat; 22 23 28 public class RMIRemoteNotificationClientHandler extends AbstractRemoteNotificationClientHandler 29 { 30 private final RMIConnection connection; 31 private final ClassLoader defaultLoader; 32 33 public RMIRemoteNotificationClientHandler(RMIConnection connection, ClassLoader defaultLoader, ConnectionNotificationEmitter emitter, HeartBeat heartbeat, Map environment) 34 { 35 super(emitter, heartbeat, environment); 36 this.connection = connection; 37 this.defaultLoader = defaultLoader; 38 } 39 40 protected NotificationResult fetchNotifications(long sequence, int maxNumber, long timeout) throws IOException 41 { 42 ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); 43 if (defaultLoader == null || defaultLoader.equals(currentLoader)) 44 { 45 return invokeFetchNotifications(sequence, maxNumber, timeout); 46 } 47 else 48 { 49 try 50 { 51 setContextClassLoader(defaultLoader); 52 return invokeFetchNotifications(sequence, maxNumber, timeout); 53 } 54 finally 55 { 56 setContextClassLoader(currentLoader); 57 } 58 } 59 } 60 61 private NotificationResult invokeFetchNotifications(long sequence, int maxNumber, long timeout) throws IOException 62 { 63 return connection.fetchNotifications(sequence, maxNumber, timeout); 64 } 65 66 private void setContextClassLoader(final ClassLoader loader) 67 { 68 AccessController.doPrivileged(new PrivilegedAction () 69 { 70 public Object run() 71 { 72 Thread.currentThread().setContextClassLoader(loader); 73 return null; 74 } 75 }); 76 } 77 } 78 | Popular Tags |