1 25 package org.objectweb.jonas.management.j2eemanagement; 26 27 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 32 import javax.management.NotificationListener ; 34 import javax.management.Notification ; 35 36 import org.objectweb.jonas.common.Log; 38 import org.objectweb.util.monolog.api.Logger; 40 import org.objectweb.util.monolog.api.BasicLevel; 41 42 import org.objectweb.jonas.mejb.ListenerProxy; 44 45 49 public class ManagementListener implements ManagementListenerMBean, NotificationListener { 50 static private Logger logger = null; 51 52 ListenerProxy proxy = null; 55 String proxyName = null; 56 57 public ManagementListener(String proxyName) { 58 super(); 59 this.proxyName = proxyName; 60 logger = Log.getLogger("org.objectweb.jonas.management.j2eemanagement.event"); 61 } 62 63 public void handleNotification(Notification notification, Object handback) { 64 if (logger.isLoggable(BasicLevel.DEBUG)) { 65 logger.log(BasicLevel.DEBUG, ""); 66 } 67 if (proxy == null) { 68 try { 69 Context context = new InitialContext (); 70 proxy = (ListenerProxy)javax.rmi.PortableRemoteObject.narrow(context.lookup(proxyName), ListenerProxy.class); 71 } catch (NamingException e) { 72 logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e); 75 return; 76 } 77 } 78 try { 80 proxy.handleNotification(notification, handback); 81 if (logger.isLoggable(BasicLevel.DEBUG)) { 82 logger.log(BasicLevel.DEBUG, "Notification deliverd to ListenerProxy with handback: " + handback.toString()); 83 } 84 } catch (java.rmi.RemoteException e) { 85 try { 87 Context context = new InitialContext (); 88 proxy = (ListenerProxy)javax.rmi.PortableRemoteObject.narrow(context.lookup(proxyName), ListenerProxy.class); 89 proxy.handleNotification(notification, handback); 90 if (logger.isLoggable(BasicLevel.DEBUG)) { 91 logger.log(BasicLevel.DEBUG, "Notification deliverd to ListenerProxy with handback: " + handback.toString()); 92 } 93 } catch (NamingException ne) { 94 logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e); 97 return; 98 } catch (java.rmi.RemoteException re) { 99 logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e); 101 return; 102 } 103 } 104 } 105 106 } 107 | Popular Tags |