01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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 6906 2005-06-09 09:55:23Z sauthieg $
22: * --------------------------------------------------------------------------
23: */package org.objectweb.jonas.management;
24:
25: import org.apache.commons.modeler.Registry;
26: import org.objectweb.jonas.server.Server;
27:
28: // JOnAS Log
29: import org.objectweb.jonas.common.Log;
30:
31: // Monolog
32: import org.objectweb.util.monolog.api.Logger;
33: import org.objectweb.util.monolog.api.BasicLevel;
34:
35: /**
36: * Utility MBean classes.
37: * @author Michel-Ange Anton
38: */
39: public class JonasMBeanTools {
40:
41: // ------------------------------------------------------------- Constants
42:
43: private final static String[] PACKAGE_DESCRIPTORS = {
44: "org.objectweb.jonas.server", "org.objectweb.jonas.ear",
45: "org.objectweb.jonas.container",
46: "org.objectweb.jonas.naming", "org.objectweb.jonas.mail",
47: "org.objectweb.jonas.resource", "org.objectweb.jonas.jtm",
48: "org.objectweb.jonas.dbm", "org.objectweb.jonas.ws.mbean" };
49:
50: // ------------------------------------------------------------- Privates variables
51:
52: private static Registry s_Registry = null;
53: private static Logger s_Logger = Log
54: .getLogger(Log.JONAS_MANAGEMENT_PREFIX);
55:
56: // ------------------------------------------------------------- Public methods
57:
58: /**
59: * Load the registry of managed object descriptions.
60: * To load a new mbean-descriptor, add it in the <code>PACKAGE_DESCRIPTORS</code> array.
61: * @return The registry where the descriptors are loaded
62: */
63: public synchronized static Registry getRegistry() {
64:
65: if (s_Registry == null) {
66: // Load registry
67: s_Registry = Registry.getRegistry(null, null);
68: ClassLoader cl = Server.class.getClassLoader();
69:
70: // Load descriptors
71: for (int i = 0; i < PACKAGE_DESCRIPTORS.length; i++) {
72: s_Registry.loadDescriptors(PACKAGE_DESCRIPTORS[i], cl);
73: }
74:
75: // Log loaded descriptors
76: if (s_Logger.isLoggable(BasicLevel.DEBUG)) {
77: String s;
78: String[] as = s_Registry.findManagedBeans();
79: s_Logger.log(BasicLevel.DEBUG,
80: ">>> 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,
86: "<<< List of all MBeans descriptors");
87: }
88: }
89: return (s_Registry);
90: }
91:
92: }
|