--- projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java 2000/11/29 21:27:08 1.5 +++ projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java 2000/12/12 18:26:52 1.6 @@ -2,11 +2,9 @@ package uk.ac.ukc.iscream.core; //---IMPORTS--- -import uk.ac.ukc.iscream.core.*; +import uk.ac.ukc.iscream.util.*; import java.util.*; import java.io.*; -import org.omg.CORBA.*; -import org.omg.PortableServer.*; /** * This class is essentially a Configuration factory. @@ -19,8 +17,13 @@ import org.omg.PortableServer.*; * * It also relies on the System.properties to set internal values. * + * ### + * A point to note is that this class does NOT yet manage + * created configurations which may cause memory problems! + * ### + * * @author $Author: ajm $ - * @version $Id: ConfigurationManagerServant.java,v 1.5 2000/11/29 21:27:08 ajm Exp $ + * @version $Id: ConfigurationManagerServant.java,v 1.6 2000/12/12 18:26:52 ajm Exp $ */ class ConfigurationManagerServant extends ConfigurationManagerPOA { @@ -29,7 +32,7 @@ class ConfigurationManagerServant extends Configuratio /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.5 $"; + public final String REVISION = "$Revision: 1.6 $"; //---STATIC METHODS--- @@ -38,14 +41,9 @@ class ConfigurationManagerServant extends Configuratio /** * Creates a new ConfiguratorServant * This class uses the System.properties to set internal values - * - * @param rootPOARef a reference to the RootPOA - * @param logRef a reference to the Logger */ - ConfigurationManagerServant(POA rootPOARef, Logger logRef) { + ConfigurationManagerServant() { // assign some local variables - _rootPOARef = rootPOARef; - _logRef = logRef; _configPath = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation"); _systemConfigFile = System.getProperty("uk.ac.ukc.iscream.SystemConfigurationFile"); @@ -53,9 +51,9 @@ class ConfigurationManagerServant extends Configuratio loadSystemConfig(); // log our status - _logRef.write(this.toString(), Logger.SYSINIT, "started"); - _logRef.write(this.toString(), Logger.SYSMSG, "configuration location - " + _configPath); - _logRef.write(this.toString(), Logger.SYSMSG, "system configuration file - " + _systemConfigFile); + _logger.write(toString(), Logger.SYSINIT, "started"); + _logger.write(toString(), Logger.SYSMSG, "configuration location - " + _configPath); + _logger.write(toString(), Logger.SYSMSG, "system configuration file - " + _systemConfigFile); } //---PUBLIC METHODS--- @@ -80,26 +78,26 @@ class ConfigurationManagerServant extends Configuratio * @return the Configuration */ public Configuration getConfiguration(String source) { - _logRef.write(this.toString(), Logger.SYSMSG, "got request for " + source); + _logger.write(toString(), Logger.SYSMSG, "got request for " + source); Configuration config = null; // check to see if we need to reload the system config // because it has changed if (isModified(_systemConfig.getFileList(), _systemConfig.getLastModified())) { - _logRef.write(this.toString(), Logger.SYSMSG, "system config changed"); + _logger.write(toString(), Logger.SYSMSG, "system config changed"); loadSystemConfig(); } // we look for this entry in the systemConfig String configFile = _systemConfig.getProperty("config." + source); - _logRef.write(this.toString(), Logger.DEBUG, "looking for config tree in - " + configFile); + _logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile); // if there is an entry if (configFile != null) { try { // get the file list of includes etc + the system config String fileList = _systemConfigFile + ";" + getIncludedFiles(configFile, ""); - _logRef.write(this.toString(), Logger.DEBUG, "config tree - " + fileList); + _logger.write(toString(), Logger.DEBUG, "config tree - " + fileList); // build the properites here from the filelist.... StringTokenizer st = new StringTokenizer(fileList, ";"); @@ -131,19 +129,19 @@ class ConfigurationManagerServant extends Configuratio } while (st.hasMoreTokens()); // this creates the configuration, all nice, ready to be returned - ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified, _logRef); - org.omg.CORBA.Object objRef = _rootPOARef.servant_to_reference(ref); + ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified); + org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); config = ConfigurationHelper.narrow(objRef); } catch (Exception e) { // not sure what to do here - System.err.println("CONFIGURATION MANAGER ERROR: " + e); - e.printStackTrace(System.out); + // so we just log the error + _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage()); } // if there isn't an entry for the requested config } else { - _logRef.write(this.toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile); + _logger.write(toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile); config = _systemConfig; } @@ -176,15 +174,21 @@ class ConfigurationManagerServant extends Configuratio } return false; } - + /** * Overrides the {@link java.lang.Object#toString() Object.toString()} * method to provide clean logging (every class should have this). * + * This uses the uk.ac.ukc.iscream.util.FormatName class + * to format the toString() + * * @return the name of this class and its CVS revision */ public String toString() { - return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; + return FormatName.getName( + _name, + getClass().getName(), + REVISION); } //---PRIVATE METHODS--- @@ -261,7 +265,7 @@ class ConfigurationManagerServant extends Configuratio * local reference _systemConfig */ private void loadSystemConfig() { - _logRef.write(this.toString(), Logger.SYSMSG, "reloading " + _systemConfigFile); + _logger.write(this.toString(), Logger.SYSMSG, "reloading " + _systemConfigFile); // get a reference to the system config and store it try { // create the properties for the configuration @@ -270,14 +274,14 @@ class ConfigurationManagerServant extends Configuratio systemConfigHolder.load(new FileInputStream(systemConfigFile)); // create the servant - ConfigurationServant ref = new ConfigurationServant(systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified(), _logRef); - org.omg.CORBA.Object objRef = _rootPOARef.servant_to_reference(ref); + ConfigurationServant ref = new ConfigurationServant(systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified()); + org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); // narrow it to a Configuration _systemConfig = ConfigurationHelper.narrow(objRef); } catch (Exception e) { - _logRef.write(this.toString(), Logger.FATAL, "ERROR: " + e.getMessage()); + _logger.write(toString(), Logger.FATAL, "ERROR: " + e.getMessage()); } } @@ -286,14 +290,26 @@ class ConfigurationManagerServant extends Configuratio //---ATTRIBUTES--- /** - * Local storage of the RootPOA + * This is the friendly identifier of the + * component this class is running in. + * eg, a Filter may be called "filter1", + * If this class does not have an owning + * component, a name from the configuration + * can be placed here. This name could also + * be changed to null for utility classes. */ - private POA _rootPOARef; + private String _name = Core.NAME; + + /** + * This holds a reference to the + * system logger that is being used. + */ + private Logger _logger = ReferenceManager.getInstance().getLogger(); /** - * Local storage of the Logger + * A reference to the reference manager in use */ - private Logger _logRef; + private ReferenceManager _refman = ReferenceManager.getInstance(); /** * The root path to all configurations