remm        2002/11/25 13:03:50

  Modified:    catalina/src/share/org/apache/catalina/core
                        ApplicationFilterChain.java
                        ApplicationFilterFactory.java DummyRequest.java
                        StandardPipeline.java StandardWrapperValve.java
  Added:       catalina/src/share/org/apache/catalina/core
                        StandardValveContext.java
  Log:
  - Optimize valves and filters processing (more optimization of
    the filter part coming).
  - Use request fields instead of allocating objects on each invocation.
  
  Revision  Changes    Path
  1.4       +5 -5      
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java
  
  Index: ApplicationFilterChain.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ApplicationFilterChain.java       16 Oct 2002 15:42:09 -0000      1.3
  +++ ApplicationFilterChain.java       25 Nov 2002 21:03:50 -0000      1.4
  @@ -329,7 +329,7 @@
       void release() {
   
           this.filters.clear();
  -        this.iterator = iterator;
  +        this.iterator = null;
           this.servlet = null;
   
       }
  
  
  
  1.4       +18 -4     
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationFilterFactory.java
  
  Index: ApplicationFilterFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationFilterFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ApplicationFilterFactory.java     12 Sep 2002 00:09:27 -0000      1.3
  +++ ApplicationFilterFactory.java     25 Nov 2002 21:03:50 -0000      1.4
  @@ -98,6 +98,9 @@
       public static final String 
DISPATCHER_TYPE_ATTR="org.apache.catalina.core.DISPATCHER_TYPE";
       public static final String 
