You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2002/12/02 09:37:43 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components EnvironmentStack.java CocoonComponentManager.java

cziegeler    2002/12/02 00:37:43

  Modified:    src/java/org/apache/cocoon/components Tag:
                        cocoon_2_0_3_branch EnvironmentStack.java
                        CocoonComponentManager.java
  Log:
  Finally fixing environment stack handling for multi-threading
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +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.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- EnvironmentStack.java	20 Nov 2002 14:53:21 -0000	1.1.2.1
  +++ EnvironmentStack.java	2 Dec 2002 08:37:42 -0000	1.1.2.2
  @@ -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.13.2.7  +35 -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.13.2.6
  retrieving revision 1.13.2.7
  diff -u -r1.13.2.6 -r1.13.2.7
  --- CocoonComponentManager.java	22 Nov 2002 06:38:49 -0000	1.13.2.6
  +++ CocoonComponentManager.java	2 Dec 2002 08:37:42 -0000	1.13.2.7
  @@ -89,7 +89,7 @@
            
       
       /** The environment information */
  -    private static InheritableThreadLocal environmentStack = new InheritableThreadLocal();
  +    private static InheritableThreadLocal environmentStack = new CloningInheritableThreadLocal();
   
       /** Create the ComponentManager */
       public CocoonComponentManager()
  @@ -209,6 +209,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 );
  +        }
           final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
           if ( null != stack && !stack.empty()) {
               final Object[] objects = (Object[])stack.getCurrent();
  @@ -225,7 +231,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();
  @@ -241,7 +247,7 @@
                           ((RequestLifecycleComponent) component).setup((org.apache.cocoon.environment.SourceResolver)objects[0],
                                                                 objectModel);
                       } 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);
                   }
  @@ -457,3 +463,28 @@
           this.sitemapConfigurations.remove(this.sitemapConfigurations.size()-1);
       }               
   }
  +
  +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