myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1296668 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: context/ context/servlet/ lifecycle/ view/ view/facelets/
Date Sat, 03 Mar 2012 16:54:28 GMT
Author: lu4242
Date: Sat Mar  3 16:54:27 2012
New Revision: 1296668

URL: http://svn.apache.org/viewvc?rev=1296668&view=rev
Log:
MYFACES-3486 [perf] cache Factories to prevent unnecessary FactoryFinder.getFactory() calls

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java?rev=1296668&r1=1296667&r2=1296668&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java
Sat Mar  3 16:54:27 2012
@@ -24,12 +24,15 @@ import java.util.logging.Logger;
 
 import javax.faces.FacesException;
 import javax.faces.FactoryFinder;
+import javax.faces.application.ApplicationFactory;
 import javax.faces.context.ExceptionHandlerFactory;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.ExternalContextFactory;
 import javax.faces.context.FacesContext;
 import javax.faces.context.FacesContextFactory;
+import javax.faces.context.PartialViewContextFactory;
 import javax.faces.lifecycle.Lifecycle;
+import javax.faces.render.RenderKitFactory;
 
 import org.apache.myfaces.context.servlet.FacesContextImpl;
 import org.apache.myfaces.shared.util.ClassUtils;
@@ -55,7 +58,13 @@ public class FacesContextFactoryImpl ext
      * Reference to factory to prevent unnecessary lookups
      */
     private final ExceptionHandlerFactory _exceptionHandlerFactory;
-        
+    
+    private final ApplicationFactory _applicationFactory;
+    
+    private final RenderKitFactory _renderKitFactory;
+    
+    private final PartialViewContextFactory _partialViewContextFactory;
+    
     /**
      * This var is assigned as the same as javax.faces.context.ExternalContext._firstInstance,
      * and since it is a static reference and does not change, we can cache it here safely.
@@ -110,6 +119,14 @@ public class FacesContextFactoryImpl ext
         _exceptionHandlerFactory = (ExceptionHandlerFactory)
             FactoryFinder.getFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY);
         
+        _applicationFactory = (ApplicationFactory)
+            FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+        
+        _renderKitFactory = (RenderKitFactory)
+            FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+
+        _partialViewContextFactory = (PartialViewContextFactory) 
+            FactoryFinder.getFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY);
     }
 
     @Override
@@ -158,16 +175,21 @@ public class FacesContextFactoryImpl ext
             if (externalContext instanceof ReleaseableExternalContext)
             {
                 facesContext = new FacesContextImpl(externalContext, (ReleaseableExternalContext)
externalContext,
-                                                    this);
+                                                    this, _applicationFactory, _renderKitFactory,

+                                                    _partialViewContextFactory);
             }
             else if (defaultExternalContext != null && defaultExternalContext instanceof
ReleaseableExternalContext)
             {
                 facesContext = new FacesContextImpl(externalContext,
-                                                    (ReleaseableExternalContext) defaultExternalContext,
this);
+                                                    (ReleaseableExternalContext) defaultExternalContext,
this,
+                                                    _applicationFactory, _renderKitFactory,

+                                                    _partialViewContextFactory);
             }
             else
             {
-                facesContext = new FacesContextImpl(externalContext, null, this);
+                facesContext = new FacesContextImpl(externalContext, null, this,
+                                                    _applicationFactory, _renderKitFactory,

+                                                    _partialViewContextFactory);
             }
             
             facesContext.setExceptionHandler(_exceptionHandlerFactory.getExceptionHandler());

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java?rev=1296668&r1=1296667&r2=1296668&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java
Sat Mar  3 16:54:27 2012
@@ -18,6 +18,8 @@
  */
 package org.apache.myfaces.context;
 
+import javax.faces.FactoryFinder;
+import javax.faces.component.visit.VisitContextFactory;
 import javax.faces.context.FacesContext;
 import javax.faces.context.PartialViewContext;
 import javax.faces.context.PartialViewContextFactory;
