KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > management > JonasMBeanTools


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  * $Id: JonasMBeanTools.java,v 1.8 2005/06/09 09:55:22 sauthieg Exp $
22  * --------------------------------------------------------------------------
23  */

24
25 package org.objectweb.jonas.management;
26
27 import org.apache.commons.modeler.Registry;
28 import org.objectweb.jonas.server.Server;
29
30 // JOnAS Log
31
import org.objectweb.jonas.common.Log;
32
33 // Monolog
34
import org.objectweb.util.monolog.api.Logger;
35 import org.objectweb.util.monolog.api.BasicLevel;
36
37 /**
38  * Utility MBean classes.
39  * @author Michel-Ange Anton
40  */

41 public class JonasMBeanTools {
42
43 // ------------------------------------------------------------- Constants
44

45     private final static String JavaDoc[] PACKAGE_DESCRIPTORS = {
46         "org.objectweb.jonas.server", "org.objectweb.jonas.ear",
47         "org.objectweb.jonas.container", "org.objectweb.jonas.naming",
48         "org.objectweb.jonas.mail",
49         "org.objectweb.jonas.resource", "org.objectweb.jonas.jtm",
50         "org.objectweb.jonas.dbm", "org.objectweb.jonas.ws.mbean"};
51
52 // ------------------------------------------------------------- Privates variables
53

54     private static Registry s_Registry = null;
55     private static Logger s_Logger = Log.getLogger(Log.JONAS_MANAGEMENT_PREFIX);
56
57 // ------------------------------------------------------------- Public methods
58

59     /**
60      * Load the registry of managed object descriptions.
61      * To load a new mbean-descriptor, add it in the <code>PACKAGE_DESCRIPTORS</code> array.
62      * @return The registry where the descriptors are loaded
63      */

64     public synchronized static Registry getRegistry() {
65
66         if (s_Registry == null) {
67             // Load registry
68
s_Registry = Registry.getRegistry(null, null);
69             ClassLoader JavaDoc cl = Server.class.getClassLoader();
70
71             // Load descriptors
72
for (int i = 0; i < PACKAGE_DESCRIPTORS.length; i++) {
73                 s_Registry.loadDescriptors(PACKAGE_DESCRIPTORS[i], cl);
74             }
75
76             // Log loaded descriptors
77
if (s_Logger.isLoggable(BasicLevel.DEBUG)) {
78                 String JavaDoc s;
79                 String JavaDoc[] as = s_Registry.findManagedBeans();
80                 s_Logger.log(BasicLevel.DEBUG, ">>> List of all MBeans descriptors");
81                 for (int i = 0; i < as.length; i++) {
82                     s = ">>> " + i + ") " + as[i];
83                     s_Logger.log(BasicLevel.DEBUG, s);
84                 }
85                 s_Logger.log(BasicLevel.DEBUG, "<<< List of all MBeans descriptors");
86             }
87         }
88         return (s_Registry);
89     }
90
91 }
92
Popular Tags