KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > management > j2eemanagement > ManagementListener


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id:
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas.management.j2eemanagement;
26
27 // JNDI
28
import javax.naming.Context JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31
32 // JMX
33
import javax.management.NotificationListener JavaDoc;
34 import javax.management.Notification JavaDoc;
35
36 // JOnAS Log
37
import org.objectweb.jonas.common.Log;
38 // Monolog
39
import org.objectweb.util.monolog.api.Logger;
40 import org.objectweb.util.monolog.api.BasicLevel;
41
42 // MEJB
43
import org.objectweb.jonas.mejb.ListenerProxy;
44
45 /**
46  * This MBean is created by the Management EJB in order to listen to notifications emitted
47  * by the MBeans on which the a listener was add by the MEJB's client.
48  */

49 public class ManagementListener implements ManagementListenerMBean, NotificationListener JavaDoc {
50     static private Logger logger = null;
51
52     // Remote proxy implementing the javax.management.NotificationListener interface
53
// allowing to deliver the notifications to the MEJB's client.
54
ListenerProxy proxy = null;
55     String JavaDoc proxyName = null;
56
57     public ManagementListener(String JavaDoc proxyName) {
58         super();
59         this.proxyName = proxyName;
60         logger = Log.getLogger("org.objectweb.jonas.management.j2eemanagement.event");
61     }
62
63     public void handleNotification(Notification JavaDoc notification, Object JavaDoc handback) {
64         if (logger.isLoggable(BasicLevel.DEBUG)) {
65             logger.log(BasicLevel.DEBUG, "");
66         }
67         if (proxy == null) {
68             try {
69                 Context JavaDoc context = new InitialContext JavaDoc();
70                 proxy = (ListenerProxy)javax.rmi.PortableRemoteObject.narrow(context.lookup(proxyName), ListenerProxy.class);
71             } catch (NamingException JavaDoc e) {
72                 // Could not retrieve listener proxy
73
// ManagementListener is not able to deliver notification
74
logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e);
75                 return;
76             }
77         }
78         // deliver notification to the remote ListenerProxy
79
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 JavaDoc e) {
85             // Try to retrive proxy from JNDI
86
try {
87                 Context JavaDoc context = new InitialContext JavaDoc();
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 JavaDoc ne) {
94                 // Could not retrieve listener proxy
95
// ManagementListener is not able to deliver notification
96
logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e);
97                 return;
98             } catch (java.rmi.RemoteException JavaDoc re) {
99                 // Could not retrieve listener proxy deliver notification
100
logger.log(BasicLevel.WARN, "ManagementListener MBean cannot deliver notification to the remote ListenerProxy:" + e);
101                 return;
102             }
103         }
104     }
105
106 }
107
Popular Tags