DISPATCHER_REQUEST_PATH_ATTR="org.apache.catalina.core.DISPATCHER_REQUEST_PATH";
   
  +    private static final SecurityManager securityManager = 
  +        System.getSecurityManager();
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -142,7 +145,18 @@
               return (null);
   
           // Create and initialize a filter chain object
  -        ApplicationFilterChain filterChain = new ApplicationFilterChain();
  +        ApplicationFilterChain filterChain = null;
  +        if (securityManager == null) {
  +            Request req = (Request) request;
  +            filterChain = (ApplicationFilterChain) req.getFilterChain();
  +            if (filterChain == null) {
  +                filterChain = new ApplicationFilterChain();
  +                req.setFilterChain(filterChain);
  +            }
  +        } else {
  +            // Security: Do not recycle
  +            filterChain = new ApplicationFilterChain();
  +        }
   
           filterChain.setServlet(servlet);
   
  
  
  
  1.2       +25 -4     
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/DummyRequest.java
  
  Index: DummyRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/DummyRequest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DummyRequest.java 9 Oct 2002 08:01:11 -0000       1.1
  +++ DummyRequest.java 25 Nov 2002 21:03:50 -0000      1.2
  @@ -91,6 +91,7 @@
   import javax.naming.NamingException;
   import javax.naming.Binding;
   import javax.naming.directory.DirContext;
  +import javax.servlet.FilterChain;
   import javax.servlet.RequestDispatcher;
   import javax.servlet.Servlet;
   import javax.servlet.ServletContext;
  @@ -112,6 +113,7 @@
   import org.apache.catalina.HttpRequest;
   import org.apache.catalina.Logger;
   import org.apache.catalina.Response;
  +import org.apache.catalina.ValveContext;
   import org.apache.catalina.Wrapper;
   import org.apache.catalina.deploy.ApplicationParameter;
   import org.apache.catalina.util.Enumerator;
  @@ -149,6 +151,9 @@
       protected String servletPath = null;
       protected Wrapper wrapper = null;
   
  +    protected FilterChain filterChain = null;
  +    protected ValveContext valveContext = null;
  +
       public String getContextPath() {
           return (contextPath);
       }
  @@ -161,6 +166,14 @@
           return decodedURI;
       }
   
  +    public FilterChain getFilterChain() {
  +        return (this.filterChain);
  +    }
  +
  +    public void setFilterChain(FilterChain filterChain) {
  +        this.filterChain = filterChain;
  +    }
  +
       public String getQueryString() {
           return queryString;
       }
  @@ -183,6 +196,14 @@
   
       public void setServletPath(String path) {
           servletPath = path;
  +    }
  +
  +    public ValveContext getValveContext() {
  +        return (this.valveContext);
  +    }
  +
  +    public void setValveContext(ValveContext valveContext) {
  +        this.valveContext = valveContext;
       }
   
       public Wrapper getWrapper() {
  
  
  
  1.2       +14 -75    
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardPipeline.java
  
  Index: StandardPipeline.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardPipeline.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardPipeline.java     18 Jul 2002 16:48:13 -0000      1.1
  +++ StandardPipeline.java     25 Nov 2002 21:03:50 -0000      1.2
  @@ -477,7 +477,17 @@
           throws IOException, ServletException {
   
           // Invoke the first Valve in this pipeline for this request
  -        (new StandardPipelineValveContext()).invokeNext(request, response);
  +        //(new StandardPipelineValveContext()).invokeNext(request, response);
  +
  +        StandardValveContext valveContext = 
  +            (StandardValveContext) request.getValveContext();
  +        if (valveContext == null) {
  +            valveContext = new StandardValveContext();
  +            request.setValveContext(valveContext);
  +        }
  +
  +        valveContext.set(basic, valves);
  +        valveContext.invokeNext(request, response);
   
       }
   
  @@ -577,77 +587,6 @@
                                  "]: " + message);
               throwable.printStackTrace(System.out);
           }
  -
  -    }
  -
  -
  -    // ------------------------------- StandardPipelineValveContext Inner Class
  -
  -
  -    protected class StandardPipelineValveContext
  -        implements ValveContext {
  -
  -
  -        // ------------------------------------------------- Instance Variables
  -
  -
  -        protected int stage = 0;
  -
  -
  -        // --------------------------------------------------------- Properties
  -
  -
  -        /**
  -          * Return descriptive information about this ValveContext 
  -          * implementation.
  -          */
  -        public String getInfo() {
  -            return info;
  -        }
  -
  -
  -        // ----------------------------------------------------- Public Methods
  -
  -
  -        /**
  -         * Cause the <code>invoke()</code> method of the next Valve that is 
  -         * part of the Pipeline currently being processed (if any) to be 
  -         * executed, passing on the specified request and response objects 
  -         * plus this <code>ValveContext</code> instance.  Exceptions thrown by
  -         * a subsequently executed Valve (or a Filter or Servlet at the 
  -         * application level) will be passed on to our caller.
  -         *
  -         * If there are no more Valves to be executed, an appropriate
  -         * ServletException will be thrown by this ValveContext.
  -         *
  -         * @param request The request currently being processed
  -         * @param response The response currently being created
  -         *
  -         * @exception IOException if thrown by a subsequent Valve, Filter, or
  -         *  Servlet
  -         * @exception ServletException if thrown by a subsequent Valve, Filter,
  -         *  or Servlet
  -         * @exception ServletException if there are no further Valves 
  -         *  configured in the Pipeline currently being processed
  -         */
  -        public void invokeNext(Request request, Response response)
  -            throws IOException, ServletException {
  -
  -            int subscript = stage;
  -            stage = stage + 1;
  -
  -            // Invoke the requested Valve for the current request thread
  -            if (subscript < valves.length) {
  -                valves[subscript].invoke(request, response, this);
  -            } else if ((subscript == valves.length) && (basic != null)) {
  -                basic.invoke(request, response, this);
  -            } else {
  -                throw new ServletException
  -                    (sm.getString("standardPipeline.noValve"));
  -            }
  -
  -        }
  -
   
       }
   
  
  
  
  1.7       +6 -5      
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java
  
  Index: StandardWrapperValve.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StandardWrapperValve.java 9 Oct 2002 12:52:40 -0000       1.6
  +++ StandardWrapperValve.java 25 Nov 2002 21:03:50 -0000      1.7
  @@ -262,7 +262,8 @@
           ApplicationFilterFactory factory = 
               ApplicationFilterFactory.getInstance();
           ApplicationFilterChain filterChain = 
  -            factory.createFilterChain(sreq, wrapper, servlet);
  +            factory.createFilterChain((ServletRequest) request, 
  +                                      wrapper, servlet);
   
           // Call the filter chain for this request
           // NOTE: This also calls the servlet's service() method
  
  
  
  1.1                  
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardValveContext.java
  
  Index: StandardValveContext.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardValveContext.java,v
 1.1 2002/11/25 21:03:50 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2002/11/25 21:03:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.catalina.core;
  
  
  import java.io.IOException;
  import javax.servlet.ServletException;
  import org.apache.catalina.Request;
  import org.apache.catalina.Response;
  import org.apache.catalina.Valve;
  import org.apache.catalina.ValveContext;
  import org.apache.catalina.util.StringManager;
  
  
  /**
   * Standard implementation of a <code>ValveContext</code>.
   *
   * @author Craig R. McClanahan
   * @author Remy Maucherat
   */
  
  public class StandardValveContext
      implements ValveContext {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The string manager for this package.
       */
      protected static StringManager sm =
          StringManager.getManager(Constants.Package);
  
  
      protected String info = 
          "org.apache.catalina.core.StandardValveContext/1.0";
      protected int stage = 0;
      protected Valve basic = null;
      protected Valve valves[] = null;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return descriptive information about this ValveContext 
       * implementation.
       */
      public String getInfo() {
          return info;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Cause the <code>invoke()</code> method of the next Valve that is 
       * part of the Pipeline currently being processed (if any) to be 
       * executed, passing on the specified request and response objects 
       * plus this <code>ValveContext</code> instance.  Exceptions thrown by
       * a subsequently executed Valve (or a Filter or Servlet at the 
       * application level) will be passed on to our caller.
       *
       * If there are no more Valves to be executed, an appropriate
       * ServletException will be thrown by this ValveContext.
       *
       * @param request The request currently being processed
       * @param response The response currently being created
       *
       * @exception IOException if thrown by a subsequent Valve, Filter, or
       *  Servlet
       * @exception ServletException if thrown by a subsequent Valve, Filter,
       *  or Servlet
       * @exception ServletException if there are no further Valves 
       *  configured in the Pipeline currently being processed
       */
      public void invokeNext(Request request, Response response)
          throws IOException, ServletException {
  
          int subscript = stage;
          stage = stage + 1;
  
          // Invoke the requested Valve for the current request thread
          if (subscript < valves.length) {
              valves[subscript].invoke(request, response, this);
          } else if ((subscript == valves.length) && (basic != null)) {
              basic.invoke(request, response, this);
          } else {
              throw new ServletException
                  (sm.getString("standardPipeline.noValve"));
          }
  
      }
  
  
      // -------------------------------------------------------- Package Methods
  
  
      /**
       * Reset state.
       */
      void set(Valve basic, Valve valves[]) {
          stage = 0;
          this.basic = basic;
          this.valves = valves;
      }
  
  
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to