click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From med...@apache.org
Subject svn commit: r1310984 - in /click/trunk/click: documentation/docs/roadmap-changes.html framework/src/org/apache/click/util/MessagesMap.java framework/src/org/apache/click/util/PropertyUtils.java framework/test/org/apache/click/util/MessagesMapTest.java
Date Sun, 08 Apr 2012 12:18:26 GMT
Author: medgar
Date: Sun Apr  8 12:18:26 2012
New Revision: 1310984

URL: http://svn.apache.org/viewvc?rev=1310984&view=rev
Log:
CLK-788

Modified:
    click/trunk/click/documentation/docs/roadmap-changes.html
    click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java
    click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java
    click/trunk/click/framework/test/org/apache/click/util/MessagesMapTest.java

Modified: click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/roadmap-changes.html?rev=1310984&r1=1310983&r2=1310984&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ click/trunk/click/documentation/docs/roadmap-changes.html Sun Apr  8 12:18:26 2012
@@ -100,6 +100,10 @@
               Added URL request params options to the PageSubmit class
           [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-779">CLK-779</a>].
           </li>
+   		  <li>
+			  Added support using Click as a JBoss 7 module
+		  [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-788">CLK-788</a>].
+   		  </li>
           <li class="change">
               Removed AutoCompleteTextField dependency on Page. The Ajax callback
               URL is instead looked up from the request itself. This change removes

Modified: click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java?rev=1310984&r1=1310983&r2=1310984&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java Sun Apr  8 12:18:26
2012
@@ -31,12 +31,13 @@ import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.servlet.ServletContext;
-import org.apache.commons.lang.Validate;
 
 import org.apache.click.Context;
 import org.apache.click.service.ConfigService;
+import org.apache.commons.lang.Validate;
 
 /**
  * Provides a localized read only messages Map for Page and Control classes.
@@ -68,13 +69,19 @@ import org.apache.click.service.ConfigSe
  */
 public class MessagesMap implements Map<String, String> {
 
-    /** Cache of resource bundle and locales which were not found. */
-    protected static final Set<String> NOT_FOUND_CACHE =
-        Collections.synchronizedSet(new HashSet<String>());
-
-    /** Cache of messages keyed by bundleName + Locale name. */
-    protected static final Map<Object, Map<String, String>> MESSAGES_CACHE =
-        new HashMap<Object, Map<String, String>>();
+    /**
+     * Cache of resource bundle and locales which were not found, with support
+     * for multiple class loaders.
+     */
+    protected static final Map<ClassLoader, Set<String>> NOT_FOUND_CLASSLOADER_CACHE
+        = Collections.synchronizedMap(new HashMap<ClassLoader, Set<String>>());
+
+    /**
+     * Provides a synchronized cache of get value reflection methods, with
+     * support for multiple class loaders.
+     */
+    protected static final Map<ClassLoader, Map<CacheKey, Map<String, String>>>
MESSAGES_CLASSLOADER_CACHE
+        = Collections.synchronizedMap(new HashMap<ClassLoader, Map<CacheKey, Map<String,
String>>>());
 
     /** The cache key set load lock. */
     protected static final Object CACHE_LOAD_LOCK = new Object();
@@ -302,7 +309,7 @@ public class MessagesMap implements Map<
             CacheKey resourceKey = new CacheKey(globalBaseName,
                 baseClass.getName(), locale.toString());
 
-            messages = MESSAGES_CACHE.get(resourceKey);
+            messages = getMessagesCache().get(resourceKey);
 
             if (messages != null) {
                 return;
@@ -335,7 +342,7 @@ public class MessagesMap implements Map<
                 ServletContext servletContext = Context.getThreadLocalContext().getServletContext();
                 ConfigService configService = ClickUtils.getConfigService(servletContext);
                 if (configService.isProductionMode() || configService.isProfileMode()) {
-                    MESSAGES_CACHE.put(resourceKey, messages);
+                    getMessagesCache().put(resourceKey, messages);
                 }
             }
         }
@@ -354,7 +361,7 @@ public class MessagesMap implements Map<
 
         String resourceKey = resourceBundleName + locale.toString();
 
-        if (!NOT_FOUND_CACHE.contains(resourceKey)) {
+        if (!getNotFoundCache().contains(resourceKey)) {
             try {
                 ResourceBundle resources = createResourceBundle(resourceBundleName, locale);
 
@@ -366,13 +373,37 @@ public class MessagesMap implements Map<
                 }
 
             } catch (MissingResourceException mre) {
-                NOT_FOUND_CACHE.add(resourceKey);
+                getNotFoundCache().add(resourceKey);
             }
         }
     }
 
     // Private Methods --------------------------------------------------------
 
+    protected static Set<String> getNotFoundCache() {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+        Set<String> notFoundCache = NOT_FOUND_CLASSLOADER_CACHE.get(cl);
+        if (notFoundCache == null) {
+            notFoundCache = new HashSet<String>();
+            NOT_FOUND_CLASSLOADER_CACHE.put(cl, notFoundCache);
+        }
+
+        return notFoundCache;
+    }
+
+    protected static Map<CacheKey, Map<String, String>> getMessagesCache() {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+        Map<CacheKey, Map<String, String>> messagesCache = MESSAGES_CLASSLOADER_CACHE.get(cl);
+        if (messagesCache == null) {
+            messagesCache = new ConcurrentHashMap<CacheKey, Map<String, String>>();
+            MESSAGES_CLASSLOADER_CACHE.put(cl, messagesCache);
+        }
+
+        return messagesCache;
+    }
+
     /**
      * See DRY Performance article by Kirk Pepperdine.
      * <p/>

Modified: click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java?rev=1310984&r1=1310983&r2=1310984&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java Sun Apr  8 12:18:26
2012
@@ -19,6 +19,8 @@
 package org.apache.click.util;
 
 import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -39,6 +41,13 @@ public class PropertyUtils {
     private static final Map<String, Object> GET_METHOD_CACHE
         = new ConcurrentHashMap<String, Object>();
 
+    /**
+     * Provides a synchronized cache of get value reflection methods, with
+     * support for multiple class loaders.
+     */
+    private static final Map<ClassLoader, Map<CacheKey, Method>> GET_METHOD_CLASSLOADER_CACHE
+        = Collections.synchronizedMap(new HashMap<ClassLoader, Map<CacheKey, Method>>());
+
     // -------------------------------------------------------- Public Methods
 
     /**
@@ -69,13 +78,13 @@ public class PropertyUtils {
             remainingPart = name.substring(baseIndex + 1);
         }
 
-        Object value = getObjectPropertyValue(source, basePart, GET_METHOD_CACHE);
+        Object value = getObjectPropertyValue(source, basePart, getGetMethodCache());
 
         if (remainingPart == null || value == null) {
             return value;
 
         } else {
-            return getValue(value, remainingPart, GET_METHOD_CACHE);
+            return getValue(value, remainingPart, getGetMethodCache());
         }
     }
 
@@ -206,6 +215,18 @@ public class PropertyUtils {
         return configService.getPropertyService();
     }
 
+    private static Map<CacheKey, Method> getGetMethodCache() {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+        Map<CacheKey, Method> getMethodCache = GET_METHOD_CLASSLOADER_CACHE.get(cl);
+        if (getMethodCache == null) {
+            getMethodCache = new ConcurrentHashMap<CacheKey, Method>();
+            GET_METHOD_CLASSLOADER_CACHE.put(cl, getMethodCache);
+        }
+
+        return getMethodCache;
+    }
+
     // Inner Classes ----------------------------------------------------------
 
     /**

Modified: click/trunk/click/framework/test/org/apache/click/util/MessagesMapTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/util/MessagesMapTest.java?rev=1310984&r1=1310983&r2=1310984&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/util/MessagesMapTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/util/MessagesMapTest.java Sun Apr  8
12:18:26 2012
@@ -252,7 +252,7 @@ public class MessagesMapTest extends Tes
         }
 
         public void clearCache() {
-            MESSAGES_CACHE.clear();
+        	MESSAGES_CLASSLOADER_CACHE.clear();
             clearResourceBundleCache();
         }
 



Mime
View raw message