@@ -26,10 +28,20 @@ import org.apache.myfaces.context.servle
 
 public class PartialViewContextFactoryImpl extends PartialViewContextFactory
 {
+    private final VisitContextFactory _visitContextFactory;
+    
+    public PartialViewContextFactoryImpl()
+    {
+        super();
+        
+        _visitContextFactory = (VisitContextFactory) 
+            FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+    }
 
+    
     @Override
     public PartialViewContext getPartialViewContext(FacesContext context)
     {
-        return new PartialViewContextImpl(context);
+        return new PartialViewContextImpl(context, _visitContextFactory);
     }
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java?rev=1296668&r1=1296667&r2=1296668&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
Sat Mar  3 16:54:27 2012
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 
 import javax.faces.FactoryFinder;
+import javax.faces.application.ApplicationFactory;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
@@ -68,6 +69,9 @@ public class FacesContextImpl extends Fa
     private boolean _validationFailed = false;
     private PartialViewContext _partialViewContext = null;
     private ReleaseableFacesContextFactory _facesContextFactory = null;
+    
+    private PartialViewContextFactory _partialViewContextFactory = null;
+    private RenderKitFactory _renderKitFactory = null;
 
     // ~ Constructors -------------------------------------------------------------------------------
     
@@ -105,6 +109,22 @@ public class FacesContextImpl extends Fa
         
         _facesContextFactory = facesContextFactory;
     }
+    
+    public FacesContextImpl(final ExternalContext externalContext,
+            final ReleaseableExternalContext defaultExternalContext , 
+            final ReleaseableFacesContextFactory facesContextFactory,
+            final ApplicationFactory applicationFactory,
+            final RenderKitFactory renderKitFactory,
+            final PartialViewContextFactory partialViewContextFactory)
+    {
+        // setCurrentInstance is called in constructor of super class
+        super(externalContext, defaultExternalContext, applicationFactory, 
+                renderKitFactory);
+        
+        _facesContextFactory = facesContextFactory;
+        _renderKitFactory = renderKitFactory;
+        _partialViewContextFactory = partialViewContextFactory;
+    }
 
     // ~ Methods ------------------------------------------------------------------------------------
     
@@ -120,7 +140,10 @@ public class FacesContextImpl extends Fa
         _responseWriter = null;
         _maximumSeverity = null;
         _partialViewContext = null;
-        
+        _facesContextFactory = null;
+        _renderKitFactory = null;
+        _partialViewContextFactory = null;
+
         if (_facesContextFactory != null)
         {
             _facesContextFactory.release();
@@ -269,10 +292,13 @@ public class FacesContextImpl extends Fa
         if (_partialViewContext == null)
         {
             //Get through factory finder
-            PartialViewContextFactory factory = (PartialViewContextFactory)
-                FactoryFinder.getFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY);
+            if (_partialViewContextFactory == null)
+            {
+                _partialViewContextFactory = (PartialViewContextFactory)
+                    FactoryFinder.getFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY);
+            }
             // Put actual facesContext as param, not this - this can be wrapped
-            _partialViewContext = factory.getPartialViewContext(FacesContext.getCurrentInstance());
+            _partialViewContext = _partialViewContextFactory.getPartialViewContext(FacesContext.getCurrentInstance());
         }
         return _partialViewContext;
     }
@@ -375,9 +401,12 @@ public class FacesContextImpl extends Fa
             // method to check if a request is a postback, is always detect the param
             // javax.faces.ViewState, so there is no problem after all.
             String renderKitId = facesContext.getApplication().getViewHandler().calculateRenderKitId(facesContext);
-            RenderKitFactory factory = (RenderKitFactory) 
-                FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
-            renderKit = factory.getRenderKit(facesContext, renderKitId);
+            if (_renderKitFactory == null)
+            {
+                _renderKitFactory = (RenderKitFactory) 
+                    FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+            }
+            renderKit = _renderKitFactory.getRenderKit(facesContext, renderKitId);
         }
         return renderKit.getResponseStateManager().isPostback(facesContext);
     }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java?rev=1296668&r1=1296667&r2=1296668&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
Sat Mar  3 16:54:27 2012
@@ -63,6 +63,8 @@ public abstract class FacesContextImplBa
     
     protected boolean _released = false;
     
