cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r124234 - in cocoon/trunk: . src/blocks/cron/WEB-INF/xconf src/blocks/hsqldb/WEB-INF/xconf src/blocks/python/java/org/apache/cocoon/components/language/programming/python src/blocks/slide/conf src/blocks/xmldb/conf src/blocks/xsp/java/org/apache/cocoon/acting src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript src/core/java/org/apache/cocoon/components src/core/java/org/apache/cocoon/core/container src/core/test/org/apache/cocoon/core/container src/java/org/apache/cocoon src/java/org/apache/cocoon/components/container src/java/org/apache/cocoon/components/treeprocessor src/java/org/apache/cocoon/components/treeprocessor/sitemap src/test/org/apache/cocoon
Date Wed, 05 Jan 2005 17:42:37 GMT
Author: sylvain
Date: Wed Jan  5 09:42:34 2005
New Revision: 124234

URL: http://svn.apache.org/viewcvs?view=rev&rev=124234
Log:
New lazy mode to load components, which heavily speeds up Cocoon initialization time
Added:
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/LazyHandler.java   (contents, props changed)
Modified:
   cocoon/trunk/src/blocks/cron/WEB-INF/xconf/cocoon-cron.xconf
   cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf
   cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java
   cocoon/trunk/src/blocks/slide/conf/slide-servlet.xweb
   cocoon/trunk/src/blocks/xmldb/conf/xindice-servlet.xweb
   cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java
   cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java
   cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java
   cocoon/trunk/src/core/java/org/apache/cocoon/components/ServiceInfo.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/DefaultServiceSelector.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java
   cocoon/trunk/src/core/test/org/apache/cocoon/core/container/ContainerTestCase.java
   cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java
   cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles
   cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
   cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
   cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java
   cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java
   cocoon/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java
   cocoon/trunk/status.xml

Modified: cocoon/trunk/src/blocks/cron/WEB-INF/xconf/cocoon-cron.xconf
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/cron/WEB-INF/xconf/cocoon-cron.xconf?view=diff&rev=124234&p1=cocoon/trunk/src/blocks/cron/WEB-INF/xconf/cocoon-cron.xconf&r1=124233&p2=cocoon/trunk/src/blocks/cron/WEB-INF/xconf/cocoon-cron.xconf&r2=124234
==============================================================================
--- cocoon/trunk/src/blocks/cron/WEB-INF/xconf/cocoon-cron.xconf	(original)
+++ cocoon/trunk/src/blocks/cron/WEB-INF/xconf/cocoon-cron.xconf	Wed Jan  5 09:42:34 2005
@@ -18,7 +18,7 @@
 <components>
     <component role="org.apache.cocoon.components.cron.JobScheduler"
                class="org.apache.cocoon.components.cron.CocoonQuartzJobScheduler"
-               logger="cron">
+               logger="cron" preload="true">
       <!--+
           | Definitions for a thread pool used to schedule jobs
           +-->

Modified: cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf?view=diff&rev=124234&p1=cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf&r1=124233&p2=cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf&r2=124234
==============================================================================
--- cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf	(original)
+++ cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf	Wed Jan  5 09:42:34 2005
@@ -27,7 +27,7 @@
       +-->
   <hsqldb-server class="org.apache.cocoon.components.hsqldb.ServerImpl"
                  logger="core.hsqldb-server"
-                 pool-max="1" pool-min="1">
+                 preload="true">
      <parameter name="port" value="9002"/>
      <parameter name="silent" value="true"/>
      <parameter name="trace" value="false"/>

Modified: cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java?view=diff&rev=124234&p1=cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java&r1=124233&p2=cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java&r2=124234
==============================================================================
--- cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java	(original)
+++ cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java	Wed Jan  5 09:42:34 2005
@@ -21,11 +21,9 @@
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceManager;
 
-import org.apache.cocoon.components.ServiceInfo;
 import org.apache.cocoon.components.language.programming.Program;
 import org.apache.cocoon.components.language.generator.CompiledComponent;
 import org.apache.cocoon.core.container.AbstractComponentHandler;
-import org.apache.cocoon.core.container.ComponentEnvironment;
 import org.apache.cocoon.core.container.ComponentHandler;
 
 import java.io.File;
