00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.jonas.management.j2eemanagement;
00026
00027
00028 import javax.naming.Context;
00029 import javax.naming.InitialContext;
00030 import javax.naming.NamingException;
00031
00032
00033 import javax.management.NotificationListener;
00034 import javax.management.Notification;
00035
00036
00037 import org.objectweb.jonas.common.Log;
00038
00039 import org.objectweb.util.monolog.api.Logger;
00040 import org.objectweb.util.monolog.api.BasicLevel;
00041
00042
00043 import org.objectweb.jonas.mejb.ListenerProxy;
00044
00049 public class ManagementListener implements ManagementListenerMBean, NotificationListener {
00050 static private Logger logger = null;
00051
00052
00053
00054 ListenerProxy proxy = null;
00055 String proxyName = null;
00056
00057 public ManagementListener(String proxyName) {
00058 super();
00059 this.proxyName = proxyName;
00060 logger = Log.getLogger("org.objectweb.jonas.management.j2eemanagement.event");
00061 }
00062
00063 public void handleNotification(Notification notification, Object handback) {
00064 logger.log(BasicLevel.DEBUG, "");
00065 if (proxy == null) {
00066 try {
00067 Context context = new InitialContext();
00068 proxy = (ListenerProxy)javax.rmi.PortableRemoteObject.narrow(context.lookup(proxyName), ListenerProxy.class);
00069 } catch (NamingException e) {
00070
00071
00072 logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e);
00073 return;
00074 }
00075 }
00076
00077 try {
00078 proxy.handleNotification(notification, handback);
00079 logger.log(BasicLevel.DEBUG, "Notification deliverd to ListenerProxy with handback: " + handback.toString());
00080 } catch (java.rmi.RemoteException e) {
00081
00082 try {
00083 Context context = new InitialContext();
00084 proxy = (ListenerProxy)javax.rmi.PortableRemoteObject.narrow(context.lookup(proxyName), ListenerProxy.class);
00085 proxy.handleNotification(notification, handback);
00086 logger.log(BasicLevel.DEBUG, "Notification deliverd to ListenerProxy with handback: " + handback.toString());
00087 } catch (NamingException ne) {
00088
00089
00090 logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e);
00091 return;
00092 } catch (java.rmi.RemoteException re) {
00093
00094 logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e);
00095 return;
00096 }
00097 }
00098 }
00099
00100 }