001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id:
023: * --------------------------------------------------------------------------
024: */
025: package org.objectweb.jonas.management.j2eemanagement;
026:
027: // JNDI
028: import javax.naming.Context;
029: import javax.naming.InitialContext;
030: import javax.naming.NamingException;
031:
032: // JMX
033: import javax.management.NotificationListener;
034: import javax.management.Notification;
035:
036: // JOnAS Log
037: import org.objectweb.jonas.common.Log; // Monolog
038: import org.objectweb.util.monolog.api.Logger;
039: import org.objectweb.util.monolog.api.BasicLevel;
040:
041: // MEJB
042: import org.objectweb.jonas.mejb.ListenerProxy;
043:
044: /**
045: * This MBean is created by the Management EJB in order to listen to notifications emitted
046: * by the MBeans on which the a listener was add by the MEJB's client.
047: */
048: public class ManagementListener implements ManagementListenerMBean,
049: NotificationListener {
050: static private Logger logger = null;
051:
052: // Remote proxy implementing the javax.management.NotificationListener interface
053: // allowing to deliver the notifications to the MEJB's client.
054: ListenerProxy proxy = null;
055: String proxyName = null;
056:
057: public ManagementListener(String proxyName) {
058: super ();
059: this .proxyName = proxyName;
060: logger = Log
061: .getLogger("org.objectweb.jonas.management.j2eemanagement.event");
062: }
063:
064: public void handleNotification(Notification notification,
065: Object handback) {
066: if (logger.isLoggable(BasicLevel.DEBUG)) {
067: logger.log(BasicLevel.DEBUG, "");
068: }
069: if (proxy == null) {
070: try {
071: Context context = new InitialContext();
072: proxy = (ListenerProxy) javax.rmi.PortableRemoteObject
073: .narrow(context.lookup(proxyName),
074: ListenerProxy.class);
075: } catch (NamingException e) {
076: // Could not retrieve listener proxy
077: // ManagementListener is not able to deliver notification
078: logger
079: .log(
080: BasicLevel.WARN,
081: "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:"
082: + e);
083: return;
084: }
085: }
086: // deliver notification to the remote ListenerProxy
087: try {
088: proxy.handleNotification(notification, handback);
089: if (logger.isLoggable(BasicLevel.DEBUG)) {
090: logger.log(BasicLevel.DEBUG,
091: "Notification deliverd to ListenerProxy with handback: "
092: + handback.toString());
093: }
094: } catch (java.rmi.RemoteException e) {
095: // Try to retrive proxy from JNDI
096: try {
097: Context context = new InitialContext();
098: proxy = (ListenerProxy) javax.rmi.PortableRemoteObject
099: .narrow(context.lookup(proxyName),
100: ListenerProxy.class);
101: proxy.handleNotification(notification, handback);
102: if (logger.isLoggable(BasicLevel.DEBUG)) {
103: logger.log(BasicLevel.DEBUG,
104: "Notification deliverd to ListenerProxy with handback: "
105: + handback.toString());
106: }
107: } catch (NamingException ne) {
108: // Could not retrieve listener proxy
109: // ManagementListener is not able to deliver notification
110: logger
111: .log(
112: BasicLevel.WARN,
113: "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:"
114: + e);
115: return;
116: } catch (java.rmi.RemoteException re) {
117: // Could not retrieve listener proxy deliver notification
118: logger
119: .log(
120: BasicLevel.WARN,
121: "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:"
122: + e);
123: return;
124: }
125: }
126: }
127:
128: }
|