@@ -67,16 +65,9 @@
     public ComponentHandler getHandler(ServiceManager manager,
                                        Context context)
     throws Exception {
-        final ComponentEnvironment env = new ComponentEnvironment();
-        env.serviceManager = manager;
-        env.context = context;
-        env.logger = this.getLogger();
-        final ServiceInfo info = new ServiceInfo();
-        info.setConfiguration(config);
-        info.setServiceClass(clazz);
-        
+
         return AbstractComponentHandler.getComponentHandler(
-                null, info, env, null);
+                clazz, getLogger(), context, manager, config);
     }
 
     public CompiledComponent newInstance() throws Exception {

Modified: cocoon/trunk/src/blocks/slide/conf/slide-servlet.xweb
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/slide/conf/slide-servlet.xweb?view=diff&rev=124234&p1=cocoon/trunk/src/blocks/slide/conf/slide-servlet.xweb&r1=124233&p2=cocoon/trunk/src/blocks/slide/conf/slide-servlet.xweb&r2=124234
==============================================================================
--- cocoon/trunk/src/blocks/slide/conf/slide-servlet.xweb	(original)
+++ cocoon/trunk/src/blocks/slide/conf/slide-servlet.xweb	Wed Jan  5 09:42:34 2005
@@ -160,7 +160,9 @@
                 of interoperability problems.
             </description>
         </init-param>
-        <load-on-startup>2</load-on-startup>
+        <!-- Uncomment this to load slide servlet on startup -->
+        <!--load-on-startup>2</load-on-startup-->
+
         <!-- Uncomment this to get authentication -->
         <!--security-role-ref>
             <role-name>root</role-name>

Modified: cocoon/trunk/src/blocks/xmldb/conf/xindice-servlet.xweb
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xmldb/conf/xindice-servlet.xweb?view=diff&rev=124234&p1=cocoon/trunk/src/blocks/xmldb/conf/xindice-servlet.xweb&r1=124233&p2=cocoon/trunk/src/blocks/xmldb/conf/xindice-servlet.xweb&r2=124234
==============================================================================
--- cocoon/trunk/src/blocks/xmldb/conf/xindice-servlet.xweb	(original)
+++ cocoon/trunk/src/blocks/xmldb/conf/xindice-servlet.xweb	Wed Jan  5 09:42:34 2005
@@ -36,6 +36,7 @@
       <param-value>WEB-INF/xindice.xml</param-value>
     </init-param>
 
-    <load-on-startup>1</load-on-startup>
+    <!-- Uncomment to load the xindice servlet on startup-->
+    <!--load-on-startup>1</load-on-startup-->
   </servlet>
 </xweb>

Modified: cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java?view=diff&rev=124234&p1=cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java&r1=124233&p2=cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java&r2=124234
==============================================================================
--- cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java	(original)
+++ cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java	Wed Jan  5 09:42:34 2005
@@ -25,11 +25,9 @@
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.thread.ThreadSafe;
 
-import org.apache.cocoon.components.ServiceInfo;
 import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
 import org.apache.cocoon.components.sax.XMLByteStreamFragment;
 import org.apache.cocoon.core.container.AbstractComponentHandler;
-import org.apache.cocoon.core.container.ComponentEnvironment;
 import org.apache.cocoon.core.container.ComponentHandler;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Redirector;
@@ -90,18 +88,12 @@
     public void configure(Configuration conf)
     throws ConfigurationException {
         try {
-            final ComponentEnvironment env = new ComponentEnvironment();
-            env.serviceManager = this.manager;
-            env.logger = this.getLogger();
-            final ServiceInfo info = new ServiceInfo();
-            info.setConfiguration(conf);
-            info.setServiceClass(ServerPagesGenerator.class);
-            
             this.generatorHandler = AbstractComponentHandler.getComponentHandler(
-                null,  // role
-                info,
-                env,
-                null   // RoleManager
+                ServerPagesGenerator.class,
+                this.getLogger(),
+                null,  // Context
+                this.manager,
+                conf
             );
 
             this.generatorHandler.initialize();

Modified: cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java?view=diff&rev=124234&p1=cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java&r1=124233&p2=cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java&r2=124234
==============================================================================
--- cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java	(original)
+++ cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java	Wed Jan  5 09:42:34 2005
@@ -20,11 +20,9 @@
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceManager;
 
-import org.apache.cocoon.components.ServiceInfo;
 import org.apache.cocoon.components.language.generator.CompiledComponent;
 import org.apache.cocoon.components.language.programming.Program;
 import org.apache.cocoon.core.container.AbstractComponentHandler;
-import org.apache.cocoon.core.container.ComponentEnvironment;
 import org.apache.cocoon.core.container.ComponentHandler;
 
 /**
@@ -49,18 +47,13 @@
     public ComponentHandler getHandler(ServiceManager manager,
                                        Context context)
     throws Exception {
-        final ComponentEnvironment env = new ComponentEnvironment();
-        env.serviceManager = manager;
-        env.context = context;
-        env.logger = this.getLogger();
-        final ServiceInfo info = new ServiceInfo();
-        info.setConfiguration(new DefaultConfiguration("", "GeneratorSelector"));
-        info.setServiceClass(program);
 
         return AbstractComponentHandler.getComponentHandler(
-                null, // role
-                info,
-                env, null);
+                program,
+                getLogger(),
+                context,
+                manager,
+                new DefaultConfiguration("", "GeneratorSelector"));
     }
 
     public CompiledComponent newInstance() throws Exception {

Modified: cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java?view=diff&rev=124234&p1=cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java&r1=124233&p2=cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java&r2=124234
==============================================================================
--- cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java	(original)
+++ cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java	Wed Jan  5 09:42:34 2005
@@ -21,11 +21,9 @@
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceManager;
 
-import org.apache.cocoon.components.ServiceInfo;
 import org.apache.cocoon.components.language.generator.CompiledComponent;
 import org.apache.cocoon.components.language.programming.Program;
 import org.apache.cocoon.core.container.AbstractComponentHandler;
-import org.apache.cocoon.core.container.ComponentEnvironment;
 import org.apache.cocoon.core.container.ComponentHandler;
 
 import java.io.File;
@@ -69,16 +67,9 @@
     public ComponentHandler getHandler(ServiceManager manager,
                                        Context context)
     throws Exception {
-        final ComponentEnvironment env = new ComponentEnvironment();
-        env.serviceManager = manager;
-        env.context = context;
-        env.logger = this.getLogger();
-        final ServiceInfo info = new ServiceInfo();
-        info.setConfiguration(this.config);
-        info.setServiceClass(clazz);
 
         return AbstractComponentHandler.getComponentHandler(
-                null, info, env, null);
+                clazz, getLogger(), context, manager, config);
     }
 
     public CompiledComponent newInstance() throws Exception {

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/components/ServiceInfo.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/components/ServiceInfo.java?view=diff&rev=124234&p1=cocoon/trunk/src/core/java/org/apache/cocoon/components/ServiceInfo.java&r1=124233&p2=cocoon/trunk/src/core/java/org/apache/cocoon/components/ServiceInfo.java&r2=124234
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/components/ServiceInfo.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/components/ServiceInfo.java	Wed Jan  5 09:42:34 2005
@@ -33,7 +33,6 @@
     private String destroyMethodName;
     private String poolInMethodName;
     private String poolOutMethodName;
-    private Class serviceClass;
     private String serviceClassName;
     private Configuration configuration;
     
@@ -110,13 +109,6 @@
     public void setPoolOutMethodName(String poolMethod) {
         this.poolOutMethodName = poolMethod;
     }
-
-    /**
-     * @return Returns the serviceClass.
-     */
-    public Class getServiceClass() {
-        return serviceClass;
-    }
     
     /**
      * @return Returns the serviceClassName.
@@ -132,13 +124,6 @@
         this.serviceClassName = serviceClassName;
     }
     
-    /**
-     * @param serviceClass The serviceClass to set.
-     */
-    public void setServiceClass(Class serviceClass) {
-        this.serviceClass = serviceClass;
-    }
-        
     /**
      * @return Returns the configuration.
      */

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java?view=diff&rev=124234&p1=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java&r1=124233&p2=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java&r2=124234
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java	Wed Jan  5 09:42:34 2005
@@ -16,9 +16,16 @@
  */
 package org.apache.cocoon.core.container;
 
+import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.excalibur.pool.Poolable;
 import org.apache.avalon.framework.component.Composable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.thread.SingleThreaded;
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.components.ServiceInfo;
@@ -44,87 +51,95 @@
     private boolean initialized = false;
     
     private ServiceInfo info;
-
+    
     /**
      * Looks up and returns a component handler for a given component class.
      *
      * @param role the component's role. Can be <code>null</code> if the role isn't known.
-     * @param componentClass Class of the component for which the handle is
+     * @param className Class of the component for which the handle is
      *                       being requested.
      * @param configuration The configuration for this component.
-     * @param serviceManager The service manager which will be managing the service.
-     * @param context The current context object.
-     * @param logger  The current logger
-     * @param loggerManager The current LoggerManager.
+     * @param componentEnv The component's creation environment.
      *
      * @throws Exception If there were any problems obtaining a ComponentHandler
      */
-    public static ComponentHandler getComponentHandler( final String role,
-                                                        final ServiceInfo info,
-                                                        final ComponentEnvironment env,
-                                                        final RoleManager roleManager)
-    throws Exception {
+    public static ComponentHandler getComponentHandler(
+            String role, String className, Configuration configuration, ComponentEnvironment componentEnv) throws Exception {
+        
+        // Load the class
+        Class componentClass;
+        
+        try {
+            componentClass = componentEnv.loadClass(className);
+        } catch(ClassNotFoundException cnfe) {
+            throw new ConfigurationException("Cannot find class " + className + " for component at " +
+                    configuration.getLocation(), cnfe);
+        }
+
         int numInterfaces = 0;
 
-        // FIXME we don't need the class but a classloader
-        info.setServiceClassName(info.getServiceClass().getName());
+        final ServiceInfo info = new ServiceInfo();
+        info.setServiceClassName(className);
+        info.setConfiguration(configuration);
         
         // Early check for Composable
-        if ( Composable.class.isAssignableFrom( info.getServiceClass() ) ) {
+        if ( Composable.class.isAssignableFrom( componentClass ) ) {
             throw new Exception("Interface Composable is not supported anymore. Please change class "
-                                + info.getServiceClassName() + " to use Serviceable instead.");
+                                + componentClass.getName() + " to use Serviceable instead.");
         }
 
-        if( SingleThreaded.class.isAssignableFrom( info.getServiceClass() ) ) {
+        if( SingleThreaded.class.isAssignableFrom( componentClass ) ) {
             numInterfaces++;
             info.setModel(ServiceInfo.MODEL_PRIMITIVE);
         }
 
-        if( ThreadSafe.class.isAssignableFrom( info.getServiceClass() ) ) {
+        if( ThreadSafe.class.isAssignableFrom( componentClass ) ) {
             numInterfaces++;
             info.setModel(ServiceInfo.MODEL_SINGLETON);
         }
 
-        if( Poolable.class.isAssignableFrom( info.getServiceClass() ) ) {
+        if( Poolable.class.isAssignableFrom( componentClass ) ) {
             numInterfaces++;
             info.setModel(ServiceInfo.MODEL_POOLED);
         }
 
         if( numInterfaces > 1 ) {
             throw new Exception( "[CONFLICT] More than one lifecycle interface in "
-                                 + info.getServiceClassName() + "  May implement no more than one of "
+                                 + componentClass.getName() + "  May implement no more than one of "
                                  + "SingleThreaded, ThreadSafe, or Poolable" );
         }
 
         if ( numInterfaces == 0 ) {
             // this component does not use avalon interfaces, so get the info from the configuration
-            info.fill(info.getConfiguration());
+            info.fill(configuration);
         }
         
         // Create the factory to use to create the instances of the Component.
         ComponentFactory factory;
-        
-        if (DefaultServiceSelector.class.isAssignableFrom(info.getServiceClass())) {
+        ComponentHandler handler;
+                
+        if (DefaultServiceSelector.class.isAssignableFrom(componentClass)) {
             // Special factory for DefaultServiceSelector
-            factory = new DefaultServiceSelector.Factory(env, roleManager, info, role);
+            factory = new DefaultServiceSelector.Factory(componentEnv, info, role);
+            handler = new ThreadSafeComponentHandler(info, componentEnv.logger, factory);
+            handler.initialize();
+            return handler;
             
-        } else if (StandaloneServiceSelector.class.isAssignableFrom(info.getServiceClass())) {
+        } else if (StandaloneServiceSelector.class.isAssignableFrom(componentClass)) {
             // Special factory for StandaloneServiceSelector
-            factory = new StandaloneServiceSelector.Factory(env, roleManager, info, role);
+            factory = new StandaloneServiceSelector.Factory(componentEnv, info, role);
                 
         } else {
-            factory = new ComponentFactory(env, info);
+            factory = new ComponentFactory(componentEnv, info);
         }
 
-        ComponentHandler handler;
-        
         if( info.getModel() == ServiceInfo.MODEL_POOLED )  {
-            handler = new PoolableComponentHandler( info, env.logger, factory, info.getConfiguration() );
+            handler = new PoolableComponentHandler( info, componentEnv.logger, factory, configuration );
         } else if( info.getModel() == ServiceInfo.MODEL_SINGLETON ) {
-            handler = new ThreadSafeComponentHandler( info, env.logger, factory );
+            handler = new ThreadSafeComponentHandler( info, componentEnv.logger, factory );
         } else {
             // This is a SingleThreaded component
-            handler = new SingleThreadedComponentHandler( info, env.logger, factory );
+            handler = new SingleThreadedComponentHandler( info, componentEnv.logger, factory );
         }
 
         return handler;
@@ -256,4 +271,13 @@
     }
     
     protected abstract void doInitialize() throws Exception;
+
+    /**
+     * Create a component handler (version used by XSP)
+     */
+    public static ComponentHandler getComponentHandler(Class clazz, Logger logger, Context context, ServiceManager manager, Configuration config) throws Exception {
+        ComponentEnvironment env = new ComponentEnvironment(clazz.getClassLoader(), logger, null, null, context, manager);
+        return getComponentHandler(null, clazz.getName(), config, env);
+
+    }
 }

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java?view=diff&rev=124234&p1=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java&r1=124233&p2=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java&r2=124234
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java	Wed Jan  5 09:42:34 2005
@@ -31,7 +31,6 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.components.ServiceInfo;
 
 /**
  * Base class for all service managers: ServiceManager and ServiceSelector
@@ -62,6 +61,8 @@
 
     /** LoggerManager. */
     protected LoggerManager loggerManager;
+    
+    protected ComponentEnvironment componentEnv;
 
     
     /* (non-Javadoc)
@@ -94,18 +95,19 @@
      * @throws Exception If there were any problems obtaining a ComponentHandler
      */
     protected ComponentHandler getComponentHandler( final String role,
-                                                    final ServiceInfo info,
+                                                    final Class componentClass,
+                                                    final Configuration configuration,
                                                     final ServiceManager serviceManager)
     throws Exception {
-        final ComponentEnvironment env = new ComponentEnvironment();
-        env.serviceManager = serviceManager;
-        env.context = context;
-        env.logger = this.getLogger();
-        env.loggerManager = this.loggerManager;
+        if (this.componentEnv == null) {
+            this.componentEnv = new ComponentEnvironment(null, getLogger(), this.roleManager,
+                    this.loggerManager, this.context, serviceManager);
+        }
+        
         return AbstractComponentHandler.getComponentHandler(role,
-                                                     info,
-                                                     env,
-                                                     this.roleManager);
+                                                     componentClass.getName(),
+                                                     configuration,
+                                                     this.componentEnv);
     }
 
     protected void addComponent(String className,

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java?view=diff&rev=124234&p1=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java&r1=124233&p2=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java&r2=124234
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java	Wed Jan  5 09:42:34 2005
@@ -29,10 +29,33 @@
  */
 public class ComponentEnvironment {
 
-    public ServiceManager serviceManager;
-    public Context context;
-    public Logger logger;
-    public LoggerManager loggerManager;
-    public ClassLoader classloader;
+    public final ServiceManager serviceManager;
+    public final Context context;
+    public final Logger logger;
+    public final RoleManager roleManager;
+    public final LoggerManager loggerManager;
+    private final ClassLoader classLoader;
     
+    public ComponentEnvironment(ClassLoader classLoader, Logger logger, RoleManager roleManager, LoggerManager loggerManager,
+            Context context, ServiceManager serviceManager) {
+
+        // Find a class loader
+        if (classLoader == null) {
+            classLoader = Thread.currentThread().getContextClassLoader();
+            if (classLoader == null) {
+                classLoader = this.getClass().getClassLoader();
+            }            
+        }
+
+        this.classLoader = classLoader;
+        this.logger = logger;
+        this.roleManager = roleManager;
+        this.loggerManager = loggerManager;
+        this.context = context;
+        this.serviceManager = serviceManager;
+    }
+
+    public Class loadClass(String name) throws ClassNotFoundException {
+        return this.classLoader.loadClass(name);
+    }
 }

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java?view=diff&rev=124234&p1=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java&r1=124233&p2=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java&r2=124234
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java	Wed Jan  5 09:42:34 2005
@@ -36,6 +36,11 @@
     
     protected final ComponentEnvironment environment;
     
+    /**
+     * The component's logger, which may be different from the environment's logger
+     */
+    protected final Logger componentLogger;
+    
     /** The parameters for this component
      */
     protected Parameters parameters;
@@ -69,17 +74,9 @@
                 actualLogger = this.environment.loggerManager.getLoggerForCategory(category);
             }
         }
-        this.environment.logger = actualLogger;
+        this.componentLogger = actualLogger;
         
-        // now get the meta data for the component
-        // FIXME - this is a workaround
-        if ( this.environment.classloader == null ) {
-            this.environment.classloader = Thread.currentThread().getContextClassLoader();
-            if ( this.environment.classloader == null ) {
-                this.environment.classloader = this.getClass().getClassLoader();
-            }            
-        }
-        this.serviceClass = this.environment.classloader.loadClass(this.serviceInfo.getServiceClassName());
+        this.serviceClass = this.environment.loadClass(this.serviceInfo.getServiceClassName());
         if ( this.serviceInfo.getDestroyMethodName() != null ) {
             this.destroyMethod = this.serviceClass.getMethod(this.serviceInfo.getDestroyMethodName(), null);
         } else {
@@ -124,7 +121,7 @@
                     this.serviceClass.getName() + "." );
         }
 
-        ContainerUtil.enableLogging(component, this.environment.logger);
+        ContainerUtil.enableLogging(component, this.componentLogger);
         ContainerUtil.contextualize( component, this.environment.context );
         ContainerUtil.service( component, this.environment.serviceManager );
         ContainerUtil.configure( component, this.serviceInfo.getConfiguration() );

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java?view=diff&rev=124234&p1=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java&r1=124233&p2=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java&r2=124234
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java	Wed Jan  5 09:42:34 2005
@@ -18,21 +18,30 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
+import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.components.ServiceInfo;
 import org.apache.cocoon.core.source.SimpleSourceResolver;
 import org.apache.excalibur.source.Source;
@@ -45,8 +54,8 @@
  * @version SVN $Revision: 1.6 $Id$
  */
 public class CoreServiceManager
-extends AbstractServiceManager
-implements ServiceManager, Configurable {
+        extends AbstractLogEnabled
+        implements Contextualizable, ThreadSafe, Disposable, Initializable, ServiceManager, Configurable {
     
     /**
      * An empty configuration object, that can be used when no configuration is known but one
@@ -54,6 +63,31 @@
      */
     public static final Configuration EMPTY_CONFIGURATION = new DefaultConfiguration("-", "unknown location");
     
+    /** The application context for components */
+    protected Context context;
+
+    /** Static component mapping handlers. */
+    protected final Map componentMapping = Collections.synchronizedMap(new HashMap());
+
+    /** Used to map roles to ComponentHandlers. */
+    protected final Map componentHandlers = Collections.synchronizedMap(new HashMap());
+
+    /** Is the Manager disposed or not? */
+    protected boolean disposed;
+
+    /** Is the Manager initialized? */
+    protected boolean initialized;
+
+    /** RoleInfos. */
+    protected RoleManager roleManager;
+
+    /** LoggerManager. */
+    protected LoggerManager loggerManager;
+    
+    private ComponentEnvironment componentEnv;
+    
+    private boolean lazyMode = Boolean.getBoolean("org.apache.cocoon.core.LazyMode");
+    
     /** The location where this manager is defined */
     protected String location;
     
@@ -89,6 +123,9 @@
     public void enableLogging(Logger logger) {
         super.enableLogging(logger);
         this.roleManager.enableLogging(logger);
+        String msg = "Lazy mode: " + this.lazyMode;
+        logger.debug(msg);
+        System.out.println(msg);
     }
 
     /* (non-Javadoc)
@@ -98,6 +135,13 @@
         this.context = context;
     }
     
+    /**
+     * Configure the LoggerManager.
+     */
+    public void setLoggerManager( final LoggerManager manager ) {
+        this.loggerManager = manager;
+    }
+    
     public void setRoleManager (RoleManager rm) {
         if (rm != null) {
             // Override the one eventually got in the parent (see constructor)
@@ -109,6 +153,9 @@
      * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
      */
     public void configure(Configuration configuration) throws ConfigurationException {
+        
+        this.componentEnv = new ComponentEnvironment(null, getLogger(), this.roleManager, this.loggerManager, this.context, this);
+        
         // Setup location
         this.location = configuration.getLocation();
         
@@ -137,7 +184,7 @@
      */
     public void initialize()
     throws Exception {
-        super.initialize();
+        this.initialized = true;
 
         // Initialize component handlers. This is done in no particular order, but initializing a
         // handler may indirectly initialize another handler through a call to lookup().
@@ -207,7 +254,7 @@
                 forceDisposal = true;
             }
         }
-        super.dispose();
+        this.disposed = true;
     }
 
     //=============================================================================================
@@ -284,15 +331,11 @@
                     }
 
                     try {
-                        // FIXME use different class loader
-                        final Class componentClass = this.getClass().getClassLoader().loadClass( info.getServiceClassName() );
                         final Configuration configuration = new DefaultConfiguration( "", "-" );
-                        info.setServiceClass(componentClass);
-                        info.setConfiguration(configuration);
 
                         handler = this.getComponentHandler(role,
-                                                       info,
-                                                       this);
+                                                       info.getServiceClassName(),
+                                                       configuration);
 
                         handler.initialize();
                     } catch (ServiceException se) {
@@ -399,56 +442,58 @@
      * Add a new component to the manager.
      *
      * @param role the role name for the new component.
-     * @param component the class of this component.
+     * @param className the class of this component.
      * @param configuration the configuration for this component.
      */
-    public void addComponent( final String role,
-                              final Class component,
-                              final Configuration configuration )
-    throws ServiceException {
+    public void addComponent( String role,
+                              String className,
+                              Configuration configuration )
+    throws ConfigurationException {
         if( this.initialized ) {
-            throw new ServiceException( role,
-                "Cannot add components to an initialized CoreServiceManager." );
+            throw new IllegalStateException("Cannot add components to an initialized CoreServiceManager." );
+        }
+
+        // check for old excalibur class names - we only test against the selector
+        // implementation
+        if ( "org.apache.cocoon.components.ExtendedComponentSelector".equals(className)) {
+            className = DefaultServiceSelector.class.getName();
+        }
+        
+        if( this.getLogger().isDebugEnabled() ) {
+            this.getLogger().debug( "Adding component (" + role + " = " + className + ")" );
         }
 
         ComponentHandler handler = (ComponentHandler)this.componentHandlers.get(role);
         if (handler != null) {
-            // Overloaded component: we only allow selectors to be overloaded
-            ServiceInfo info = handler.getInfo();
-            // FIXME - info should not contain the class, we need to get it from somewhere else
-            if (!DefaultServiceSelector.class.isAssignableFrom(component) ||
-                !DefaultServiceSelector.class.isAssignableFrom(info.getServiceClass())) {
-                throw new ServiceException(role, "Component declared at " + info.getLocation() + " is redefined at " +
-                        configuration.getLocation());
-            }
+            // Check that override is allowed. If yes, the handler will be redefined below, allowing
+            // the new definition to feed this manager with its components.
+            checkComponentOverride(role, className, configuration, handler);
         }
+        
         try {
-            final ServiceInfo info = new ServiceInfo();
-            info.setConfiguration(configuration);
-            info.setServiceClass(component);
-            handler = this.getComponentHandler(role, info, this);
+            handler = this.getComponentHandler(role, className, configuration);
 
             if( this.getLogger().isDebugEnabled() ) {
                 this.getLogger().debug( "Handler type = " + handler.getClass().getName() );
             }
 
             this.componentHandlers.put( role, handler );
-        } catch ( final ServiceException se ) {
-            throw se;
+        } catch ( final ConfigurationException ce ) {
+            throw ce;
         } catch( final Exception e ) {
-            throw new ServiceException( role, "Could not set up component handler.", e );
+            throw new ConfigurationException( "Could not add component defined at " + configuration.getLocation(), e );
         }
         
-        // Initialize shadow selector now, it will feed this service manager
-        if ( DefaultServiceSelector.class.isAssignableFrom( component )) {
-            try {
-                handler.initialize();
-            } catch(ServiceException se) {
-                throw se;
-            } catch(Exception e) {
-                throw new ServiceException(role, "Could not initialize selector", e);
-            }
-        }
+//        // Initialize shadow selector now, it will feed this service manager
+//        if ( DefaultServiceSelector.class.isAssignableFrom( component )) {
+//            try {
+//                handler.initialize();
+//            } catch(ServiceException se) {
+//                throw se;
+//            } catch(Exception e) {
+//                throw new ServiceException(role, "Could not initialize selector", e);
+//            }
+//        }
     }
     
     /**
@@ -517,6 +562,30 @@
     // Private methods
     //=============================================================================================
     
+    /**
+     * Obtain a new ComponentHandler for the specified component. 
+     * 
+     * @param role the component's role.
+     * @param componentClass Class of the component for which the handle is
+     *                       being requested.
+     * @param configuration The configuration for this component.
+     * @param serviceManager The service manager which will be managing the Component.
+     *
+     * @throws Exception If there were any problems obtaining a ComponentHandler
+     */
+    private ComponentHandler getComponentHandler( final String role,
+                                                    final String className,
+                                                    final Configuration configuration)
+    throws Exception {
+        
+        if (!lazyMode || configuration.getAttributeAsBoolean("preload", false) || role.endsWith("Selector")) {
+            return AbstractComponentHandler.getComponentHandler(
+                    role, className, configuration, this.componentEnv);
+        } else {
+            return new LazyHandler(role, className, configuration, this.componentEnv);
+        }
+    }
+
     private void parseConfiguration(final Configuration configuration, String contextURI, Set loadedURIs) 
         throws ConfigurationException {
 
@@ -562,8 +631,8 @@
                 if (name != null) {
                     role = role + "/" + name;
                 }
-    
-                this.addComponent(className, role, componentConfig);
+
+                this.addComponent(role, className, componentConfig);
             }
         }
     }
@@ -690,5 +759,34 @@
             this.parentManager.release(this.cachedSourceResolver);
         }
         this.cachedSourceResolver = null;
+    }
+    
+    /** 
+     * Check if a component can be overriden. Only {@link DefaultSelector} or its subclasses can be
+     * overriden, as they directly feed this manager with their component definitions and are empty
+     * shells delegating to this manager afterwards.
+     */
+    private void checkComponentOverride(String role, String className, Configuration config,
+            ComponentHandler existingHandler) throws ConfigurationException {
+        
+        // We only allow selectors to be overloaded
+        ServiceInfo info = existingHandler.getInfo();
+        if (!className.equals(info.getServiceClassName())) {
+            throw new ConfigurationException("Role " + role + " redefined with a different class name, at " +
+                    config.getLocation());
+        }
+        
+        Class clazz;
+        try {
+            clazz = this.componentEnv.loadClass(className);
+        } catch(ClassNotFoundException cnfe) {
+            throw new ConfigurationException("Cannot load class " + className + " for component at " +
+                    config.getLocation(), cnfe);
+        }
+
+        if (!DefaultServiceSelector.class.isAssignableFrom(clazz)) {
+            throw new ConfigurationException("Component declared at " + info.getLocation() + " is redefined at " +
+                    config.getLocation());
+        }
     }
 }

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/DefaultServiceSelector.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/DefaultServiceSelector.java?view=diff&rev=124234&p1=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/DefaultServiceSelector.java&r1=124233&p2=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/DefaultServiceSelector.java&r2=124234
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/DefaultServiceSelector.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/DefaultServiceSelector.java	Wed Jan  5 09:42:34 2005
@@ -118,7 +118,7 @@
             }
             
             // Add this component in the manager
-            this.manager.addComponent(className, this.rolePrefix + key, instance);
+            this.manager.addComponent(this.rolePrefix + key, className, instance);
         }
         
         // Register default key, if any
