myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r986196 - in /myfaces/trinidad/trunk: src/site/xdoc/devguide/configuration.xml src/site/xdoc/release-notes.xml trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
Date Tue, 17 Aug 2010 05:52:13 GMT
Author: matzew
Date: Tue Aug 17 05:52:13 2010
New Revision: 986196

URL: http://svn.apache.org/viewvc?rev=986196&view=rev
Log:
TRINIDAD-1669 -  Improve transient memory consumption of UIXComponentBase.getClientId()

applying patch from Andy Schwartz. Thanks dude!

Modified:
    myfaces/trinidad/trunk/src/site/xdoc/devguide/configuration.xml
    myfaces/trinidad/trunk/src/site/xdoc/release-notes.xml
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java

Modified: myfaces/trinidad/trunk/src/site/xdoc/devguide/configuration.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/src/site/xdoc/devguide/configuration.xml?rev=986196&r1=986195&r2=986196&view=diff
==============================================================================
--- myfaces/trinidad/trunk/src/site/xdoc/devguide/configuration.xml (original)
+++ myfaces/trinidad/trunk/src/site/xdoc/devguide/configuration.xml Tue Aug 17 05:52:13 2010
@@ -603,6 +603,50 @@ containing a single parameter.
       </subsection>
 
     </section>
+
+<section name="System properties">
+<p>
+Some Apache Trinidad configuration options are set by a System Property.
+</p>
+
+<subsection name="org.apache.myfaces.trinidad.CHECK_STATE_SERIALIZATION">
+<p>
+For better High Availability Testing Support the <code>org.apache.myfaces.trinidad.CHECK_STATE_SERIALIZATION</code>
System Property has been introduced.
+The behavior is controlled by passing a comma-delimited set of case-insensitive values on
the system property:
+<ul>
+<li><strong>NONE</strong> no state serialization checks are performed (the
default)</li>
+<li><strong>ALL</strong> perform all available tests (unless NONE is also
specified, in which case NONE takes precedence)</li>
+<li><strong>SESSION</strong> Wrap the Session Map returned by the ExternalContext
to test that only Serializable objects are placed in the Session Map, throwing a CastCastException
if the Object is not Serializable</li>
+<li><strong>TREE</strong> aggressively attempt to serialize the component
state during state saving and throw an exception if serialization fails</li>
+<li><strong>COMPONENT</strong> aggressively attempt to serialize each component
subtree's state during state saving in order to identify the problem component (slow)</li>
+<li><strong>PROPERTY</strong> aggessively attempt to serialize each property
value during state saving in order to identify the problem property (slow)</li>
+</ul>
+For high availability testing, the tester would initially start off validating the Session
and JSF state is Serializable by setting the system property to:
+<code>-Dorg.apache.myfaces.trinidad.CHECK_STATE_SERIALIZATION=session,tree</code>
+
+If a JSF state serialization is detected, the test is rerun with the component and property
flags enabled:
+<code>-Dorg.apache.myfaces.trinidad.CHECK_STATE_SERIALIZATION=all</code>
+</p>
+</subsection>
+
+<subsection name="org.apache.myfaces.trinidad.CLIENT_ID_CACHING">
+
+<p>The <code>org.apache.myfaces.trinidad.CLIENT_ID_CACHING</code> system
property controls the behavior of <code>UIXComponentBase.getClientId()</code>.
 By default, this method is optimized to reduce the amount of time spent building client id
strings.  The client id is computed and cached until the id is changed via a call to <code>setId()</code>.
 This matches the behavior of the standard <code>UIComponentBase.getClientId()</code>
implementation.</p>
+
+<p>Client id caching requires that iterating components reset the ids of any descendent
components on each iteration.  Failure to do this results in incorrect (the same) client ids
being used across iterations.  This system property is provided to help locate/debug such
cases.</p>
+
+<p>The following values may be specified:</p>
+
+<ul>
+<li><strong>OFF</strong> Client id caching will not be performed.  Instead,
the client id will be recalculated on each call to UIXComponentBase.getClientId().</li>
+<li><strong>DEBUG</strong> Client id caching will be performed and additional
debugging diagnostics will be logged.  This adds overhead to each call to UIXComponentBase.getClientId()
and as such should only be used for testing/debugging purposes.</li>
+<li><strong>ON</strong> Client id caching will be performed.</li>
+</ul>
+
+<p>The system property defaults to <code>ON</code>, which is the correct
value for production deployments.</p>
+</subsection>
+
+</section>
     
   </body>
 </document>

