001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Mathieu Peltier.
021: * Contributor(s): Nicolas Modrzyk, Emmanuel Cecchet.
022: */package org.continuent.sequoia.controller.core;
023:
024: import java.io.File;
025: import java.net.URL;
026: import java.util.Properties;
027:
028: import org.continuent.sequoia.common.util.Constants;
029: import org.continuent.sequoia.common.xml.ControllerXmlTags;
030: import org.continuent.sequoia.common.xml.DatabasesXmlTags;
031:
032: /**
033: * Constants relative to Sequoia controller.
034: *
035: * @author <a href="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
036: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
037: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
038: * @author <a href="mailto:duncan@mightybot.com">Duncan Smith </a>
039: * @version 1.0
040: */
041: public class ControllerConstants {
042: private static final String PROP_FILENAME_RADIX = "controller_default.properties";
043: /**
044: * Controller properties
045: */
046: private static final Properties CONTROLLER_PROPERTIES = new Properties();
047:
048: /** Controller factory to use */
049: public static final ControllerFactory CONTROLLER_FACTORY;
050:
051: static {
052: try {
053: CONTROLLER_PROPERTIES.load(ClassLoader
054: .getSystemResourceAsStream(PROP_FILENAME_RADIX));
055: CONTROLLER_FACTORY = (ControllerFactory) Class.forName(
056: CONTROLLER_PROPERTIES
057: .getProperty("controller.factory"))
058: .newInstance();
059: } catch (Exception e) {
060: throw new ExceptionInInitializerError(
061: "Invalid controller factory ("
062: + CONTROLLER_PROPERTIES
063: .getProperty("controller.factory")
064: + "), fix your " + PROP_FILENAME_RADIX
065: + " file");
066: }
067: }
068:
069: /** Default controller port number value. */
070: public static final String PRODUCT_NAME = CONTROLLER_PROPERTIES
071: .getProperty("product.name");
072:
073: /** Default controller port number value. */
074: public static final int DEFAULT_PORT = Integer
075: .parseInt(CONTROLLER_PROPERTIES.getProperty(
076: "controller.default.port", "25322"));
077:
078: /**
079: * Default IP address to bind controller to.
080: * {@link java.net.InetAddress#anyLocalAddress()}.getHostAddress() would
081: * probably be better.
082: */
083: public static final String DEFAULT_IP = CONTROLLER_PROPERTIES
084: .getProperty("controller.default.ip", "0.0.0.0");
085:
086: /** Default backlog size for driver connections. */
087: public static final int DEFAULT_BACKLOG_SIZE = Integer
088: .parseInt(CONTROLLER_PROPERTIES.getProperty(
089: "controller.default.backlog.size", "10"));
090:
091: /**
092: * Maximum number of characters to display when a SQL statement is logged into
093: * an Exception.
094: */
095: public static final int SQL_SHORT_FORM_LENGTH = Integer
096: .parseInt(CONTROLLER_PROPERTIES.getProperty(
097: "sql.short.form.length", "40"));
098:
099: /**
100: * Doctype for the virtual database config file
101: */
102: public static final String VIRTUAL_DATABASE_DOCTYPE = CONTROLLER_PROPERTIES
103: .getProperty(
104: "virtual.database.doctype",
105: "<!DOCTYPE SEQUOIA PUBLIC \"-//Continuent//DTD SEQUOIA "
106: + Constants.VERSION
107: + "//EN\" \"http://sequoia.continuent.org/dtds/sequoia-"
108: + Constants.VERSION + ".dtd\">");
109: /**
110: * Doctype for the controller config file
111: */
112: public static final String CONTROLLER_DOCTYPE = CONTROLLER_PROPERTIES
113: .getProperty(
114: "virtual.database.doctype",
115: "<!DOCTYPE SEQUOIA-CONTROLLER PUBLIC \"-//Continuent//DTD SEQUOIA-CONTROLLER "
116: + Constants.VERSION
117: + "//EN\" \"http://sequoia.continuent.org/dtds/sequoia-controller-"
118: + Constants.VERSION + ".dtd\">");
119:
120: /** Sequoia DTD file name (must be found in classpath). */
121: public static final String SEQUOIA_DTD_FILE = CONTROLLER_PROPERTIES
122: .getProperty("virtual.database.dtd", "sequoia.dtd");
123:
124: /** Virtual database XML config file rool element name */
125: public static final String VIRTUAL_DATABASE_XML_ROOT_ELEMENT = CONTROLLER_PROPERTIES
126: .getProperty("virtual.database.xml.root.element",
127: DatabasesXmlTags.ELT_SEQUOIA);
128:
129: /** SEQUOIA-CONTROLLER DTD file name (must be found in classpath). */
130: public static final String SEQUOIA_CONTROLLER_DTD_FILE = CONTROLLER_PROPERTIES
131: .getProperty("controller.dtd", "sequoia-controller.dtd");
132:
133: /** Sequoia Controller XML config file root element name */
134: public static final String CONTROLLER_XML_ROOT_ELEMENT = CONTROLLER_PROPERTIES
135: .getProperty("controller.xml.root.element",
136: ControllerXmlTags.ELT_SEQUOIA_CONTROLLER);
137: /**
138: * Default sleep time in ms for a controller worker thread. If no job is ready
139: * after this time, the thread dies.
140: */
141: public static final int DEFAULT_CONTROLLER_WORKER_THREAD_SLEEP_TIME = Integer
142: .parseInt(CONTROLLER_PROPERTIES.getProperty(
143: "controller.default.worker.thread.sleep.time",
144: "15000"));
145:
146: /** JMX Enable by default */
147: public static final boolean JMX_ENABLE = Boolean.valueOf(
148: CONTROLLER_PROPERTIES.getProperty("controller.jmx.enabled",
149: "true")).booleanValue();
150:
151: /** Add Driver enable by default */
152: public static final boolean ADD_DRIVER_ENABLE = Boolean.valueOf(
153: CONTROLLER_PROPERTIES.getProperty(
154: "controller.add.driver.enabled", "false"))
155: .booleanValue();
156:
157: /**
158: * Name of the Sequoia driver JAR file (must be found in classpath). This
159: * information is used to find the drivers directory.
160: */
161: public static final String SEQUOIA_DRIVER_JAR_FILE = CONTROLLER_PROPERTIES
162: .getProperty("controller.driver.jar.file",
163: "/sequoia-driver.jar");
164:
165: /** Default configuration file */
166: public static final String DEFAULT_CONFIG_FILE = CONTROLLER_PROPERTIES
167: .getProperty("controller.default.config.file",
168: "controller.xml");
169:
170: /** Log4j property file resource (must be found in classpath). */
171: public static final String LOG4J_RESOURCE = CONTROLLER_PROPERTIES
172: .getProperty("log4j.properties.file", "/log4j.properties");
173:
174: /** Report file */
175: public static final String REPORT_FILE = CONTROLLER_PROPERTIES
176: .getProperty("controller.report.file", "sequoia.report");
177:
178: /**
179: * Ping interval of idle persistent connections. A value of 0 will mean that
180: * it will never be checked.
181: */
182: public static final int IDLE_PERSISTENT_CONNECTION_PING_INTERVAL = Integer
183: .parseInt(CONTROLLER_PROPERTIES.getProperty(
184: "default.timeout.for.idle.persistent.connection",
185: "0"));
186:
187: /**
188: * Return default path and name for saving of configuration file
189: *
190: * @param resource name of the resource to get save file for
191: * @return path
192: */
193: public static final String getSaveFile(String resource) {
194: URL url = ControllerConstants.class.getResource("/"
195: + DEFAULT_CONFIG_FILE);
196: File dir = (new File(url.getFile())).getParentFile();
197: return dir.getPath() + File.separator + resource + "-saved.xml";
198: }
199:
200: //
201: // Backend auto-enable constants
202: //
203:
204: /** Enable all backend from their last known state at controller start */
205: public static final int AUTO_ENABLE_TRUE = 0;
206: /** Do not enable any backend when starting controller */
207: public static final int AUTO_ENABLE_FALSE = 1;
208: /** Restore the state from an existing recovery log */
209: public static final int AUTO_ENABLE_FORCE = 2;
210:
211: //
212: // VDB load options (implemented using auto-enable backdoor)
213: //
214: /** Initialize state to empty recovery log */
215: public static final int AUTO_ENABLE_INIT = 3;
216: /** Bypass last-man-down checks **/
217: public static final int AUTO_ENABLE_FORCE_LOAD = 4;
218:
219: /** Auto Enable Backend default */
220: public static final int AUTO_ENABLE_BACKEND = AUTO_ENABLE_FALSE;
221:
222: }
|