cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components EnvironmentStack.java CocoonComponentManager.java
Date Mon, 02 Dec 2002 08:39:18 GMT
cziegeler    2002/12/02 00:39:17

  Modified:    src/java/org/apache/cocoon/environment/wrapper
                        EnvironmentWrapper.java
               src/java/org/apache/cocoon/environment
                        ObjectModelHelper.java
               src/java/org/apache/cocoon/components/source/impl
                        SitemapSource.java
               src/java/org/apache/cocoon/components EnvironmentStack.java
                        CocoonComponentManager.java
  Log:
  Finally fixing environment stack handling for multi-threading
  Fixing recycling of sources
  Fixing minor bug in EnvironmentWrapper constructor
  Adding possibility to pass objects from the outer pipeline to an internal one
  
  Revision  Changes    Path
  1.22      +12 -8     xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
  
  Index: EnvironmentWrapper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- EnvironmentWrapper.java	24 Sep 2002 08:46:35 -0000	1.21
  +++ EnvironmentWrapper.java	2 Dec 2002 08:39:17 -0000	1.22
  @@ -131,7 +131,7 @@
                                 Logger      logger,
                                 boolean     rawMode)
       throws MalformedURLException {
  -        this(env, requestURI, queryString, logger, null, false);
  +        this(env, requestURI, queryString, logger, null, rawMode);
       }
   
       /**
  @@ -155,13 +155,17 @@
           this.prefix = new StringBuffer(env.getURIPrefix());
   
           // create new object model and replace the request object
  -        this.objectModel = new HashMap(4);
           Map oldObjectModel = env.getObjectModel();
  -        Iterator keys = oldObjectModel.keySet().iterator();
  -        String key;
  -        while (keys.hasNext()) {
  -            key = (String)keys.next();
  -            this.objectModel.put(key, oldObjectModel.get(key));
  +        if (oldObjectModel instanceof HashMap) {
  +            this.objectModel = (Map)((HashMap)oldObjectModel).clone();
  +        } else {
  +            this.objectModel = new HashMap(oldObjectModel.size()*2);
  +            Iterator entries = oldObjectModel.entrySet().iterator();
  +            Map.Entry entry;
  +            while (entries.hasNext()) {
  +                entry = (Map.Entry)entries.next();
  +                this.objectModel.put(entry.getKey(), entry.getValue());
  +            }
           }
           this.request = new RequestWrapper(ObjectModelHelper.getRequest(oldObjectModel),
                                             requestURI,
  
  
  
  1.7       +5 -1      xml-cocoon2/src/java/org/apache/cocoon/environment/ObjectModelHelper.java
  
  Index: ObjectModelHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/ObjectModelHelper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ObjectModelHelper.java	19 Aug 2002 11:14:05 -0000	1.6
  +++ ObjectModelHelper.java	2 Dec 2002 08:39:17 -0000	1.7
  @@ -86,6 +86,10 @@
       /** Key for the environment {@link Context} in the object model. */
       public final static String EXPIRES_OBJECT  = "expires";
   
  +    /** Key for a {@link Map} containing information from
  +     * a parent request provided to a sub-request (internal processing) */
  +    public final static String PARENT_CONTEXT = "parent-context";
  +     
       private ObjectModelHelper() {
           // Forbid instantiation
       }
  
  
  
  1.25      +9 -2      xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
  
  Index: SitemapSource.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- SitemapSource.java	20 Nov 2002 14:23:33 -0000	1.24
  +++ SitemapSource.java	2 Dec 2002 08:39:17 -0000	1.25
  @@ -50,13 +50,13 @@
   */
   package org.apache.cocoon.components.source.impl;
   
  +import org.apache.excalibur.source.Recyclable;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceNotFoundException;
   import org.apache.excalibur.source.SourceValidity;
   import org.apache.excalibur.source.impl.validity.AggregatedValidity;
   
  -import org.apache.avalon.excalibur.pool.Recyclable;
   import org.apache.avalon.excalibur.xml.XMLizable;
   
   import org.apache.avalon.framework.component.ComponentException;
  @@ -68,6 +68,8 @@
   import org.apache.cocoon.components.EnvironmentStack;
   import org.apache.cocoon.components.pipeline.ProcessingPipeline;
   import org.apache.cocoon.environment.Environment;
  +import org.apache.cocoon.environment.ObjectModelHelper;
  +import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
   import org.apache.cocoon.xml.AbstractXMLConsumer;
   import org.apache.cocoon.xml.ContentHandlerWrapper;
  @@ -203,6 +205,11 @@
               "cocoon://" + requestURI + "?" + queryString;
   
           this.environment = new EnvironmentWrapper(env, requestURI, queryString, logger,
manager, rawMode);
  +        if ( null != parameters ) {
  +            this.environment.getObjectModel().put(ObjectModelHelper.PARENT_CONTEXT, parameters);
  +        } else {
  +            this.environment.getObjectModel().remove(ObjectModelHelper.PARENT_CONTEXT);
  +        }
           this.uri = uri;
           this.discardValidity();
       }
  
  
  
  1.3       +9 -1      xml-cocoon2/src/java/org/apache/cocoon/components/EnvironmentStack.java
  
  Index: EnvironmentStack.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/EnvironmentStack.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EnvironmentStack.java	21 Nov 2002 08:42:19 -0000	1.2
  +++ EnvironmentStack.java	2 Dec 2002 08:39:17 -0000	1.3
  @@ -60,7 +60,9 @@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
    */
  -public final class EnvironmentStack extends ArrayStack {
  +public final class EnvironmentStack 
  +    extends ArrayStack 
  +    implements Cloneable {
       
       int offset;
       
  @@ -82,6 +84,12 @@
       
       public int getOffset() {
           return this.offset;
  +    }
  +    
  +    public Object clone() {
  +        EnvironmentStack old = (EnvironmentStack) super.clone();
  +        old.offset = offset;
  +        return old;
       }
   }
   
  
  
  
  1.42      +33 -4     xml-cocoon2/src/java/org/apache/cocoon/components/CocoonComponentManager.java
  
  Index: CocoonComponentManager.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/CocoonComponentManager.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- CocoonComponentManager.java	22 Nov 2002 06:37:46 -0000	1.41
  +++ CocoonComponentManager.java	2 Dec 2002 08:39:17 -0000	1.42
  @@ -94,7 +94,7 @@
            
       
       /** The environment information */
  -    private static InheritableThreadLocal environmentStack = new InheritableThreadLocal();
  +    private static InheritableThreadLocal environmentStack = new CloningInheritableThreadLocal();
   
       /** The configured <code>SourceResolver</code> */
       private SourceResolver sourceResolver;
  @@ -226,6 +226,12 @@
        */
       public Component lookup( final String role )
       throws ComponentException {
  +        if( null == role ) {
  +            final String message =
  +                "ComponentLocator Attempted to retrieve component with null role.";
  +
  +            throw new ComponentException( role, message );
  +        }
           if ( role.equals(SourceResolver.ROLE) ) {
               if ( null == this.sourceResolver ) {
                   this.sourceResolver = (SourceResolver) super.lookup( role );
  @@ -249,7 +255,7 @@
           final Component component = super.lookup( role );
           if (null != component && component instanceof RequestLifecycleComponent)
{
               if (stack == null || stack.empty()) {
  -                throw new ComponentException("ComponentManager has no Environment Stack.");
  +                throw new ComponentException(role, "ComponentManager has no Environment
Stack.");
               }
               final Object[] objects = (Object[]) stack.getCurrent();
               final Map objectModel = ((Environment)objects[0]).getObjectModel();
  @@ -288,7 +294,7 @@
                               }
                           }
                       } catch (Exception local) {
  -                        throw new ComponentException("Exception during setup of RequestLifecycleComponent
with role '"+role+"'", local);
  +                        throw new ComponentException(role, "Exception during setup of RequestLifecycleComponent.",
local);
                       }
                       desc.addRequestLifecycleComponent(role, component, this);
                   }
  @@ -551,4 +557,27 @@
       }               
   }
   
  +final class CloningInheritableThreadLocal 
  +    extends InheritableThreadLocal {
  +
  +    /**
  +     * Computes the child's initial value for this InheritableThreadLocal
  +     * as a function of the parent's value at the time the child Thread is
  +     * created.  This method is called from within the parent thread before
  +     * the child is started.
  +     * <p>
  +     * This method merely returns its input argument, and should be overridden
  +     * if a different behavior is desired.
  +     *
  +     * @param parentValue the parent thread's value 
  +     * @return the child thread's initial value
  +     */
  +    protected Object childValue(Object parentValue) {
  +        if ( null != parentValue) {
  +            return ((EnvironmentStack)parentValue).clone();
  +        } else {
  +            return null;
  +        }
  +    }
  +}
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message