KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > util > management > MXWrapper


1 /*
2  * Copyright (C) 2001 - 2005 ScalAgent Distributed Technologies
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  */

19 package fr.dyade.aaa.util.management;
20
21 import org.objectweb.util.monolog.api.BasicLevel;
22 import org.objectweb.util.monolog.api.Logger;
23 import org.objectweb.util.monolog.api.LoggerFactory;
24
25 import fr.dyade.aaa.util.Debug;
26
27 public final class MXWrapper {
28   /**
29    * Name of the property that allow to configure the JMX server proxy: it
30    * gives the name of the implementation class of the MXServer interface.
31    * If the property is not defined JMX is not used.
32    */

33   public final static String JavaDoc ServerImpl = "MXServer";
34
35   public static MXServer mxserver = null;
36
37   public static void init() {
38     if (mxserver != null) return;
39
40     String JavaDoc mxname = System.getProperty(ServerImpl);
41
42     // Be careful, do not call Debug.getLogger before initializing the
43
// MXServer (see Debug.init).
44

45     try {
46       if ((mxname != null) && (mxname.length() > 0))
47         Class.forName(mxname).newInstance();
48     } catch (Exception JavaDoc exc) {
49       Debug.getLogger("fr.dyade.aaa.util.management").log(
50         BasicLevel.ERROR, "can't instantiate MXServer: " + mxname, exc);
51     }
52
53     Debug.getLogger("fr.dyade.aaa.util.management").log(
54       BasicLevel.INFO, "MXWrapper.ServerImpl -> " + mxname);
55   }
56
57   public static void registerMBean(Object JavaDoc bean,
58                                    String JavaDoc domain,
59                                    String JavaDoc name) throws Exception JavaDoc {
60     if (mxserver == null) return;
61
62     Debug.getLogger("fr.dyade.aaa.util.management").log(
63       BasicLevel.INFO, "registerMBean: " + name + " -> " + mxserver);
64
65     mxserver.registerMBean(bean, domain, name);
66   }
67
68   public static void unregisterMBean(String JavaDoc domain,
69                                      String JavaDoc name) throws Exception JavaDoc {
70     if (mxserver == null) return;
71
72     Debug.getLogger("fr.dyade.aaa.util.management").log(
73       BasicLevel.INFO, "unregisterMBean: " + name + " -> " + mxserver);
74
75     mxserver.unregisterMBean(domain, name);
76   }
77
78   public static void setMXServer(MXServer server) {
79     Debug.getLogger("fr.dyade.aaa.util.management").log(
80       BasicLevel.INFO, "setMXServer: " + server);
81
82     mxserver = server;
83   }
84
85   public static MXServer getMXServer() {
86     return mxserver;
87   }
88 }
89
Popular Tags