commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pro...@apache.org
Subject svn commit: r227285 - in /jakarta/commons/proper/jelly/trunk: src/java/org/apache/commons/jelly/JellyContext.java src/java/org/apache/commons/jelly/impl/TagScript.java src/test/org/apache/commons/jelly/core/BaseMemoryLeakTest.java xdocs/changes.xml
Date Thu, 04 Aug 2005 01:26:26 GMT
Author: proyal
Date: Wed Aug  3 18:26:19 2005
New Revision: 227285

URL: http://svn.apache.org/viewcvs?rev=227285&view=rev
Log:
Restore JellyContext.isCacheTags to fix regression

Modified:
    jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/JellyContext.java
    jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/impl/TagScript.java
    jakarta/commons/proper/jelly/trunk/src/test/org/apache/commons/jelly/core/BaseMemoryLeakTest.java
    jakarta/commons/proper/jelly/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/JellyContext.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/JellyContext.java?rev=227285&r1=227284&r2=227285&view=diff
==============================================================================
--- jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/JellyContext.java
(original)
+++ jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/JellyContext.java
Wed Aug  3 18:26:19 2005
@@ -20,17 +20,15 @@
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.WeakHashMap;
 
 import org.apache.commons.jelly.parser.XMLParser;
 import org.apache.commons.jelly.util.ClassLoaderUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
@@ -92,6 +90,9 @@
     /** Should we export tag libraries to our parents context */
     private boolean exportLibraries = true;
 
+    /** Should we cache Tag instances, per thread, to reduce object contruction overhead?
*/
+    private boolean cacheTags = false;
+
     /**
      * Create a new context with the currentURL set to the rootURL
      */
@@ -132,6 +133,7 @@
         this.rootURL = parent.rootURL;
         this.currentURL = parent.currentURL;
         this.variables.put("parentScope", parent.variables);
+        this.cacheTags = parent.cacheTags;
         init();
     }
 
@@ -799,6 +801,30 @@
      */
     public void setCurrentURL(URL currentURL) {
         this.currentURL = currentURL;
+    }
+
+    /**
+     * Returns whether caching of Tag instances, per thread, is enabled.
+     * Caching Tags can boost performance, on some JVMs, by reducing the cost of
+     * object construction when running Jelly inside a multi-threaded application server
+     * such as a Servlet engine.
+     *
+     * @return whether caching of Tag instances is enabled.
+     */
+    public boolean isCacheTags() {
+        return cacheTags;
+    }
+
+    /**
+     * Sets whether caching of Tag instances, per thread, is enabled.
+     * Caching Tags can boost performance, on some JVMs, by reducing the cost of
+     * object construction when running Jelly inside a multi-threaded application server
+     * such as a Servlet engine.
+     *
+     * @param cacheTags Whether caching should be enabled or disabled.
+     */
+    public void setCacheTags(boolean cacheTags) {
+        this.cacheTags = cacheTags;
     }
 
     /**

Modified: jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/impl/TagScript.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/impl/TagScript.java?rev=227285&r1=227284&r2=227285&view=diff
==============================================================================
--- jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/impl/TagScript.java
(original)
+++ jakarta/commons/proper/jelly/trunk/src/java/org/apache/commons/jelly/impl/TagScript.java
Wed Aug  3 18:26:19 2005
@@ -203,6 +203,9 @@
     public void run(JellyContext context, XMLOutput output) throws JellyTagException {
         URL rootURL = context.getRootURL();
         URL currentURL = context.getCurrentURL();
+        if ( ! context.isCacheTags() ) {
+            clearTag();
+        }
         try {
             Tag tag = getTag(context);
             if ( tag == null ) {
@@ -527,6 +530,13 @@
         }
     }
 
+    /**
+     * Flushes the current cached tag so that it will be created, lazily, next invocation
+     */
+    protected void clearTag() {
+        Thread t = Thread.currentThread();
+        threadLocalTagCache.put(t,null);
+    }
 
     /**
      * Allows the script to set the tag instance to be used, such as in a StaticTagScript

Modified: jakarta/commons/proper/jelly/trunk/src/test/org/apache/commons/jelly/core/BaseMemoryLeakTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/trunk/src/test/org/apache/commons/jelly/core/BaseMemoryLeakTest.java?rev=227285&r1=227284&r2=227285&view=diff
==============================================================================
--- jakarta/commons/proper/jelly/trunk/src/test/org/apache/commons/jelly/core/BaseMemoryLeakTest.java
(original)
+++ jakarta/commons/proper/jelly/trunk/src/test/org/apache/commons/jelly/core/BaseMemoryLeakTest.java
Wed Aug  3 18:26:19 2005
@@ -41,7 +41,7 @@
  * @author Hans Gilde
  *  
  */
-public class BaseMemoryLeakTest extends TestCase {
+public abstract class BaseMemoryLeakTest extends TestCase {
     private final static Log log = LogFactory.getLog(BaseMemoryLeakTest.class);
 
     /**

Modified: jakarta/commons/proper/jelly/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/trunk/xdocs/changes.xml?rev=227285&r1=227284&r2=227285&view=diff
==============================================================================
--- jakarta/commons/proper/jelly/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/jelly/trunk/xdocs/changes.xml Wed Aug  3 18:26:19 2005
@@ -24,6 +24,9 @@
     <author email="dion@apache.org">dIon Gillard</author>
   </properties>
   <body>
+    <release version="1.1-dev">
+      <action dev="proyal" type="fix">Restored JellyContext.isCacheTags and its behavior
for backwards compatibility</action>
+    </release>
     <release version="1.0" date="2005-06-12">
       <action dev="brett" type="fix" due-to="Hans Gilde">Improve tag caching to improve
memory consumption</action>
       <action dev="dion" type="fix" issue="JELLY-196">SwitchTag can not be reused if
default encountered.</action>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message