You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2001/07/13 08:22:18 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/config ServerXmlReader.java
costin 01/07/12 23:22:17
Modified: src/share/org/apache/tomcat/modules/config
ServerXmlReader.java
Log:
Make sure modules.xml file is configurable.
Another small optimization in startup time, by caching the information
we need in modules.xml and avoiding a parse.
( modules.xml is supposed to grow in future to allow much more decriptive
info about tomcat modules, most of it will be used by the admin interface,
tomcat only need name/class name - sort of taskdef in ant )
This can be turned off as default ( but I don't see any reasons for that ).
A next step would be to cache the result of Hook introspection, and maybe
( a bit more difficult ) the XmlMapper work can be avoided - that should
reduce the startup time to an insignifiant value.
( and of course, allow very small tomcat runtime, without xml or introspection)
I'm not planning any of those for 3.3, but in a new set of config
modules ( that could be used instead of the default one ), after 3.3 is
released.
Revision Changes Path
1.10 +55 -12 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/ServerXmlReader.java
Index: ServerXmlReader.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/config/ServerXmlReader.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ServerXmlReader.java 2001/06/28 07:27:17 1.9
+++ ServerXmlReader.java 2001/07/13 06:22:15 1.10
@@ -94,8 +94,11 @@
// -------------------- Properties --------------------
String configFile=null;
+ String moduleFile=null;
static final String DEFAULT_CONFIG="conf/server.xml";
-
+ static final String DEFAULT_MODULES="conf/modules.xml";
+ boolean useCachedModules=true;// can roll back
+
public void setConfig( String s ) {
configFile=s;
}
@@ -104,6 +107,10 @@
System.getProperties().put("tomcat.home", h);
}
+ public void setModuleConfig( String f ) {
+ moduleFile=f;
+ }
+
// -------------------- Hooks --------------------
/** When this module is added, it'll automatically load
@@ -245,23 +252,59 @@
}
// read modules.xml, if any, and load taskdefs
- public static void addDefaultTags( ContextManager cm, XmlMapper xh)
+ public void addDefaultTags( ContextManager cm, XmlMapper xh)
throws TomcatException
{
if( cm.getNote( "modules" ) != null )
return;
- File f=new File( cm.getHome(), "/conf/modules.xml");
+ if( moduleFile==null ) moduleFile=DEFAULT_MODULES;
+ File f=new File(moduleFile);
+ if ( !f.isAbsolute())
+ f=new File( cm.getHome(), moduleFile );
+
if( f.exists() ) {
- Hashtable modules=new Hashtable();
+ // try cached value
+ File cachedM=new File( cm.getWorkDir() );
+ if( !cachedM.isAbsolute())
+ cachedM=new File( cm.getHome(), cm.getWorkDir());
+ cachedM=new File( cachedM, "modules.properties");
+ Properties modules=new Properties();
cm.setNote( "modules", modules );
- loadConfigFile( xh, f, cm );
- // load module-*.xml
- Vector v = getUserConfigFiles(f);
- for (Enumeration e = v.elements();
- e.hasMoreElements() ; ) {
- f = (File)e.nextElement();
- loadConfigFile(xh,f,cm);
- }
+ if( useCachedModules &&
+ cachedM.exists() &&
+ cachedM.lastModified() > f.lastModified() ) {
+ // XXX check the other modules-foo.xml
+ loadCachedModules(cachedM, modules );
+ return;
+ } else {
+ loadConfigFile( xh, f, cm );
+ // load module-*.xml
+ Vector v = getUserConfigFiles(f);
+ for (Enumeration e = v.elements();
+ e.hasMoreElements() ; ) {
+ f = (File)e.nextElement();
+ loadConfigFile(xh,f,cm);
+ }
+ saveCachedModules(cachedM, modules);
+ }
+ }
+ }
+
+ void loadCachedModules( File f, Properties mods ) {
+ try {
+ FileInputStream pos=new FileInputStream( f );
+ mods.load( pos );
+ } catch(IOException ex ) {
+ log("Error loading modules ", ex );
+ }
+ }
+
+ void saveCachedModules( File f, Properties mods ) {
+ try {
+ FileOutputStream pos=new FileOutputStream( f );
+ mods.save( pos, "Auto-generated cache file");
+ } catch(IOException ex ) {
+ log("Error saving modules ", ex );
}
}