KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > core > ControllerConstants


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

23
24 package org.continuent.sequoia.controller.core;
25
26 import java.io.File JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.util.Properties JavaDoc;
30
31 import org.continuent.sequoia.common.util.Constants;
32 import org.continuent.sequoia.common.xml.ControllerXmlTags;
33 import org.continuent.sequoia.common.xml.DatabasesXmlTags;
34
35 /**
36  * Constants relative to Sequoia controller.
37  *
38  * @author <a HREF="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
39  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
40  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
41  * @author <a HREF="mailto:duncan@mightybot.com">Duncan Smith </a>
42  * @version 1.0
43  */

44 public class ControllerConstants
45 {
46   private static final String JavaDoc PROP_FILENAME_RADIX = "controller_default.properties";
47   /**
48    * Controller properties
49    */

50   private static final Properties JavaDoc CONTROLLER_PROPERTIES = new Properties JavaDoc();
51
52   /** Controller factory to use */
53   public static final ControllerFactory CONTROLLER_FACTORY;
54
55   static
56   {
57     try
58     {
59       CONTROLLER_PROPERTIES.load(ClassLoader
60           .getSystemResourceAsStream(PROP_FILENAME_RADIX));
61     }
62     catch (IOException JavaDoc e)
63     {
64       // For some reason ExceptionInInitializerError does not support
65
// initCause(e), so we have to choose between chaining or having
66
// our custom error message
67
throw new ExceptionInInitializerError JavaDoc("Could not load "
68           + PROP_FILENAME_RADIX + " file");
69     }
70     try
71     {
72       CONTROLLER_FACTORY = (ControllerFactory) Class.forName(
73           CONTROLLER_PROPERTIES.getProperty("controller.factory"))
74           .newInstance();
75     }
76     catch (Exception JavaDoc e)
77     {
78       throw new ExceptionInInitializerError JavaDoc("Invalid controller factory ("
79           + CONTROLLER_PROPERTIES.getProperty("controller.factory")
80           + "), fix your " + PROP_FILENAME_RADIX + " file");
81     }
82   }
83
84   /** Product name (defaults to Sequoia) */
85   public static final String JavaDoc PRODUCT_NAME = CONTROLLER_PROPERTIES
86                                                                                             .getProperty(
87                                                                                                 "product.name",
88                                                                                                 "Sequoia");
89
90   /** Default controller port number value. */
91   public static final int DEFAULT_PORT = Integer
92                                                                                         .parseInt(CONTROLLER_PROPERTIES
93                                                                                             .getProperty(
94                                                                                                 "controller.default.port",
95                                                                                                 "25322"));
96
97   /**
98    * Default IP address to bind controller to.
99    * {@link java.net.InetAddress#anyLocalAddress()}.getHostAddress() would
100    * probably be better.
101    */

102   public static final String JavaDoc DEFAULT_IP = CONTROLLER_PROPERTIES
103                                                                                         .getProperty(
104                                                                                             "controller.default.ip",
105                                                                                             "0.0.0.0");
106
107   /** Default backlog size for driver connections. */
108   public static final int DEFAULT_BACKLOG_SIZE = Integer
109                                                                                         .parseInt(CONTROLLER_PROPERTIES
110                                                                                             .getProperty(
111                                                                                                 "controller.default.backlog.size",
112                                                                                                 "10"));
113
114   /**
115    * Maximum number of characters to display when a SQL statement is logged into
116    * an Exception.
117    */

118   public static final int SQL_SHORT_FORM_LENGTH = Integer
119                                                                                         .parseInt(CONTROLLER_PROPERTIES
120                                                                                             .getProperty(
121                                                                                                 "sql.short.form.length",
122                                                                                                 "40"));
123
124   /**
125    * Doctype for the virtual database config file
126    */

127   public static final String JavaDoc VIRTUAL_DATABASE_DOCTYPE = CONTROLLER_PROPERTIES
128                                                                                         .getProperty(
129                                                                                             "virtual.database.doctype",
130                                                                                             "<!DOCTYPE SEQUOIA PUBLIC \"-//Continuent//DTD SEQUOIA "
131                                                                                                 + Constants.VERSION
132                                                                                                 + "//EN\" \"http://sequoia.continuent.org/dtds/sequoia-"
133                                                                                                 + Constants.VERSION
134                                                                                                 + ".dtd\">");
135   /**
136    * Doctype for the controller config file
137    */

138   public static final String JavaDoc CONTROLLER_DOCTYPE = CONTROLLER_PROPERTIES
139                                                                                         .getProperty(
140                                                                                             "virtual.database.doctype",
141                                                                                             "<!DOCTYPE SEQUOIA-CONTROLLER PUBLIC \"-//Continuent//DTD SEQUOIA-CONTROLLER "
142                                                                                                 + Constants.VERSION
143                                                                                                 + "//EN\" \"http://sequoia.continuent.org/dtds/sequoia-controller-"
144                                                                                                 + Constants.VERSION
145                                                                                                 + ".dtd\">");
146
147   /** Sequoia DTD file name (must be found in classpath). */
148   public static final String JavaDoc SEQUOIA_DTD_FILE = CONTROLLER_PROPERTIES
149                                                                                         .getProperty(
150                                                                                             "virtual.database.dtd",
151                                                                                             "sequoia.dtd");
152
153   /** Virtual database XML config file rool element name */
154   public static final String JavaDoc VIRTUAL_DATABASE_XML_ROOT_ELEMENT = CONTROLLER_PROPERTIES
155                                                                                         .getProperty(
156                                                                                             "virtual.database.xml.root.element",
157                                                                                             DatabasesXmlTags.ELT_SEQUOIA);
158
159   /** SEQUOIA-CONTROLLER DTD file name (must be found in classpath). */
160   public static final String JavaDoc SEQUOIA_CONTROLLER_DTD_FILE = CONTROLLER_PROPERTIES
161                                                                                         .getProperty(
162                                                                                             "controller.dtd",
163                                                                                             "sequoia-controller.dtd");
164
165   /** Sequoia Controller XML config file root element name */
166   public static final String JavaDoc CONTROLLER_XML_ROOT_ELEMENT = CONTROLLER_PROPERTIES
167                                                                                         .getProperty(
168                                                                                             "controller.xml.root.element",
169                                                                                             ControllerXmlTags.ELT_SEQUOIA_CONTROLLER);
170   /**
171    * Default sleep time in ms for a controller worker thread. If no job is ready
172    * after this time, the thread dies.
173    */

174   public static final int DEFAULT_CONTROLLER_WORKER_THREAD_SLEEP_TIME = Integer
175                                                                                         .parseInt(CONTROLLER_PROPERTIES
176                                                                                             .getProperty(
177                                                                                                 "controller.default.worker.thread.sleep.time",
178                                                                                                 "15000"));
179
180   /** JMX Enable by default */
181   public static final boolean JMX_ENABLE = Boolean
182                                                                                         .valueOf(
183                                                                                             CONTROLLER_PROPERTIES
184                                                                                                 .getProperty(
185                                                                                                     "controller.jmx.enabled",
186                                                                                                     "true"))
187                                                                                         .booleanValue();
188
189   /** Add Driver enable by default */
190   public static final boolean ADD_DRIVER_ENABLE = Boolean
191                                                                                         .valueOf(
192                                                                                             CONTROLLER_PROPERTIES
193                                                                                                 .getProperty(
194                                                                                                     "controller.add.driver.enabled",
195                                                                                                     "false"))
196                                                                                         .booleanValue();
197
198   /**
199    * Name of the Sequoia driver JAR file (must be found in classpath). This
200    * information is used to find the drivers directory.
201    */

202   public static final String JavaDoc SEQUOIA_DRIVER_JAR_FILE = CONTROLLER_PROPERTIES
203                                                                                         .getProperty(
204                                                                                             "controller.driver.jar.file",
205                                                                                             "/sequoia-driver.jar");
206
207   /** Default configuration file */
208   public static final String JavaDoc DEFAULT_CONFIG_FILE = CONTROLLER_PROPERTIES
209                                                                                         .getProperty(
210                                                                                             "controller.default.config.file",
211                                                                                             "controller.xml");
212
213   /** Log4j property file resource (must be found in classpath). */
214   public static final String JavaDoc LOG4J_RESOURCE = CONTROLLER_PROPERTIES
215                                                                                         .getProperty(
216                                                                                             "log4j.properties.file",
217                                                                                             "/log4j.properties");
218
219   /** Report file */
220   public static final String JavaDoc REPORT_FILE = CONTROLLER_PROPERTIES
221                                                                                         .getProperty(
222                                                                                             "controller.report.file",
223                                                                                             "sequoia.report");
224
225   /**
226    * Ping interval of idle persistent connections. A value of 0 will mean that
227    * it will never be checked.
228    */

229   public static final int IDLE_PERSISTENT_CONNECTION_PING_INTERVAL = Integer
230                                                                                         .parseInt(CONTROLLER_PROPERTIES
231                                                                                             .getProperty(
232                                                                                                 "default.timeout.for.idle.persistent.connection",
233                                                                                                 "0"));
234
235   /**
236    * Return default path and name for saving of configuration file
237    *
238    * @param resource name of the resource to get save file for
239    * @return path
240    */

241   public static final String JavaDoc getSaveFile(String JavaDoc resource)
242   {
243     URL JavaDoc url = ControllerConstants.class.getResource("/" + DEFAULT_CONFIG_FILE);
244     File JavaDoc dir = (new File JavaDoc(url.getFile())).getParentFile();
245     return dir.getPath() + File.separator + resource + "-saved.xml";
246   }
247
248   //
249
// Backend auto-enable constants
250
//
251

252   /** Enable all backend from their last known state at controller start */
253   public static final int AUTO_ENABLE_TRUE = 0;
254   /** Do not enable any backend when starting controller */
255   public static final int AUTO_ENABLE_FALSE = 1;
256   /** Auto Enable Backend default */
257   public static final int AUTO_ENABLE_BACKEND = AUTO_ENABLE_FALSE;
258
259 }
Popular Tags