Modified: myfaces/trinidad/trunk/src/site/xdoc/release-notes.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/src/site/xdoc/release-notes.xml?rev=986196&r1=986195&r2=986196&view=diff
==============================================================================
--- myfaces/trinidad/trunk/src/site/xdoc/release-notes.xml (original)
+++ myfaces/trinidad/trunk/src/site/xdoc/release-notes.xml Tue Aug 17 05:52:13 2010
@@ -90,6 +90,8 @@ without stopping/starting the server.
 many portions of the page that are not being rerendered can be
 skipped entirely.
 </li>
+<li>UIXComponentBase.getClientId() now implements the same caching behavior that is
provided by UIComponentBase.  The client id is computed and cached the first time that getClientId()
is called.  The cached value is retained until any subsequent call to setId().  This caching
behavior can result in a significant performance boost, particularly for views with large/deep
component trees.  (See the <a href="devguide/configuration.html#org.apache.myfaces.trinidad.CLIENT_ID_CACHING">org.apache.myfaces.trinidad.CLIENT_ID_CACHING</a>
system property for more information.)
+</li>
 </ul>
 </subsection>
     

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java?rev=986196&r1=986195&r2=986196&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
(original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
Tue Aug 17 05:52:13 2010
@@ -31,20 +31,20 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
-import java.util.concurrent.atomic.AtomicReference;
-
 import javax.el.ELContext;
 import javax.el.ELException;
 import javax.el.MethodExpression;
 import javax.el.ValueExpression;
 
 import javax.faces.FacesException;
+import javax.faces.application.ProjectStage;
 import javax.faces.component.ContextCallback;
 import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
 import javax.faces.component.behavior.ClientBehavior;
 import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.el.EvaluationException;
 import javax.faces.el.MethodBinding;
@@ -351,7 +351,7 @@ abstract public class UIXComponentBase e
   @Override
   public String getClientId(FacesContext context)
   {
-    if (_isClientIdCachingEnabled(context))
+    if (_isClientIdCachingEnabled())
     {
       String clientId = _clientId;
 
@@ -374,8 +374,10 @@ abstract public class UIXComponentBase e
           _clientId = clientId;
         }
       }
-      else
+      else if (_isClientIdDebuggingEnabled())
       {
+        _warnClientIdCachingConfig(context);
+
         // for now validate success by checking the cached result against the dynamically
         // generated result
         String realID = _calculateClientId(context);
@@ -390,6 +392,8 @@ abstract public class UIXComponentBase e
     }
     else
     {
+      _warnClientIdCachingConfig(context);
+
       return _calculateClientId(context);
     }
   }
@@ -2071,43 +2075,118 @@ abstract public class UIXComponentBase e
   {
   }
 
-  /**
-   * Temporary function controlling whether clientId caching is enabled
-   */
-  private static boolean _isClientIdCachingEnabled(FacesContext context)
+  private static boolean _isClientIdCachingEnabled()
   {
-    if (context == null)
-      throw new IllegalArgumentException("FacesContext is null");
+    return (_CLIENT_ID_CACHING != ClientIdCaching.OFF);
+  }
 
-    Boolean cacheClientIds = _sClientIdCachingEnabled.get();
+  private static boolean _isClientIdDebuggingEnabled()
+  {
+    return (_CLIENT_ID_CACHING == ClientIdCaching.DEBUG);
+  }
 
