ManagementListener.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: 
00023  * --------------------------------------------------------------------------
00024  */
00025 package org.objectweb.jonas.management.j2eemanagement;
00026 
00027 // JNDI
00028 import javax.naming.Context;
00029 import javax.naming.InitialContext;
00030 import javax.naming.NamingException;
00031 
00032 // JMX
00033 import javax.management.NotificationListener;
00034 import javax.management.Notification;
00035 
00036 // JOnAS Log
00037 import org.objectweb.jonas.common.Log;
00038 // Monolog
00039 import org.objectweb.util.monolog.api.Logger;
00040 import org.objectweb.util.monolog.api.BasicLevel;
00041 
00042 // MEJB
00043 import org.objectweb.jonas.mejb.ListenerProxy;
00044 
00049 public class ManagementListener implements ManagementListenerMBean, NotificationListener {
00050     static private Logger logger = null;
00051 
00052     // Remote proxy implementing the javax.management.NotificationListener interface
00053     // allowing to deliver the notifications to the MEJB's client.
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                 // Could not retrieve listener proxy
00071                 // ManagementListener is not able to deliver notification
00072                 logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e);
00073                 return;
00074             }
00075         }
00076         // deliver notification to the remote ListenerProxy
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             // Try to retrive proxy from JNDI
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                 // Could not retrieve listener proxy
00089                 // ManagementListener is not able to deliver notification
00090                 logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e);
00091                 return;
00092             } catch (java.rmi.RemoteException re) {
00093                 // Could not retrieve listener proxy deliver notification
00094                 logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e);
00095                 return;
00096             }
00097         }
00098     }
00099 
00100 }

Generated on Tue Feb 15 15:05:18 2005 for JOnAS by  doxygen 1.3.9.1