I've noticed a bunch of commits moving away from Commons' ExtendedProperties, towards stratum.configuration.
How stable is stratum.configuration wrt to ExtendedProperties? Would you consider it production-quality? Regards, Kelvin ----- Original Message ----- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, February 06, 2002 11:18 PM Subject: cvs commit: jakarta-turbine-torque/src/java/org/apache/torque/oid IDBroker.java mpoeschl 02/02/06 07:18:56 Modified: src/java/org/apache/torque Torque.java src/java/org/apache/torque/adapter DBFactory.java src/java/org/apache/torque/oid IDBroker.java Log: * make Torque implement Configurable and Initializeable * use the stratum.configuration package instead of ExtendedProperties Revision Changes Path 1.43 +121 -39 jakarta-turbine-torque/src/java/org/apache/torque/Torque.java Index: Torque.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- Torque.java 8 Jan 2002 20:50:07 -0000 1.42 +++ Torque.java 6 Feb 2002 15:18:56 -0000 1.43 @@ -3,7 +3,7 @@ /* ==================================================================== * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -63,7 +63,6 @@ import java.util.List; import java.util.Vector; import java.util.Properties; -import org.apache.commons.collections.ExtendedProperties; import org.apache.log4j.Category; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.helpers.NullEnumeration; @@ -76,6 +75,11 @@ import org.apache.torque.pool.ConnectionPool; import org.apache.torque.pool.DBConnection; import org.apache.torque.util.BasePeer; +import org.apache.stratum.configuration.Configuration; +import org.apache.stratum.configuration.PropertiesConfiguration; +import org.apache.stratum.exception.NestableException; +import org.apache.stratum.lifecycle.Configurable; +import org.apache.stratum.lifecycle.Initializable; /** * The implementation of Torque. @@ -84,9 +88,10 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Magnús Þór Torfason</a> * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a> - * @version $Id: Torque.java,v 1.42 2002/01/08 20:50:07 dlr Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]">Martin Poeschl</a> + * @version $Id: Torque.java,v 1.43 2002/02/06 15:18:56 mpoeschl Exp $ */ -public class Torque +public class Torque implements Initializable, Configurable { /** * Name of property that specifies the default @@ -104,8 +109,8 @@ */ private static String defaultDBName; - /** - * The global cache of database maps + /** + * The global cache of database maps */ private static Map dbMaps; @@ -118,13 +123,13 @@ /** * The logging category. */ - private static Category category = + private static Category category = Category.getInstance(Torque.class.getName()); /** * Torque-specific configuration. */ - private static ExtendedProperties configuration; + private static Configuration configuration; /** * The connection pool monitor. @@ -144,6 +149,83 @@ */ private static List mapBuilders = new Vector(); + + /** + * initialize Torque + * + * @see org.apache.stratum.lifecycle.Initializable + */ + public void initialize() throws Exception + { + // FIX ME!! + // duplicated code init(Configuration) + if (configuration == null) + { + throw new Exception("Torque cannot be initialized without " + + "a valid configuration. Please check the log files " + + "for further details."); + } + + // Setup log4j, I suppose we might want to deal with + // systems other than log4j ... + configureLogging(); + + // Now that we have dealt with processing the log4j properties + // that may be contained in the configuration we will make the + // configuration consist only of the remain torque specific + // properties that are contained in the configuration. First + // look for properties that are in the "torque" namespace. + Configuration originalConf = configuration; + configuration = configuration.subset("torque"); + + if (configuration == null || configuration.isEmpty()) + { + // If there are no properties in the "torque" namespace + // than try the "services.DatabaseService" namespace. This + // will soon be deprecated. + configuration = originalConf.subset("services.DatabaseService"); + + // the configuration may already have any prefixes stripped + if (configuration == null || configuration.isEmpty()) + { + configuration = originalConf; + } + } + + dbMaps = new HashMap(); + pools = new HashMap(); + DBFactory.init(configuration); + + isInit = true; + for (Iterator i = mapBuilders.iterator(); i.hasNext(); ) + { + //this will add any maps in this builder to the proper database map + BasePeer.getMapBuilder((String)i.next()); + } + // any further mapBuilders will be called/built on demand + mapBuilders = null; + + + // Create monitor thread + monitor = new Monitor(); + // Indicate that this is a system thread. JVM will quit only when there + // are no more active user threads. Settings threads spawned internally + // by Turbine as daemons allows commandline applications using Turbine + // to terminate in an orderly manner. + monitor.setDaemon(true); + monitor.start(); + } + + /** + * configure torque + * + * @see org.apache.stratum.lifecycle.Configurable + */ + public void configure(Configuration config) throws NestableException + { + configuration = config; + } + /** * Initialization of Torque with a properties file. * @@ -152,7 +234,7 @@ public static void init(String configFile) throws Exception { - ExtendedProperties c = new ExtendedProperties(configFile); + Configuration c = (Configuration)new PropertiesConfiguration(configFile); init(c); } @@ -161,7 +243,7 @@ * * @param c The Torque configuration. */ - public static void init(ExtendedProperties c) + public static void init(Configuration c) throws Exception { Torque.setConfiguration(c); @@ -170,20 +252,20 @@ throw new Exception("Torque cannot be initialized without " + "a valid configuration. Please check the log files " + "for further details."); - } - + } + // Setup log4j, I suppose we might want to deal with // systems other than log4j ... configureLogging(); - + // Now that we have dealt with processing the log4j properties // that may be contained in the configuration we will make the // configuration consist only of the remain torque specific - // properties that are contained in the configuration. First + // properties that are contained in the configuration. First // look for properties that are in the "torque" namespace. - ExtendedProperties originalConf = configuration; + Configuration originalConf = configuration; configuration = configuration.subset("torque"); - + if (configuration == null || configuration.isEmpty()) { // If there are no properties in the "torque" namespace @@ -195,7 +277,7 @@ if (configuration == null || configuration.isEmpty()) { configuration = originalConf; - } + } } dbMaps = new HashMap(); @@ -203,14 +285,14 @@ DBFactory.init(configuration); isInit = true; - for ( Iterator i=mapBuilders.iterator(); i.hasNext(); ) + for (Iterator i = mapBuilders.iterator(); i.hasNext(); ) { //this will add any maps in this builder to the proper database map BasePeer.getMapBuilder((String)i.next()); } // any further mapBuilders will be called/built on demand mapBuilders = null; - + // Create monitor thread monitor = new Monitor(); @@ -230,7 +312,7 @@ /** * Sets the configuration for Torque and all dependencies. */ - public static void setConfiguration(ExtendedProperties c) + public static void setConfiguration(Configuration c) { configuration = c; } @@ -238,11 +320,11 @@ /** * Get the configuration for this component. */ - public static ExtendedProperties getConfiguration() + public static Configuration getConfiguration() { return configuration; - } - + } + /** * Configure the logging for this subsystem. */ @@ -252,9 +334,9 @@ { // Get the applicationRoot for use in the log4j // properties. - String applicationRoot = + String applicationRoot = getConfiguration().getString("torque.applicationRoot", "."); - + //!! Need a configurable log directory. File logsDir = new File(applicationRoot, "logs"); @@ -267,29 +349,29 @@ } // Extract the log4j values out of the configuration and - // place them in a Properties object so that we can + // place them in a Properties object so that we can // use the log4j PropertyConfigurator. Properties p = new Properties(); p.put("torque.applicationRoot", applicationRoot); - + Iterator i = getConfiguration().getKeys(); while (i.hasNext()) { String key = (String) i.next(); - + // We only want log4j properties. if (key.startsWith("log4j") == false) { continue; } - + // We have to deal with ExtendedProperties way // of dealing with "," in properties which is to // make them separate values. Log4j category // properties contain commas so we must stick them // back together for log4j. String[] values = getConfiguration().getStringArray(key); - + String value; if (values.length == 1) { @@ -298,15 +380,15 @@ else { value = values[0] + "," + values[1]; - } - + } + p.put(key, value); - } - + } + PropertyConfigurator.configure(p); category.info("Logging has been configured by Torque."); } - + } /** @@ -482,7 +564,7 @@ public static void registerMapBuilder(String className) { mapBuilders.add(className); - } + } /** * Returns the specified property of the given database, or the empty @@ -835,7 +917,7 @@ .append(pool.getNbrAvailable()).append(" + ") .append(pool.getNbrCheckedOut()).append(" = ") .append(pool.getTotalCount()); - + category.info(buf.toString()); } @@ -865,10 +947,10 @@ // same object. else if (defaultDBName == null) { - defaultDBName = + defaultDBName = configuration.getString(DATABASE_DEFAULT, DEFAULT_NAME); } - + return defaultDBName; } 1.20 +4 -3 jakarta-turbine-torque/src/java/org/apache/torque/adapter/DBFactory.java Index: DBFactory.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/adapter/DBFactory.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- DBFactory.java 14 Dec 2001 22:14:06 -0000 1.19 +++ DBFactory.java 6 Feb 2002 15:18:56 -0000 1.20 @@ -56,8 +56,9 @@ import java.util.Hashtable; import java.util.Iterator; -import org.apache.commons.collections.ExtendedProperties; import org.apache.log4j.Category; +import org.apache.stratum.configuration.Configuration; + /** * This class creates different {@link org.apache.torque.adapter.DB} @@ -68,7 +69,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Brett McLaughlin</a> * @author <a href="mailto:[EMAIL PROTECTED]">Ralf Stranzenbach</a> * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a> - * @version $Id: DBFactory.java,v 1.19 2001/12/14 22:14:06 brekke Exp $ + * @version $Id: DBFactory.java,v 1.20 2002/02/06 15:18:56 mpoeschl Exp $ */ public class DBFactory { @@ -101,7 +102,7 @@ * configuration is queried to get a list of JDBC drivers and * their associated adapters. */ - public static void init(ExtendedProperties configuration) + public static void init(Configuration configuration) { adapters = new Hashtable(); initializeDriverToAdapterMap(); 1.11 +5 -5 jakarta-turbine-torque/src/java/org/apache/torque/oid/IDBroker.java Index: IDBroker.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/IDBroker.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- IDBroker.java 26 Nov 2001 23:46:16 -0000 1.10 +++ IDBroker.java 6 Feb 2002 15:18:56 -0000 1.11 @@ -64,8 +64,8 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.List; -import org.apache.commons.collections.ExtendedProperties; import org.apache.log4j.Category; +import org.apache.stratum.configuration.Configuration; import org.apache.torque.Torque; import org.apache.torque.TorqueException; import org.apache.torque.map.DatabaseMap; @@ -113,7 +113,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Frank Y. Kim</a> * @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a> - * @version $Id: IDBroker.java,v 1.10 2001/11/26 23:46:16 jmcnally Exp $ + * @version $Id: IDBroker.java,v 1.11 2002/02/06 15:18:56 mpoeschl Exp $ */ public class IDBroker implements Runnable, IdGenerator @@ -196,7 +196,7 @@ */ private static final BigDecimal ONE = new BigDecimal("1"); - private ExtendedProperties configuration; + private Configuration configuration; private static final String DB_IDBROKER_CLEVERQUANTITY = "idbroker.clever.quantity"; @@ -219,7 +219,7 @@ { this.tableMap = tMap; configuration = Torque.getConfiguration(); - + // Start the housekeeper thread only if prefetch has not been disabled if (configuration.getBoolean(DB_IDBROKER_PREFETCH, true)) { @@ -270,7 +270,7 @@ } } - public void setConfiguration(ExtendedProperties configuration) + public void setConfiguration(Configuration configuration) { this.configuration = configuration; } -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>