KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jmx > AbsJmxServiceImpl


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 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  * $Id: AbsJmxServiceImpl.java,v 1.17 2005/04/28 08:43:24 benoitf Exp $
22  * --------------------------------------------------------------------------
23  */

24 package org.objectweb.jonas.jmx;
25
26 import java.util.List JavaDoc;
27
28 import javax.management.MBeanServer JavaDoc;
29 import javax.management.MBeanServerFactory JavaDoc;
30 import javax.management.remote.JMXServiceURL JavaDoc;
31 import javax.naming.Context JavaDoc;
32 import javax.naming.NamingException JavaDoc;
33
34 import org.objectweb.jonas.common.Log;
35 import org.objectweb.jonas.service.AbsServiceImpl;
36 import org.objectweb.jonas.service.ServiceException;
37 import org.objectweb.util.monolog.api.BasicLevel;
38 import org.objectweb.util.monolog.api.Logger;
39
40 /**
41  * JMX Service implementation. This singleton class must exist in each jonas
42  * server that is to be administered via JMX. Its main role is to initialize the
43  * service (the singleton object).
44  * @author Guillaume Riviere
45  * @author Michel Bruno
46  * @author Adriana Danes
47  */

48
49 public abstract class AbsJmxServiceImpl extends AbsServiceImpl implements JmxService {
50
51     /**
52      * Trace logger
53      */

54     private static Logger logger = null;
55
56     /**
57      * @return Logger logger object
58      */

59     protected static Logger getLogger() {
60         return logger;
61     }
62
63     /**
64      * JMX server (MBean server) instance
65      */

66     private MBeanServer JavaDoc jmxServer = null;
67
68     /**
69      * Init the Service. Create the MBeanServer. Configuration information is
70      * passed through a Context object.
71      * @param ctx context containing service initilaisation parameters
72      * @exception ServiceException the service could not be initialized
73      */

74     public void doInit(Context JavaDoc ctx) throws ServiceException {
75         logger = Log.getLogger(Log.JONAS_JMX_PREFIX);
76         super.initLogger(Log.getLogger(Log.JONAS_MANAGEMENT_PREFIX));
77
78         // Create the MBeanServer
79

80         // get Id
81
String JavaDoc idMBeanServer = null;
82         try {
83             idMBeanServer = (String JavaDoc) ctx.lookup("idMBeanServer");
84         } catch (NamingException JavaDoc ne) {
85             throw new ServiceException("Cannot found the id of the MBean Server", ne);
86         }
87
88         // ----------------------
89
List JavaDoc mbeanServers = MBeanServerFactory.findMBeanServer(idMBeanServer);
90         if (mbeanServers.size() == 0) {
91             throw new ServiceException("No MBean server found for id '" + idMBeanServer + "'.");
92         }
93         if (logger.isLoggable(BasicLevel.DEBUG)) {
94             logger.log(BasicLevel.DEBUG, "Use first MBean server ID found");
95         }
96         jmxServer = (MBeanServer JavaDoc) mbeanServers.get(0);
97
98         if (logger.isLoggable(BasicLevel.DEBUG)) {
99             logger.log(BasicLevel.DEBUG, "JMX Service initialized");
100         }
101     }
102
103     /**
104      * Start the Service Initialization of the service is already done.
105      * @exception ServiceException the service could not be started
106      */

107     public abstract void doStart() throws ServiceException;
108
109     /**
110      * Stop this service
111      * @exception ServiceException the service could not be stoped
112      */

113     public abstract void doStop() throws ServiceException;
114
115     public abstract JMXServiceURL JavaDoc[] getConnectorServerURLs();
116
117     /**
118      * @return The local reference of the MBean server
119      */

120     public MBeanServer JavaDoc getJmxServer() {
121         return this.jmxServer;
122     }
123
124     /**
125      * Remove internal references to the MBeanServer.
126      */

127     protected void releaseJmxServer() {
128         try {
129             MBeanServerFactory.releaseMBeanServer(jmxServer);
130         } catch (java.lang.IllegalArgumentException JavaDoc ex) {
131             // The mbeanServer is not found.
132
logger.log(BasicLevel.ERROR, "Cannot find the MBeanServer" + ex);
133         }
134     }
135
136 }
Popular Tags