struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1201770 - /struts/struts2/branches/new_conversion/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
Date Mon, 14 Nov 2011 16:12:56 GMT
Author: lukaszlenart
Date: Mon Nov 14 16:12:55 2011
New Revision: 1201770

URL: http://svn.apache.org/viewvc?rev=1201770&view=rev
Log:
WW-3702 - adds optional flag to enable/disable internal cache to prevent memory leaks

Modified:
    struts/struts2/branches/new_conversion/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java

Modified: struts/struts2/branches/new_conversion/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/new_conversion/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java?rev=1201770&r1=1201769&r2=1201770&view=diff
==============================================================================
--- struts/struts2/branches/new_conversion/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
(original)
+++ struts/struts2/branches/new_conversion/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
Mon Nov 14 16:12:55 2011
@@ -20,6 +20,7 @@
 package org.apache.struts2.cdi;
 
 import com.opensymphony.xwork2.ObjectFactory;
+import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.util.logging.Logger;
 import com.opensymphony.xwork2.util.logging.LoggerFactory;
 
@@ -54,6 +55,8 @@ public class CdiObjectFactory extends Ob
 
     Map<Class<?>, InjectionTarget<?>> injectionTargetCache = new ConcurrentHashMap<Class<?>,
InjectionTarget<?>>();
 
+    private boolean useInternalCache = false;
+
     public CdiObjectFactory() {
         super();
         LOG.info("Initializing Struts2 CDI integration...");
@@ -119,11 +122,15 @@ public class CdiObjectFactory extends Ob
      * @return if found in cache, an existing instance. A new instance otherwise.
      */
     protected InjectionTarget<?> getInjectionTarget(Class<?> clazz) {
-        InjectionTarget<?> result;
-        result = injectionTargetCache.get(clazz);
+        InjectionTarget<?> result = null;
+        if (useInternalCache) {
+            result = injectionTargetCache.get(clazz);
+        }
         if (result == null) {
             result = beanManager.createInjectionTarget(beanManager.createAnnotatedType(clazz));
-            injectionTargetCache.put(clazz, result);
+            if (useInternalCache) {
+                injectionTargetCache.put(clazz, result);
+            }
         }
 
         return result;
@@ -139,4 +146,15 @@ public class CdiObjectFactory extends Ob
     protected CreationalContext buildNonContextualCreationalContext(BeanManager beanManager)
{
         return beanManager != null ? beanManager.createCreationalContext(null) : null;
     }
+
+    /**
+     * Disables use of internal cache for InjectionTargets
+     *
+     * @param useInternalCache
+     */
+    @Inject(value = "struts.cdi.useInternalCache", required = false)
+    public void setUseInternalCache(String useInternalCache) {
+        this.useInternalCache = "true".equalsIgnoreCase(useInternalCache);
+    }
+
 }



Mime
View raw message