@@ -191,13 +191,11 @@
      */
     public static class Factory extends ComponentFactory {
         private final String role;
-        private final RoleManager roleManager;
         
-        public Factory(ComponentEnvironment env, RoleManager manager, ServiceInfo info, String role) 
+        public Factory(ComponentEnvironment env, ServiceInfo info, String role) 
         throws Exception {
             super(env, info);
             this.role = role;
-            this.roleManager = manager;
         }
         
         protected void setupInstance(Object object)
@@ -208,7 +206,7 @@
             ContainerUtil.contextualize(component, this.environment.context);
             ContainerUtil.service(component, this.environment.serviceManager);
             
-            component.setRoleManager(this.roleManager);
+            component.setRoleManager(this.environment.roleManager);
             component.setRole(this.role);
             
             ContainerUtil.configure(component, this.serviceInfo.getConfiguration());

Added: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/LazyHandler.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/LazyHandler.java?view=auto&rev=124234
==============================================================================
--- (empty file)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/LazyHandler.java	Wed Jan  5 09:42:34 2005
@@ -0,0 +1,116 @@
+/*
+ * Created on Jan 3, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.cocoon.core.container;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.cocoon.components.ServiceInfo;
+
+/**
+ * @author sylvain
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class LazyHandler implements ComponentHandler {
+    
+    private String role;
+    private String className;
+    private Configuration config;
+    private ComponentEnvironment compEnv;
+    
+    private ComponentHandler delegate;
+    
+    public LazyHandler(String role, String className, Configuration configuration, ComponentEnvironment environment) {
+        this.role = role;
+        this.className = className;
+        this.config = configuration;
+        this.compEnv = environment;
+    }
+    
+    private ComponentHandler getDelegate() throws Exception {
+        if (this.delegate == null) {
+//            System.err.println("######## " + System.identityHashCode(compEnv.serviceManager) + " creating handler for " + this.role);
+            this.delegate = AbstractComponentHandler.getComponentHandler(role, className, config, compEnv);
+            this.delegate.initialize();
+        }
+        
+        return this.delegate;
+    }
+    
+    private ComponentHandler getDelegateRE() {
+        try {
+            return getDelegate();
+        } catch (Exception e) {
+            throw new CascadingRuntimeException("Cannot get delegate handler", e);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.core.container.ComponentHandler#get()
+     */
+    public Object get() throws Exception {
+        return getDelegate().get();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.core.container.ComponentHandler#put(java.lang.Object)
+     */
+    public void put(Object component) throws Exception {
+        getDelegate().put(component);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.core.container.ComponentHandler#isSingleton()
+     */
+    public boolean isSingleton() {
+        return getDelegateRE().isSingleton();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.core.container.ComponentHandler#canBeDisposed()
+     */
+    public boolean canBeDisposed() {
+        // We can always be disposed if handler was never used
+        if (this.delegate == null) {
+            return true;
+        } else {
+            return getDelegateRE().canBeDisposed();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.core.container.ComponentHandler#dispose()
+     */
+    public void dispose() {
+        // Dispose only if handler was actually used
+        if (this.delegate != null) {
+            this.delegate.dispose();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.core.container.ComponentHandler#initialize()
+     */
+    public void initialize() throws Exception {
+        // nothing (delegate is initialized when created)
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.core.container.ComponentHandler#getInfo()
+     */
+    public ServiceInfo getInfo() {
+        if (this.delegate == null) {
+            final ServiceInfo info = new ServiceInfo();
+            info.setServiceClassName(className);
+            info.setConfiguration(config);
+            return info;
+        } else {
+            return this.delegate.getInfo();
+        }
+    }
+}

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java?view=diff&rev=124234&p1=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java&r1=124233&p2=cocoon/trunk/src/core/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java&r2=124234
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java	Wed Jan  5 09:42:34 2005
@@ -343,11 +343,9 @@
         }
 
         try {
-            final ServiceInfo info = new ServiceInfo();
-            info.setConfiguration(configuration);
-            info.setServiceClass(component);
             final ComponentHandler handler = getComponentHandler( null,
-                                                                  info,
+                                                                  component,
+                                                                  configuration,
                                                                   this.serviceManager);
 
             handler.initialize();
@@ -460,13 +458,11 @@
      */
     public static class Factory extends ComponentFactory {
         
-        private final RoleManager roleManager;
         private final String role;
         
-        public Factory(ComponentEnvironment env, RoleManager roleManager, ServiceInfo info, String role) 
+        public Factory(ComponentEnvironment env, ServiceInfo info, String role) 
         throws Exception {
             super(env, info);
-            this.roleManager = roleManager;
             this.role = role;
         }
         
@@ -479,7 +475,7 @@
             ContainerUtil.service(component, this.environment.serviceManager);
             
             component.setLoggerManager(this.environment.loggerManager);
-            component.setRoleManager(this.roleManager);
+            component.setRoleManager(this.environment.roleManager);
 
             ServiceManager manager = this.environment.serviceManager;
             if (manager instanceof CoreServiceManager) {

Modified: cocoon/trunk/src/core/test/org/apache/cocoon/core/container/ContainerTestCase.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/test/org/apache/cocoon/core/container/ContainerTestCase.java?view=diff&rev=124234&p1=cocoon/trunk/src/core/test/org/apache/cocoon/core/container/ContainerTestCase.java&r1=124233&p2=cocoon/trunk/src/core/test/org/apache/cocoon/core/container/ContainerTestCase.java&r2=124234
==============================================================================
--- cocoon/trunk/src/core/test/org/apache/cocoon/core/container/ContainerTestCase.java	(original)
+++ cocoon/trunk/src/core/test/org/apache/cocoon/core/container/ContainerTestCase.java	Wed Jan  5 09:42:34 2005
@@ -24,6 +24,7 @@
 import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
 import org.apache.avalon.framework.container.ContainerUtil;
@@ -259,7 +260,7 @@
      * components.
      */
     protected void addComponents( CoreServiceManager manager) 
-    throws ServiceException {
+    throws ServiceException, ConfigurationException {
         // subclasses can add components here
     }
     

Modified: cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java?view=diff&rev=124234&p1=cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java&r1=124233&p2=cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java&r2=124234
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java	Wed Jan  5 09:42:34 2005
@@ -184,6 +184,8 @@
      * @exception Exception if an error occurs
      */
     public void initialize() throws Exception {
+//long start = System.currentTimeMillis();
+
         this.serviceManager = new CocoonServiceManager(this.parentServiceManager);
         ContainerUtil.enableLogging(this.serviceManager, getLogger().getChildLogger("manager"));
         ContainerUtil.contextualize(this.serviceManager, this.context);
@@ -227,6 +229,8 @@
         if (this.serviceManager.hasService(RequestListener.ROLE)){
             this.requestListener = (RequestListener) this.serviceManager.lookup(RequestListener.ROLE);
         }
+//long delay = System.currentTimeMillis() - start;
+//System.err.println("########## Cocoon.initialize() : " + delay);
     }
 
     /** Dump System Properties */
@@ -470,6 +474,8 @@
      */
     public boolean process(Environment environment)
     throws Exception {
+//long start = System.currentTimeMillis();
+
         if (this.disposed) {
             throw new IllegalStateException("You cannot process a Disposed Cocoon engine.");
         }
@@ -519,6 +525,9 @@
             }
             // commit response on success
             environment.commitResponse();
+
+//long delay = System.currentTimeMillis() - start;
+//System.err.println("########## Cocoon.process() : " + delay);
 
             return result;
         } catch (Exception any) {

Modified: cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles?view=diff&rev=124234&p1=cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles&r1=124233&p2=cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles&r2=124234
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles	Wed Jan  5 09:42:34 2005
@@ -204,7 +204,7 @@
         default-class="org.apache.cocoon.i18n.XMLResourceBundleFactory"/>
 
   <!-- Control flow layer: the interpreters selector and continuations  manager -->
-  <role name="org.apache.cocoon.components.flow.Interpreter" 
+  <role name="org.apache.cocoon.components.flow.InterpreterSelector" 
         shorthand="flow-interpreters"
         default-class="org.apache.cocoon.core.container.DefaultServiceSelector"/>
 

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java?view=diff&rev=124234&p1=cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java&r1=124233&p2=cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java&r2=124234
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java	Wed Jan  5 09:42:34 2005
@@ -54,7 +54,7 @@
         this.info = new ProcessorComponentInfo(parentInfo);
     }
     
-    public void addComponent(String role, Class clazz, Configuration config) throws ServiceException {
+    public void addComponent(String role, String clazz, Configuration config) throws ConfigurationException {
         super.addComponent(role, clazz, config);
         // Let's ProcessorComponentInfo do its stuff.
         // Note: if more behaviours of this kind are needed, we may setup an

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java?view=diff&rev=124234&p1=cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java&r1=124233&p2=cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java&r2=124234
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java	Wed Jan  5 09:42:34 2005
@@ -95,7 +95,7 @@
      * @param clazz the component's class
      * @param config the component's configuration
      */
-    public void componentAdded(String role, Class clazz, Configuration config) {
+    public void componentAdded(String role, String clazz, Configuration config) {
         if (role.startsWith(GENERATOR_PREFIX)) {
             setupLabelAndPipelineHint(role, config);
 

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java?view=diff&rev=124234&p1=cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java&r1=124233&p2=cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java&r2=124234
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java	Wed Jan  5 09:42:34 2005
@@ -57,7 +57,7 @@
         this.manager = manager;
 
         try {
-            this.interpreterSelector = (ServiceSelector) manager.lookup(Interpreter.ROLE);
+            this.interpreterSelector = (ServiceSelector) manager.lookup(Interpreter.ROLE + "Selector");
             // Obtain the Interpreter instance for this language
             this.interpreter = (Interpreter) this.interpreterSelector.select(language);
             // Set interpreter ID as location of the flow node (which includes full sitemap file path)

Modified: cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java?view=diff&rev=124234&p1=cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java&r1=124233&p2=cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java&r2=124234
==============================================================================
--- cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java	(original)
+++ cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java	Wed Jan  5 09:42:34 2005
@@ -16,6 +16,7 @@
 
 package org.apache.cocoon;
 
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.cocoon.core.container.CoreServiceManager;
@@ -37,7 +38,7 @@
      * @see org.apache.cocoon.core.container.ContainerTestCase#addComponents(org.apache.cocoon.core.container.CocoonServiceManager)
      */
     protected void addComponents(CoreServiceManager manager) 
-    throws ServiceException {
+    throws ServiceException, ConfigurationException {
         super.addComponents(manager);
         if ( this.addSourceFactories() ) {
             // Create configuration for source-factories
@@ -51,12 +52,12 @@
             factory.setAttribute("name", "*");
             df.addChild(factory);
             manager.addComponent("org.apache.excalibur.source.SourceFactorySelector", 
-                                 CocoonServiceSelector.class, 
+                                 CocoonServiceSelector.class.getName(), 
                                  df);
         }
         if ( this.addSourceResolver() ) {
             manager.addComponent(SourceResolver.ROLE, 
-                    SourceResolverImpl.class, 
+                    SourceResolverImpl.class.getName(), 
                     new DefaultConfiguration("", "-"));
         }
     }

Modified: cocoon/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java?view=diff&rev=124234&p1=cocoon/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java&r1=124233&p2=cocoon/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java&r2=124234
==============================================================================
--- cocoon/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java	(original)
+++ cocoon/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java	Wed Jan  5 09:42:34 2005
@@ -28,6 +28,7 @@
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.context.DefaultContext;
 import org.apache.avalon.framework.parameters.Parameters;
@@ -130,7 +131,7 @@
      * @see org.apache.cocoon.core.container.ContainerTestCase#addComponents(org.apache.cocoon.core.container.CocoonServiceManager)
      */
     protected void addComponents(CoreServiceManager manager) 
-    throws ServiceException {
+    throws ServiceException, ConfigurationException {
         super.addComponents(manager);
         final String[] o = this.getSitemapComponentInfo();
         if ( o != null ) {
@@ -145,7 +146,7 @@
             factory.setAttribute("name", key);
             df.addChild(factory);
             manager.addComponent(typeClassName + "Selector", 
-                                 CocoonServiceSelector.class, 
+                                 CocoonServiceSelector.class.getName(), 
                                  df);
         }
     }
@@ -505,7 +506,7 @@
         SourceResolver resolver = null;
 
         try {
-            selector = (ServiceSelector) this.lookup(Interpreter.ROLE);
+            selector = (ServiceSelector) this.lookup(Interpreter.ROLE + "Selector");
             assertNotNull("Test lookup of interpreter selector", selector);
 
             resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
@@ -548,7 +549,7 @@
         SourceResolver resolver = null;
 
         try {
-            selector = (ServiceSelector) this.lookup(Interpreter.ROLE);
+            selector = (ServiceSelector) this.lookup(Interpreter.ROLE + "Selector");
             assertNotNull("Test lookup of interpreter selector", selector);
 
             resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);

Modified: cocoon/trunk/status.xml
Url: http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?view=diff&rev=124234&p1=cocoon/trunk/status.xml&r1=124233&p2=cocoon/trunk/status.xml&r2=124234
==============================================================================
--- cocoon/trunk/status.xml	(original)
+++ cocoon/trunk/status.xml	Wed Jan  5 09:42:34 2005
@@ -203,6 +203,11 @@
   <changes>
  <release version="@version@" date="@date@">
    <action dev="SW" type="add">
+     Add an experimental lazy loading in the service manager that dramatically speeds up Cocoon init time
+     (approx 4 times faster). To use it, set JAVA_OPTIONS="-Dorg.apache.cocoon.core.LazyMode=true" prior
+     to starting "cocoon.sh servlet".
+   </action>
+   <action dev="SW" type="add">
      Add an include feature to xconf files and xmap files, to allow an easier configuration of the system.
      The main cocoon.xconf is now a list of inclusion of the main core components and a
      separate xconf file for each block. Additional role files can also be included.

Mime
View raw message