cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r325932 - in /cocoon: blocks/hsqldb/trunk/WEB-INF/xconf/ blocks/ojb/trunk/WEB-INF/xconf/ blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/ blocks/portal-sample/trunk/samples/conf/ trunk/src/java/org/apache/cocoon/components/store/impl...
Date Mon, 17 Oct 2005 17:01:11 GMT
Author: sylvain
Date: Mon Oct 17 10:00:55 2005
New Revision: 325932

URL: http://svn.apache.org/viewcvs?rev=325932&view=rev
Log:
In lazy mode, load at startup components that implement the Startable interface

Modified:
    cocoon/blocks/hsqldb/trunk/WEB-INF/xconf/cocoon-hsqldb.xconf
    cocoon/blocks/ojb/trunk/WEB-INF/xconf/cocoon-ojb.xconf
    cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/ConnectionFactoryImpl.java
    cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/LoggerImpl.java
    cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf
    cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-tools.xconf
    cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java
    cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
    cocoon/trunk/src/java/org/apache/cocoon/core/container/CoreServiceManager.java

Modified: cocoon/blocks/hsqldb/trunk/WEB-INF/xconf/cocoon-hsqldb.xconf
URL: http://svn.apache.org/viewcvs/cocoon/blocks/hsqldb/trunk/WEB-INF/xconf/cocoon-hsqldb.xconf?rev=325932&r1=325931&r2=325932&view=diff
==============================================================================
--- cocoon/blocks/hsqldb/trunk/WEB-INF/xconf/cocoon-hsqldb.xconf (original)
+++ cocoon/blocks/hsqldb/trunk/WEB-INF/xconf/cocoon-hsqldb.xconf Mon Oct 17 10:00:55 2005
@@ -33,8 +33,7 @@
       |  path   : string      path to the database - context-protocol is resolved
       +-->
   <hsqldb-server class="org.apache.cocoon.components.hsqldb.ServerImpl"
-                 logger="core.hsqldb-server"
-                 preload="true">
+                 logger="core.hsqldb-server">
      <parameter name="port" value="9002"/>
      <parameter name="silent" value="true"/>
      <parameter name="trace" value="false"/>

Modified: cocoon/blocks/ojb/trunk/WEB-INF/xconf/cocoon-ojb.xconf
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ojb/trunk/WEB-INF/xconf/cocoon-ojb.xconf?rev=325932&r1=325931&r2=325932&view=diff
==============================================================================
--- cocoon/blocks/ojb/trunk/WEB-INF/xconf/cocoon-ojb.xconf (original)
+++ cocoon/blocks/ojb/trunk/WEB-INF/xconf/cocoon-ojb.xconf Mon Oct 17 10:00:55 2005
@@ -26,12 +26,12 @@
   <!-- OJB Logger -->
   <component role="org.apache.cocoon.ojb.components.Logger"
              class="org.apache.cocoon.ojb.components.LoggerImpl"
-             logger="ojb" preload="true"/>
+             logger="ojb"/>
 
   <!-- OJB Connection Factory -->
   <component role="org.apache.cocoon.ojb.components.ConnectionFactory"
              class="org.apache.cocoon.ojb.components.ConnectionFactoryImpl"
-             logger="core.ojb" preload="true"/>
+             logger="core.ojb"/>
 
   <!-- OJB Persistent Manager Factory for JDO.
        Requires javax.jdo package.

Modified: cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/ConnectionFactoryImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/ConnectionFactoryImpl.java?rev=325932&r1=325931&r2=325932&view=diff
==============================================================================
--- cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/ConnectionFactoryImpl.java
(original)
+++ cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/ConnectionFactoryImpl.java
Mon Oct 17 10:00:55 2005
@@ -18,6 +18,7 @@
 import org.apache.avalon.excalibur.datasource.DataSourceComponent;
 import org.apache.avalon.framework.CascadingRuntimeException;
 import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Startable;
 import org.apache.avalon.framework.component.Component;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
@@ -35,13 +36,17 @@
 /**
  * OJB ConnectionFactory implemenation to bridge into the Avalon DataSource
  * connection pooling component defined in the Cocoon configuration.
+ * <p>
+ * This class <b>must</b> be loaded a server's startup time, as its initialization
+ * sets up some static attributes that are later used by another instance of this
+ * same class created by OJB from the <code>OJB.properties</code> file. Yeah,
weird...
  *
  * @author giacomo at apache.org
  * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
  * @version $Id$
  */
 public class ConnectionFactoryImpl implements Component, ThreadSafe, Serviceable, Disposable,
