KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > jmx > JmxConstants


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Nicolas Modrzyk.
20  * Contributor(s): _______________________.
21  */

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

36 public final class JmxConstants
37 {
38
39   /** RMI Adaptor */
40   public static final String JavaDoc ADAPTOR_TYPE_RMI = "rmiAdaptor"; //$NON-NLS-1$
41

42   /** jmx authenticator username */
43   public static final String JavaDoc CONNECTOR_AUTH_USERNAME = "jmx.auth.username"; //$NON-NLS-1$
44
/** jmx authenticator password */
45   public static final String JavaDoc CONNECTOR_AUTH_PASSWORD = "jmx.auth.password"; //$NON-NLS-1$
46

47   /** Default RMI port number value. */
48   public static final int DEFAULT_JMX_RMI_PORT = 1090;
49
50   /**
51    * This is in the xsl transformation file, so we should leave as is. Other
52    * domain are filtered.
53    */

54   private static final String JavaDoc SEQUOIA_DOMAIN_NAME = "sequoia"; //$NON-NLS-1$
55

56   /** the controller mbean type */
57   private static final String JavaDoc CONTROLLER_TYPE_VALUE = "Controller"; //$NON-NLS-1$
58
/** the virtual database mbean type */
59   public static final String JavaDoc VIRTUALDATABASE_TYPE_VALUE = "VirtualDataBase"; //$NON-NLS-1$
60
/** the data collector mbean type */
61   public static final String JavaDoc DATABASEBACKEND_TYPE_VALUE = "VirtualDataBase.Backend"; //$NON-NLS-1$
62

63   private static final String JavaDoc DATACOLLECTOR_TYPE_VALUE = "datacollector"; //$NON-NLS-1$
64

65   private static final String JavaDoc DATACOLLECTOR = "datacollector"; //$NON-NLS-1$
66
/** the cache mbean type */
67   private static final String JavaDoc SEQUOIA_TYPE_CACHE = "cache"; //$NON-NLS-1$
68

69   private static final String JavaDoc CONTROLLER_OBJECTNAME = "sequoia:type=Controller"; //$NON-NLS-1$
70
// 0 => virtual database name
71
private static final String JavaDoc VIRTUALDATABASE_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase,name={0}"; //$NON-NLS-1$
72
// 0 => virtual database name, 1 => backend name
73
private static final String JavaDoc DATABASEBACKEND_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.Backend,VirtualDataBase={0},name={1}"; //$NON-NLS-1$
74
// 0 => vdb name, 1 => backend name
75
private static final String JavaDoc BACKENDTASKQUEUES_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.Backend.TaskQueues,VirtualDataBase={0},Backend={1}"; //$NON-NLS-1$
76
// 0 => vdb name
77
private static final String JavaDoc RECOVERYLOG_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.RecoveryLog,VirtualDataBase={0}"; //$NON-NLS-1$
78
// 0 => vdb name
79
private static final String JavaDoc LOADBALANCER_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.LoadBalancer,VirtualDataBase={0}"; //$NON-NLS-1$
80
// 0 => vdb name
81
private static final String JavaDoc REQUESTMANAGER_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.RequestManager,VirtualDataBase={0}"; //$NON-NLS-1$
82
// 0 => vdb name
83
private static final String JavaDoc ABSTRACTSCHEDULER_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.AbstractScheduler,VirtualDataBase={0}"; //$NON-NLS-1$
84
// 0 => vdb name
85
private static final String JavaDoc PARSINGCACHE_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.RequestManager.ParsingCache,VirtualDataBase={0}"; //$NON-NLS-1$
86

87   /** Virtual database property name */
88   public static final String JavaDoc VIRTUALDATABASE_PROPERTY = "VirtualDataBase"; //$NON-NLS-1$
89

90   /**
91    * Get the associated jmx object name
92    *
93    * @param name the name of the mbean
94    * @param type the sequoia type of the mbean
95    * @return the associated object name, no exception is thrown as the object
96    * name calculated is always valid ex;
97    * sequoia:type:=&lt;type&gt;:name:=&lt;name&gt;
98    */

99   private static ObjectName JavaDoc getJmxObjectName(String JavaDoc name, String JavaDoc type)
100   {
101     try
102     {
103       return new ObjectName JavaDoc(SEQUOIA_DOMAIN_NAME + ":type=" + type + ",name="
104           + name);
105     }
106     catch (Exception JavaDoc e)
107     {
108       e.printStackTrace();
109       // impossible?
110
return null;
111     }
112   }
113
114   /**
115    * Get the associated controller object name
116    *
117    * @return the ObjectName associated to a controller
118    * @throws MalformedObjectNameException if the provided name is not correct
119    * @see JmxConstants#CONTROLLER_OBJECTNAME
120    */

121   public static ObjectName JavaDoc getControllerObjectName()
122       throws MalformedObjectNameException JavaDoc
123   {
124     return new ObjectName JavaDoc(CONTROLLER_OBJECTNAME);
125   }
126
127   /**
128    * Get the objectname associated with a virtualdatabase
129    *
130    * @param virtualDataBaseName the name of the virtualdatabase
131    * @return sequoia:type:=&lt;virtualdatabase&gt;:name:=&lt;name&gt;
132    * @throws MalformedObjectNameException if the provided name is not correct
133    */

134   public static ObjectName JavaDoc getVirtualDataBaseObjectName(
135       String JavaDoc virtualDataBaseName) throws MalformedObjectNameException JavaDoc
136   {
137     return new ObjectName JavaDoc(MessageFormat.format(
138         VIRTUALDATABASE_OBJECTNAME_PATTERN, new String JavaDoc[]{virtualDataBaseName}));
139   }
140
141   /**
142    * Get the associated data collector object name
143    *
144    * @return sequoia:type:=&lt;datacollector&gt;:name:=&lt;name&gt;
145    */

146   public static ObjectName JavaDoc getDataCollectorObjectName()
147   {
148     return getJmxObjectName(DATACOLLECTOR, DATACOLLECTOR_TYPE_VALUE);
149   }
150
151   /**
152    * Get the object name associated with a backend on a given virtual database
153    *
154    * @param virtualDataBaseName name of the virtual database
155    * @param name name of the backend
156    * @return the object name associated with a backend on a given virtual
157    * database
158    * @throws MalformedObjectNameException if the provided name is not correct
159    */

160   public static ObjectName JavaDoc getDatabaseBackendObjectName(
161       String JavaDoc virtualDataBaseName, String JavaDoc name)
162       throws MalformedObjectNameException JavaDoc
163   {
164     return new ObjectName JavaDoc(MessageFormat.format(
165         DATABASEBACKEND_OBJECTNAME_PATTERN, new String JavaDoc[]{virtualDataBaseName,
166             name}));
167   }
168
169   /**
170    * Get the object name associated with the recovery log on a given virtual
171    * database
172    *
173    * @param vdbName name of the virtual database
174    * @return the object name associated with the recovery log on a given virtual
175    * database
176    * @throws MalformedObjectNameException if the provided name is not correct
177    */

178   public static ObjectName JavaDoc getRecoveryLogObjectName(String JavaDoc vdbName)
179       throws MalformedObjectNameException JavaDoc
180   {
181     return new ObjectName JavaDoc(MessageFormat.format(RECOVERYLOG_OBJECTNAME_PATTERN,
182         new String JavaDoc[]{vdbName}));
183   }
184
185   /**
186    * Get the associated cache object name
187    *
188    * @param vdbName name of the virtual database
189    * @return sequoia:type:=&lt;cache&gt;:name:=&lt;name&gt;
190    */

191   public static ObjectName JavaDoc getCacheObjectName(String JavaDoc vdbName)
192   {
193     return getJmxObjectName(vdbName + "--cache", SEQUOIA_TYPE_CACHE);
194   }
195
196   /**
197    * Return the object name associated to the request manager of a given virtual
198    * database.
199    *
200    * @param vdbName name of the virtual database
201    * @return return the object name associated to the request manager of a given
202    * virtual database
203    * @throws MalformedObjectNameException if the object name is malformed
204    * @see #REQUESTMANAGER_OBJECTNAME_PATTERN
205    */

206   public static ObjectName JavaDoc getRequestManagerObjectName(String JavaDoc vdbName)
207       throws MalformedObjectNameException JavaDoc
208   {
209     return new ObjectName JavaDoc(MessageFormat.format(
210         REQUESTMANAGER_OBJECTNAME_PATTERN, new String JavaDoc[]{vdbName}));
211   }
212
213   /**
214    * Return the object name associated to the load balancer of a given virtual
215    * database.
216    *
217    * @param vdbName name of the virtual database
218    * @return return the object name associated to the load balancer of a given
219    * virtual database
220    * @throws MalformedObjectNameException if the object name is malformed
221    * @see #LOADBALANCER_OBJECTNAME_PATTERN
222    */

223   public static ObjectName JavaDoc getLoadBalancerObjectName(String JavaDoc vdbName)
224       throws MalformedObjectNameException JavaDoc
225   {
226     return new ObjectName JavaDoc(MessageFormat.format(LOADBALANCER_OBJECTNAME_PATTERN,
227         new String JavaDoc[]{vdbName}));
228   }
229
230   /**
231    * Return the object name associated to the task queues of a given backend.
232    *
233    * @param vdbName name of the virtual database managing the backend
234    * @param backendName name of the backend
235    * @return return the object name associated to the task queues of a given
236    * backend
237    * @throws MalformedObjectNameException if the object name is malformed
238    * @see #BACKENDTASKQUEUES_OBJECTNAME_PATTERN
239    */

240   public static ObjectName JavaDoc getBackendTaskQueuesObjectName(String JavaDoc vdbName,
241       String JavaDoc backendName) throws MalformedObjectNameException JavaDoc
242   {
243     return new ObjectName JavaDoc(MessageFormat.format(
244         BACKENDTASKQUEUES_OBJECTNAME_PATTERN,
245         new String JavaDoc[]{vdbName, backendName}));
246   }
247
248   /**
249    * Gets the object name of the given vdb scheduler
250    *
251    * @param vdbName name of the virtual database
252    * @return object name associated to the given virtual database scheduler
253    * @throws MalformedObjectNameException if the provided vdb name is incorrect
254    */

255   public static ObjectName JavaDoc getAbstractSchedulerObjectName(String JavaDoc vdbName)
256       throws MalformedObjectNameException JavaDoc
257   {
258     return new ObjectName JavaDoc(MessageFormat.format(
259         ABSTRACTSCHEDULER_OBJECTNAME_PATTERN, new String JavaDoc[]{vdbName}));
260   }
261
262   /**
263    * Gets the object name of the given vdb request manager parsing cache
264    *
265    * @param vdbName name of the virtual database
266    * @return object name associated to the given virtual database scheduler
267    * @throws MalformedObjectNameException if the provided vdb name is incorrect
268    */

269   public static ObjectName JavaDoc getParsingCacheObjectName(String JavaDoc vdbName)
270       throws MalformedObjectNameException JavaDoc
271   {
272     return new ObjectName JavaDoc(MessageFormat.format(PARSINGCACHE_OBJECTNAME_PATTERN,
273         new String JavaDoc[]{vdbName}));
274   }
275
276   /**
277    * Sequoia rules to determine if a mbean need authentication or not. By
278    * default all the mbeans need authentication apart from the controller mbean
279    * and the data collector mbean
280    *
281    * @param mbean <tt>ObjectName</tt> of the mbean to test
282    * @return <tt>true</tt> if the call to the mbean should have a user and a
283    * password attribute attached to it.
284    */

285   public static boolean mbeanNeedAuthentication(ObjectName JavaDoc mbean)
286   {
287     String JavaDoc type = mbean.getKeyProperty("type"); //$NON-NLS-1$
288
if (type == null)
289     {
290       return false;
291     }
292     if (type.equalsIgnoreCase(CONTROLLER_TYPE_VALUE)
293         || type.equalsIgnoreCase(DATACOLLECTOR_TYPE_VALUE))
294     {
295       return false;
296     }
297     else
298     {
299       return true;
300     }
301   }
302 }
Popular Tags