KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > jmx > JmxConstants


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): _______________________.
23  */

24
25 package org.objectweb.cjdbc.common.jmx;
26
27 import javax.management.ObjectName JavaDoc;
28
29 /**
30  * This class contains static information on the jmx services.
31  *
32  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
33  * @version 1.0
34  */

35 public final class JmxConstants
36 {
37   /** Overall Debug tag for Jmx calls */
38   public static final boolean DEBUG = false;
39
40   /** Keep connection alive ? */
41   public static final boolean KEEP_CONNECTION_ALIVE = true;
42
43   /** Default domain name for JMX */
44   public static final String JavaDoc JMX_DEFAULT_DOMAIN_NAME = "jmx";
45   /** Default Jmx type */
46   public static final String JavaDoc JMX_DEFAULT_MBEAN_TYPE = "mbean";
47
48   /** Reference name for Jndi */
49   public static final String JavaDoc JndiName = "jrmp";
50
51   /** The default jmx name for the agent to connect to */
52   public static final String JavaDoc DEFAULT_JMX_AGENT_NAME = "default";
53
54   /** RMI Adaptor */
55   public static final String JavaDoc ADAPTOR_TYPE_RMI = "rmiAdaptor";
56
57   /** ssl config for rmi */
58   public static final String JavaDoc CONNECTOR_RMI_SSL = "jmx.rmi.ssl";
59
60   /** Http adaptor */
61   public static final String JavaDoc ADAPTOR_TYPE_HTTP = "httpAdaptor";
62
63   /** jmx authenticator username */
64   public static final String JavaDoc CONNECTOR_AUTH_USERNAME = "jmx.auth.username";
65   /** jmx authenticator password */
66   public static final String JavaDoc CONNECTOR_AUTH_PASSWORD = "jmx.auth.password";
67
68   /** Default RMI port number value. */
69   public static final int DEFAULT_JMX_RMI_PORT = 1090;
70
71   /** Default JMX server HTTP adaptor port value. */
72   public static final int DEFAULT_JMX_HTTP_PORT = 8090;
73
74   /**
75    * This is in the xsl transformation file, so we should leave as is. Other
76    * domain are filtered.
77    */

78   public static final String JavaDoc CJDBC_DOMAIN_NAME = "c-jdbc";
79
80   /** the controller mbean type */
81   public static final String JavaDoc CJDBC_TYPE_CONTROLLER = "controller";
82   /** the virtual database mbean type */
83   public static final String JavaDoc CJDBC_TYPE_VIRTUALDATABASE = "virtualdatabase";
84   /** the data collector mbean type */
85   public static final String JavaDoc CJDBC_TYPE_DATACOLLECTOR = "datacollector";
86   /** the backend mbean type */
87   public static final String JavaDoc CJDBC_TYPE_BACKEND = "backend";
88   /** the recovery log mbean type */
89   private static final String JavaDoc CJDBC_TYPE_RECOVERYLOG = "recoverylog";
90   /** the cache mbean type */
91   private static final String JavaDoc CJDBC_TYPE_CACHE = "cache";
92   /** the request manager mbean type */
93   private static final String JavaDoc CJDBC_TYPE_REQUEST_MANAGER = "requestmanager";
94
95   private static final String JavaDoc CJDBC_TYPE_LOAD_BALANCER = "loadbalancer"; ;
96
97   /**
98    * Get the associated jmx object name
99    *
100    * @param name the name of the mbean
101    * @param type the c-jdbc type of the mbean
102    * @return the associated object name, no exception is thrown as the object
103    * name calculated is always valid ex;
104    * c-jdbc:type:=&lt;type&gt;:name:=&lt;name&gt;
105    */

106   public static ObjectName JavaDoc getJmxObjectName(String JavaDoc name, String JavaDoc type)
107   {
108     try
109     {
110       return new ObjectName JavaDoc(CJDBC_DOMAIN_NAME + ":type=" + type + ",name="
111           + name);
112     }
113     catch (Exception JavaDoc e)
114     {
115       e.printStackTrace();
116       // impossible?
117
return null;
118     }
119   }
120
121   /**
122    * Get the associated controller object name
123    *
124    * @return c-jdbc:type:=&lt;controller&gt;:name:=&lt;name&gt;
125    */

126   public static ObjectName JavaDoc getControllerObjectName()
127   {
128     return getJmxObjectName(CJDBC_TYPE_CONTROLLER, CJDBC_TYPE_CONTROLLER);
129   }
130
131   /**
132    * Get the associated virtualdatabase object name
133    *
134    * @param name the name of the virtualdatabase
135    * @return c-jdbc:type:=&lt;virtualdatabase&gt;:name:=&lt;name&gt;
136    */

137   public static ObjectName JavaDoc getVirtualDbObjectName(String JavaDoc name)
138   {
139     return getJmxObjectName(name, CJDBC_TYPE_VIRTUALDATABASE);
140   }
141
142   /**
143    * Get the associated data collector object name
144    *
145    * @return c-jdbc:type:=&lt;datacollector&gt;:name:=&lt;name&gt;
146    */

147   public static ObjectName JavaDoc getDataCollectorObjectName()
148   {
149     return getJmxObjectName(CJDBC_TYPE_DATACOLLECTOR, CJDBC_TYPE_DATACOLLECTOR);
150   }
151
152   /**
153    * Get the associated data collector object name
154    *
155    * @param vdbName name of the virtual database
156    * @param name name of the backend
157    * @return c-jdbc:type:=&lt;datacollector&gt;:name:=&lt;name&gt;
158    */

159   public static ObjectName JavaDoc getDatabaseBackendObjectName(String JavaDoc vdbName,
160       String JavaDoc name)
161   {
162     return getJmxObjectName(vdbName + "--" + name, CJDBC_TYPE_BACKEND);
163   }
164
165   /**
166    * Get the associated recovery log object name
167    *
168    * @param vdbName name of the virtual database
169    * @return c-jdbc:type:=&lt;recoverylog&gt;:name:=&lt;name&gt;
170    */

171   public static ObjectName JavaDoc getRecoveryLogObjectName(String JavaDoc vdbName)
172   {
173     return getJmxObjectName(vdbName + "--recoverylog", CJDBC_TYPE_RECOVERYLOG);
174   }
175
176   /**
177    * Get the associated cache object name
178    *
179    * @param vdbName name of the virtual database
180    * @return c-jdbc:type:=&lt;cache&gt;:name:=&lt;name&gt;
181    */

182   public static ObjectName JavaDoc getCacheObjectName(String JavaDoc vdbName)
183   {
184     return getJmxObjectName(vdbName + "--cache", CJDBC_TYPE_CACHE);
185   }
186
187   /**
188    * Get the associated request manager object name
189    *
190    * @param vdbName name of the virtual database
191    * @return c-jdbc:type:=&lt;requestmanager&gt;:name:=&lt;name&gt;
192    */

193   public static ObjectName JavaDoc getRequestManagerObjectName(String JavaDoc vdbName)
194   {
195     return getJmxObjectName(vdbName + "--requestmanager",
196         CJDBC_TYPE_REQUEST_MANAGER);
197   }
198
199   /**
200    * Retrieve the owning database objectname of this backend's objectname
201    *
202    * @param backend the objectname of the backend
203    * @return the objectname of the owning database.
204    */

205   public static ObjectName JavaDoc getVirtualDbObjectNameFromBackend(ObjectName JavaDoc backend)
206   {
207     String JavaDoc name = backend.toString();
208     int ind1 = name.indexOf("name=") + 5;
209     int ind2 = name.indexOf("--", ind1);
210     String JavaDoc vdbName = name.substring(ind1, ind2);
211     return getJmxObjectName(vdbName, CJDBC_TYPE_VIRTUALDATABASE);
212   }
213
214   /**
215    * Get the associated request manager object name
216    *
217    * @param name name of the virtual database
218    * @return c-jdbc:type:=&lt;--loadbalancer&gt;:name:=&lt;name&gt;
219    */

220   public static ObjectName JavaDoc getLoadBalancerObjectName(String JavaDoc name)
221   {
222     return getJmxObjectName(name + "--loadbalancer", CJDBC_TYPE_LOAD_BALANCER);
223   }
224
225   /**
226    * C-JDBC rules to determine if a mbean need authentication or not. By default
227    * all the mbeans need authentication apart from the controller mbean and the
228    * data collector mbean
229    *
230    * @param mbean <tt>ObjectName</tt> of the mbean to test
231    * @return <tt>true</tt> if the call to the mbean should have a user and a
232    * password attribute attached to it.
233    */

234   public static boolean mbeanNeedAuthentication(ObjectName JavaDoc mbean)
235   {
236     return (mbean.toString().indexOf(CJDBC_TYPE_CONTROLLER) == -1 && mbean
237         .toString().indexOf(CJDBC_TYPE_DATACOLLECTOR) == -1);
238   }
239
240 }
Popular Tags