-                                              ConnectionFactory {
+                                              ConnectionFactory, Startable {
 
     /** The <code>ServiceManager</code> to be used */
     private static ServiceManager manager;
@@ -132,5 +137,21 @@
 
     public void releaseAllResources() {
         // Nothing to do here
+    }
+
+    /**
+     * Implementation of <code>Startable</code> so that the component is preloaded
even in lazy-loading mode,
+     * which is needed for it to subscribe to portal events.
+     */
+    public void start() throws Exception {
+        // nothing
+    }
+
+    /**
+     * Implementation of <code>Startable</code> so that the component is preloaded
even in lazy-loading mode,
+     * which is needed for it to subscribe to portal events.
+     */
+    public void stop() throws Exception {
+        // nothing
     }
 }

Modified: cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/LoggerImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/LoggerImpl.java?rev=325932&r1=325931&r2=325932&view=diff
==============================================================================
--- cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/LoggerImpl.java (original)
+++ cocoon/blocks/ojb/trunk/java/org/apache/cocoon/ojb/components/LoggerImpl.java Mon Oct
17 10:00:55 2005
@@ -16,6 +16,7 @@
 package org.apache.cocoon.ojb.components;
 
 import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.activity.Startable;
 import org.apache.avalon.framework.component.Component;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.logger.NullLogger;
@@ -28,13 +29,17 @@
 
 /**
  * OJB logger implementation delegating to the Avalon logger
+ * <p>
+ * This class <b>must</b> be loaded a server's startup time, as its initialization
+ * sets up some static attributes that are later used by another instance of this
+ * same class created by OJB from the <code>OJB.properties</code> file. Yeah,
weird...
  *
  * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
  * @version $Id$
  */
 public class LoggerImpl extends AbstractLogEnabled
                         implements Component, ThreadSafe, Initializable,
-                                   Logger {
+                                   Logger, Startable {
 
     /**
      * Root logger for all OJB loggers
@@ -234,5 +239,21 @@
         }
 
         return "null";
+    }
+
+    /**
+     * Implementation of <code>Startable</code> so that the component is preloaded
even in lazy-loading mode,
+     * which is needed for it to subscribe to portal events.
+     */
+    public void start() throws Exception {
+        // nothing
+    }
+
+    /**
+     * Implementation of <code>Startable</code> so that the component is preloaded
even in lazy-loading mode,
+     * which is needed for it to subscribe to portal events.
+     */
+    public void stop() throws Exception {
+        // nothing
     }
 }

Modified: cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf?rev=325932&r1=325931&r2=325932&view=diff
==============================================================================
--- cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf (original)
+++ cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-sample.xconf Mon Oct 17 10:00:55
2005
@@ -62,7 +62,7 @@
   </portal-service>
 
   <!--  This is the profile manager using pipelines to load the various parts. -->
-  <portal-profile-manager preload="true" class="org.apache.cocoon.portal.profile.impl.GroupBasedProfileManager">
+  <portal-profile-manager class="org.apache.cocoon.portal.profile.impl.GroupBasedProfileManager">
     <parameter name="copletbasedata-global-load" value="cocoon:raw:/load-global-profile?profile=copletbasedata"/>
     <parameter name="copletdata-global-load" value="cocoon:raw:/load-global-profile?profile=copletdata"/>
     <parameter name="copletdata-role-load" value="cocoon:raw:/load-role-profile?profile=copletdata"/>

Modified: cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-tools.xconf
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-tools.xconf?rev=325932&r1=325931&r2=325932&view=diff
==============================================================================
--- cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-tools.xconf (original)
+++ cocoon/blocks/portal-sample/trunk/samples/conf/cocoon-portal-tools.xconf Mon Oct 17 10:00:55
2005
@@ -21,10 +21,10 @@
 <components>
 
   <component class="org.apache.cocoon.portal.tools.PortalToolManager" 
-             role="org.apache.cocoon.portal.tools.PortalToolManager" preload="true">
+             role="org.apache.cocoon.portal.tools.PortalToolManager">
 	<parameter name="root" value="tools/"/>
 	<parameter name="conf" value="conf.xml"/>
 	<parameter name="auth" value="auth.xml"/>
   </component>
 
-</components>
\ No newline at end of file
+</components>

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java?rev=325932&r1=325931&r2=325932&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java Mon
Oct 17 10:00:55 2005
@@ -19,7 +19,8 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 
-import org.apache.avalon.framework.activity.Startable;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.parameters.ParameterException;
 import org.apache.avalon.framework.parameters.Parameterizable;
@@ -53,11 +54,15 @@
  * @x-avalon.lifestyle type=singleton
  *
  * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
- * @version CVS $Id: StoreJanitorImpl.java,v 1.4 2004/02/28 11:47:31 cziegeler Exp $
+ * @version CVS $Id$
  */
 public class StoreJanitorImpl extends AbstractLogEnabled
                               implements StoreJanitor, Parameterizable, ThreadSafe,
-                                         Runnable, Startable {
+                                         Initializable, Disposable, 
+                                         Runnable {
+
+    // Note: this class doesn't need to be Startable. This allows the janitor thread to be
+    // lazily created the first time a store registers itsefl
 
     // Configuration parameters
     private int minFreeMemory = -1;
@@ -136,7 +141,11 @@
         }
     }
 
-    public void start() throws Exception {
+    public void initialize() throws Exception {
+        doStart();
+    }
+
+    private void doStart() throws Exception {
         this.doRun = true;
         Thread checker = new Thread(this);
         if (getLogger().isDebugEnabled()) {
@@ -148,8 +157,12 @@
         checker.start();
     }
 
-    public void stop() {
+    private void doStop() {
         this.doRun = false;
+    }
+
+    public void dispose() {
+        doStop();
     }
 
     /**

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java?rev=325932&r1=325931&r2=325932&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Mon Oct 17 10:00:55 2005
@@ -15,8 +15,14 @@
  */
 package org.apache.cocoon.components.thread;
 
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
 import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Startable;
+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;
@@ -24,12 +30,6 @@
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.thread.ThreadSafe;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
 /**
  * The DefaultRunnableManager implements the {@link RunnableManager} interface
  * and is responsible to create {@link ThreadPool}s and run {@link Runnable}s
@@ -72,8 +72,11 @@
                Configurable,
                Disposable,
                Runnable,
-               Startable,
+               Initializable,
                ThreadSafe {
+    
+    // Note: this class doesn't need to be Startable. This allows the thread pool to be
+    // lazily created the first time a Runnable is executed.
 
     //~ Static fields/initializers ---------------------------------------------
 
@@ -248,6 +251,8 @@
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
     public void dispose() {
+        doStop();
+
         if( getLogger().isDebugEnabled() ) {
             getLogger().debug( "Disposing all thread pools" );
         }
@@ -450,13 +455,22 @@
             getLogger().debug( "Exiting loop" );
         }
     }
+    
+    /**
+     * Start the managing thread
+     * 
+     * @throws Exception
+     */
+    public void initialize() throws Exception {
+        doStart();
+    }
 
     /**
      * Start the managing thread
      *
      * @throws Exception DOCUMENT ME!
      */
-    public void start() throws Exception {
+    private void doStart() throws Exception {
         if( getLogger().isDebugEnabled() ) {
             getLogger().debug( "Starting the heart" );
         }
@@ -467,10 +481,8 @@
 
     /**
      * Stop the managing thread
-     *
-     * @throws Exception DOCUMENT ME!
      */
-    public void stop( ) throws Exception {
+    private void doStop( ) {
         keepRunning = false;
 
         synchronized( commandStack ) {

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/container/CoreServiceManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/container/CoreServiceManager.java?rev=325932&r1=325931&r2=325932&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/container/CoreServiceManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/container/CoreServiceManager.java Mon Oct
17 10:00:55 2005
@@ -29,6 +29,7 @@
 import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.activity.Startable;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -181,7 +182,6 @@
      * @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(this.classloader, getLogger(), this.roleManager,
this.loggerManager, this.context, this);
 
         // Setup location
@@ -591,7 +591,7 @@
     //=============================================================================================
     // Private methods
     //=============================================================================================
-
+    
     /**
      * Obtain a new ComponentHandler for the specified component. 
      * 
@@ -608,6 +608,31 @@
                                                   final Configuration configuration,
                                                   final ComponentInfo baseInfo)
     throws Exception {
+
+        boolean lazyLoad = this.settings.isLazyMode();
+        if (lazyLoad) {
+            // handle restrictions to lazy loading
+            if (role.endsWith("Selector") || configuration.getAttributeAsBoolean("preload",
false)) {
+                lazyLoad = false;
+            } else {
+                // Check if the class implements Startable
+                Class componentClass;
+                try {
+                    componentClass = componentEnv.loadClass(className);
+                } catch (ClassNotFoundException cnfe) {
+                    throw new Exception("Cannot find class " + className + " for component
at " +
+                            configuration.getLocation(), cnfe);
+                }
+                if (Startable.class.isAssignableFrom(componentClass)) {
+                    lazyLoad = false;
+                }
+            }
+        }
+
+        if (lazyLoad) {
+            return new LazyHandler(role, className, configuration, componentEnv);
+        }
+        
         // FIXME - we should ensure that we always get an info
         ComponentInfo info;
         if ( baseInfo != null ) {
@@ -619,11 +644,7 @@
         info.setConfiguration(configuration);
         info.setServiceClassName(className);
 
-        if (!this.settings.isLazyMode() || configuration.getAttributeAsBoolean("preload",
false) || role.endsWith("Selector")) {
-            return AbstractComponentHandler.getComponentHandler(
-                    role, this.componentEnv, info);
-        }
-        return new LazyHandler(role, className, configuration, this.componentEnv);
+        return AbstractComponentHandler.getComponentHandler(role, this.componentEnv, info);
     }
 
     private void parseConfiguration(final Configuration configuration, String contextURI,
Set loadedURIs) 



Mime
View raw message