You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by cr...@apache.org on 2006/04/26 17:39:24 UTC

svn commit: r397224 - /beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java

Author: crogers
Date: Wed Apr 26 08:39:23 2006
New Revision: 397224

URL: http://svn.apache.org/viewcvs?rev=397224&view=rev
Log:
Fix for http://issues.apache.org/jira/browse/BEEHIVE-1105 - Perf bottleneck with the number of calls from PageFlowPageFilter to get ActionServlet from ServletContext. As noted in the bug, a better, long term solution such as a caching layer should be implemented. For now, this will help relieve some of the contention for getting the ActionServlet from the ServletContext. The solution with this change tracks the module paths that do not have a module config and skips code paths that would try and register it.

tests: bvt in netui (WinXP)



Modified:
    beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java

Modified: beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java?rev=397224&r1=397223&r2=397224&view=diff
==============================================================================
--- beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java (original)
+++ beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java Wed Apr 26 08:39:23 2006
@@ -42,6 +42,7 @@
 import org.apache.beehive.netui.script.common.ImplicitObjectUtil;
 import org.apache.beehive.netui.util.internal.FileUtils;
 import org.apache.beehive.netui.util.internal.ServletUtils;
+import org.apache.beehive.netui.util.internal.concurrent.InternalConcurrentHashMap;
 import org.apache.beehive.netui.util.logging.Logger;
 import org.apache.struts.Globals;
 import org.apache.struts.action.ActionForm;
@@ -58,10 +59,12 @@
     implements Filter
 {
     private static final Logger LOG = Logger.getInstance( PageFlowPageFilter.class );
+    private static final String NO_MODULE_CONFIG = "no config";
 
     private ServletContext _servletContext;
     private ServletContainerAdapter _servletContainerAdapter;
     private FlowControllerFactory _flowControllerFactory;
+    private Map _knownModulePaths = new InternalConcurrentHashMap();
 
     protected PageFlowPageFilter()
     {
@@ -176,10 +179,33 @@
                 //
                 // Ensure that the right Struts module is selected, for use by the tags.
                 //
+                boolean noModuleConfig = false;
                 if ( rw == null || ! rw.isStayInCurrentModule() ) {
+                    // Dynamically register the Struts module, if appropriate.  If there's no
+                    // module config for a given path do not continue to try and register it.
+                    // Performance fix until we implement a better caching layer for getting
+                    // module configs, etc.
+                    //
+                    // Note that two threads could potentially get here at the same time, and
+                    // both will save the module path.  This is OK -- reads from _knownModulePaths
+                    // are consistent, and the worst that will happen is that ensureModuleConfig()
+                    // will get called and the module path will get set a few times.
                     String curModulePath = PageFlowUtils.getModulePath( httpRequest );
-                    InternalUtils.ensureModuleConfig( curModulePath, _servletContext );
-                    InternalUtils.selectModule( curModulePath, httpRequest, _servletContext );
+                    String registered = (String) _knownModulePaths.get(curModulePath);
+                    if (registered == null) {
+                        ModuleConfig mc = InternalUtils.ensureModuleConfig(curModulePath, _servletContext);
+                        if (mc == null) {
+                            _knownModulePaths.put(curModulePath, NO_MODULE_CONFIG);
+                            noModuleConfig = true;
+                        }
+                        else {
+                            _knownModulePaths.put(curModulePath, curModulePath);
+                        }
+                    }
+                    else if (NO_MODULE_CONFIG.equals(registered)) {
+                        noModuleConfig = true;
+                    }
+                    InternalUtils.selectModule(curModulePath, httpRequest, _servletContext);
                 }
 
                 try
@@ -195,13 +221,13 @@
                     //
                     // Make sure that the current PageFlowController is set up for this request.
                     //
-                    PageFlowController curJpf;
+                    PageFlowController curJpf = null;
                     if ( rw != null && rw.isStayInCurrentModule() )
                     {
                         rw.setStayInCurrentModule( false );
                         curJpf = PageFlowUtils.getCurrentPageFlow( httpRequest, _servletContext );
                     }
-                    else
+                    else if ( !noModuleConfig )
                     {
                         curJpf = _flowControllerFactory.getPageFlowForRequest( requestContext );
                     }
@@ -264,6 +290,7 @@
 
     public void destroy()
     {
+        _knownModulePaths.clear();
         _servletContext = null;
     }