-    if (cacheClientIds == null)
+  // Warn if caching is disabled + production environment since this is 
+  // undesirable from a performance perspective.
+  private static void _warnClientIdCachingConfig(FacesContext context)
+  {
+    if (_CLIENT_ID_CACHING != ClientIdCaching.ON &&
+         context.isProjectStage(ProjectStage.Production) &&
+         !_warnedClientIdCachingConfig(context))
     {
-      // get the servlet initialization parameter
-      String cachingParam = context.getExternalContext().getInitParameter(
-                                                             _INIT_PROP_CLIENT_ID_CACHING_ENABLED);
+      _LOG.warning(
+        "The org.apache.myfaces.trinidad.CLIENT_ID_CACHING system property is set to: " +
+         _CLIENT_ID_CACHING +
+        ".  For best performance, client id caching should be ON in production environments.");
+
+      _clientIdCachingConfigWarned(context);
+    }
+  }
+
+  // Tests whether we have already warned about the caching config.
+  // We only want to warn once per run.
+  private static boolean _warnedClientIdCachingConfig(FacesContext context)
+  {
+    ExternalContext external = context.getExternalContext();
+    Map<String, Object> appMap = external.getApplicationMap();
+
+    return Boolean.TRUE.equals(appMap.get(_WARNED_CLIENT_ID_CACHING_KEY));
+  }
+
+  // Marks the fact that we have now warned about the caching config.
+  private static void _clientIdCachingConfigWarned(FacesContext context)
+  {
+    ExternalContext external = context.getExternalContext();
+    Map<String, Object> appMap = external.getApplicationMap();
+
+    appMap.put(_WARNED_CLIENT_ID_CACHING_KEY, Boolean.TRUE);
+  }
 
-      Boolean cachingEnabled  = (cachingParam != null)
-                                  ? Boolean.valueOf(cachingParam)
-                                  : Boolean.FALSE;  // default to false
+  // Utility for deriving initial CLIENT_ID_CACHING value.
+  private static ClientIdCaching _initClientIdCaching()
+  {
+    String cachingProperty = _getClientIdCachingSystemProperty();
+    ClientIdCaching caching = _toClientIdCachingEnum(cachingProperty);
+
+    _LOG.config("Client id caching configuration: " + caching);
 
-      // cache the servlet initialization value
-      _sClientIdCachingEnabled.set(cachingEnabled ? Boolean.TRUE : Boolean.FALSE);
+    return caching;
+  }
 
-      return cachingEnabled;
+  private static String _getClientIdCachingSystemProperty()
+  {
+    try
+    {
+      return System.getProperty(_SYSTEM_PROP_CLIENT_ID_CACHING);
     }
-    else
+    catch (Throwable t)
+    {
+      _LOG.warning(t);
+    }
+
+    return null;
+  }
+  
+  private static ClientIdCaching _toClientIdCachingEnum(String cachingProperty)
+  {
+    try
     {
-      return cacheClientIds.booleanValue();
+      return Enum.valueOf(ClientIdCaching.class, 
+                           (cachingProperty == null) ? 
+                             "ON" :
+                             cachingProperty.toUpperCase());
+    }
+    catch (IllegalArgumentException e)
+    {
+      _LOG.warning("Invalid value specified for " +
+                   _SYSTEM_PROP_CLIENT_ID_CACHING +
+                   " system property: " +
+                   cachingProperty +
+                   ". Valid values are: on | off | debug.");
+
     }
+
+    return ClientIdCaching.ON;
   }
 
-  private static AtomicReference<Boolean> _sClientIdCachingEnabled =
-                                                                 new AtomicReference<Boolean>(null);
+  // Little enum for tracking the client id caching behavior.
+  private enum ClientIdCaching
+  {
+    ON,
+    OFF,
+    DEBUG
+  }
+
+  private static final ClientIdCaching _CLIENT_ID_CACHING = _initClientIdCaching();
+
+  // System property controlling whether client ID caching is enabled
+  private static final String _SYSTEM_PROP_CLIENT_ID_CACHING =
+    "org.apache.myfaces.trinidad.CLIENT_ID_CACHING";
 
-  // temporary servlet initialization flag controlling whether client ID caching is enabled
-  private static final String _INIT_PROP_CLIENT_ID_CACHING_ENABLED =
-                                      "org.apache.myfaces.trinidadinternal.ENABLE_CLIENT_ID_CACHING";
+  // Application map key indicating that we've already warned once
+  // that the client id caching configuration is not optimized for
+  // production mode.
+  private static final String _WARNED_CLIENT_ID_CACHING_KEY =
+    "org.apache.myfaces.trinidad.WARNED_CLIENT_ID_CACHING";
 
   static private final LifecycleRenderer _UNDEFINED_LIFECYCLE_RENDERER =
                                                 new ExtendedRendererImpl();



Mime
View raw message