+    private ApplicationFactory _applicationFactory = null;
+
     /**
      * Base constructor.
      * Calls FacesContext.setCurrentInstance(this);
@@ -78,6 +80,22 @@ public abstract class FacesContextImplBa
         FacesContext.setCurrentInstance(this);
     }
     
+    public FacesContextImplBase(final ExternalContext externalContext,
+            final ReleaseableExternalContext defaultExternalContext,
+            final ApplicationFactory applicationFactory,
+            final RenderKitFactory renderKitFactory)
+    {
+        _externalContext = externalContext;
+        _defaultExternalContext = defaultExternalContext;
+        
+        _applicationFactory = applicationFactory;
+        _renderKitFactory = renderKitFactory;
+        
+        // this FacesContext impl is now the current instance
+        // note that because this method is protected, it has to be called from here
+        FacesContext.setCurrentInstance(this);
+    }
+    
     /**
      * Releases the instance fields on FacesContextImplBase.
      * Must be called by sub-classes, when overriding it!
@@ -85,6 +103,8 @@ public abstract class FacesContextImplBa
     @Override
     public void release()
     {
+        _applicationFactory = null;
+
         if (_defaultExternalContext != null)
         {
             _defaultExternalContext.release();
@@ -134,8 +154,12 @@ public abstract class FacesContextImplBa
         
         if (_application == null)
         {
-            _application = ((ApplicationFactory) FactoryFinder.getFactory(
-                    FactoryFinder.APPLICATION_FACTORY)).getApplication();
+            if (_applicationFactory == null)
+            {
+                _applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(
+                    FactoryFinder.APPLICATION_FACTORY);
+            }
+            _application = _applicationFactory.getApplication();
         }
         
         return _application;

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java?rev=1296668&r1=1296667&r2=1296668&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
Sat Mar  3 16:54:27 2012
@@ -35,6 +35,7 @@ import javax.faces.component.html.HtmlBo
 import javax.faces.component.html.HtmlHead;
 import javax.faces.component.visit.VisitCallback;
 import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitContextFactory;
 import javax.faces.component.visit.VisitHint;
 import javax.faces.component.visit.VisitResult;
 import javax.faces.context.ExternalContext;
@@ -87,11 +88,19 @@ public class PartialViewContextImpl exte
     private Boolean _partialRequest = null;
     private Boolean _renderAll = null;
     private PartialResponseWriter _partialResponseWriter = null;
+    private VisitContextFactory _visitContextFactory = null;
 
     public PartialViewContextImpl(FacesContext context)
     {
         _facesContext = context;
     }
+    
+    public PartialViewContextImpl(FacesContext context, 
+            VisitContextFactory visitContextFactory)
+    {
+        _facesContext = context;
+        _visitContextFactory = visitContextFactory;
+    }
 
     @Override
     public boolean isAjaxRequest()
@@ -400,7 +409,7 @@ public class PartialViewContextImpl exte
         Set<VisitHint> hints = new HashSet<VisitHint>();
         hints.add(VisitHint.EXECUTE_LIFECYCLE);
         hints.add(VisitHint.SKIP_UNRENDERED);
-        VisitContext visitCtx = VisitContext.createVisitContext(_facesContext, executeIds,
hints);
+        VisitContext visitCtx = getVisitContextFactory().getVisitContext(_facesContext, executeIds,
hints);
         viewRoot.visitTree(visitCtx, new PhaseAwareVisitCallback(_facesContext, phaseId));
     }
 
@@ -501,7 +510,8 @@ public class PartialViewContextImpl exte
                             }
                         }
 
-                        VisitContext visitCtx = VisitContext.createVisitContext(_facesContext,
renderIds, hints);
+                        VisitContext visitCtx = getVisitContextFactory().getVisitContext(
+                                _facesContext, renderIds, hints);
                         viewRoot.visitTree(visitCtx,
                                            new PhaseAwareVisitCallback(_facesContext, phaseId,
updatedComponents));
                     }
@@ -626,6 +636,7 @@ public class PartialViewContextImpl exte
     public void release()
     {
         assertNotReleased();
+        _visitContextFactory = null;
         _executeClientIds = null;
         _renderClientIds = null;
         _ajaxRequest = null;
@@ -678,6 +689,15 @@ public class PartialViewContextImpl exte
         }
         return null;
     }
+    
+    private VisitContextFactory getVisitContextFactory()
+    {
+        if (_visitContextFactory == null)
+        {
+            _visitContextFactory = (VisitContextFactory)FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+        }
+        return _visitContextFactory;
+    }
 
     private class PhaseAwareVisitCallback implements VisitCallback
     {

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java?rev=1296668&r1=1296667&r2=1296668&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
Sat Mar  3 16:54:27 2012
@@ -87,6 +87,7 @@ public class DefaultRestoreViewSupport i
     private Boolean _checkedViewIdCacheEnabled = null;
     
     private RenderKitFactory _renderKitFactory = null;
+    private VisitContextFactory _visitContextFactory = null;
 
     public void processComponentBinding(FacesContext facesContext, UIComponent component)
     {
@@ -101,7 +102,8 @@ public class DefaultRestoreViewSupport i
             facesContext.getAttributes().put(SKIP_ITERATION_HINT, Boolean.TRUE);
 
             EnumSet<VisitHint> visitHints = EnumSet.of(VisitHint.SKIP_ITERATION);
-            VisitContext visitContext = VisitContext.createVisitContext(facesContext, null,
visitHints);
+            VisitContext visitContext = (VisitContext) getVisitContextFactory().
+                    getVisitContext(facesContext, null, visitHints);
             component.visitTree(visitContext, new RestoreStateCallback());
         }
         finally
@@ -211,6 +213,15 @@ public class DefaultRestoreViewSupport i
         }
         return _renderKitFactory;
     }
+    
+    protected VisitContextFactory getVisitContextFactory()
+    {
+        if (_visitContextFactory == null)
+        {
+            _visitContextFactory = (VisitContextFactory)FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+        }
+        return _visitContextFactory;
+    }
         
     private static class RestoreStateCallback implements VisitCallback
     {

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java?rev=1296668&r1=1296667&r2=1296668&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
Sat Mar  3 16:54:27 2012
@@ -52,8 +52,8 @@ public class ViewDeclarationLanguageFact
 
     private static final Logger LOGGER = Logger.getLogger(ViewDeclarationLanguageFactoryImpl.class.getName());
     
-    private boolean _initialized;
-    private ViewDeclarationLanguageStrategy[] _supportedLanguages;
+    private volatile boolean _initialized;
+    private volatile ViewDeclarationLanguageStrategy[] _supportedLanguages;
     
     /**
      * 
@@ -77,7 +77,10 @@ public class ViewDeclarationLanguageFact
         // TODO: It would be nice to be able to preinitialize the factory. However, since
it requires 
         //       access to the ExternalContext it may not be possible, depending on the loading
order 
         //       in the FactoryFinder. Could use ideas here. -= SL =-
-        initialize();
+        if (!_initialized)
+        {
+            initialize();
+        }
         
         for (ViewDeclarationLanguageStrategy strategy : _supportedLanguages)
         {

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=1296668&r1=1296667&r2=1296668&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
Sat Mar  3 16:54:27 2012
@@ -40,6 +40,7 @@ import javax.faces.component.UIViewParam
 import javax.faces.component.UIViewRoot;
 import javax.faces.component.visit.VisitCallback;
 import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitContextFactory;
 import javax.faces.component.visit.VisitHint;
 import javax.faces.component.visit.VisitResult;
 import javax.faces.context.ExternalContext;
@@ -170,6 +171,8 @@ public class DefaultFaceletsStateManagem
     
     private RenderKitFactory _renderKitFactory = null;
     
+    private VisitContextFactory _visitContextFactory = null;
+    
     private Boolean _saveStateWithVisitTreeOnPSS;
     
     private String _checkIdsProductionMode;
@@ -714,7 +717,8 @@ public class DefaultFaceletsStateManagem
         try
         {
             EnumSet<VisitHint> visitHints = EnumSet.of(VisitHint.SKIP_ITERATION);
-            uiViewRoot.visitTree( VisitContext.createVisitContext (facesContext, null, visitHints),
new VisitCallback()
+            uiViewRoot.visitTree( getVisitContextFactory().getVisitContext(
+                    facesContext, null, visitHints), new VisitCallback()
             {
                 public VisitResult visit(VisitContext context, UIComponent target)
                 {
@@ -1012,6 +1016,15 @@ public class DefaultFaceletsStateManagem
         }
         return _renderKitFactory;
     }
+    
+    protected VisitContextFactory getVisitContextFactory()
+    {
+        if (_visitContextFactory == null)
+        {
+            _visitContextFactory = (VisitContextFactory)FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+        }
+        return _visitContextFactory;
+    }
 
     protected String getCheckIdProductionMode(FacesContext facesContext)
     {



Mime
View raw message