You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by me...@apache.org on 2012/09/14 15:34:59 UTC
svn commit: r1384772 - in
/click/trunk/click/framework/src/org/apache/click/util:
ClassLoaderCache.java MessagesMap.java
Author: medgar
Date: Fri Sep 14 13:34:58 2012
New Revision: 1384772
URL: http://svn.apache.org/viewvc?rev=1384772&view=rev
Log:
Fixed shared state bug with JBoss7 when click is deployed as a module
Added:
click/trunk/click/framework/src/org/apache/click/util/ClassLoaderCache.java
Modified:
click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java
Added: click/trunk/click/framework/src/org/apache/click/util/ClassLoaderCache.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/ClassLoaderCache.java?rev=1384772&view=auto
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/ClassLoaderCache.java (added)
+++ click/trunk/click/framework/src/org/apache/click/util/ClassLoaderCache.java Fri Sep 14 13:34:58 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.util;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Provides a classloader object map cache keyed on the current threads
+ * classloader.
+ *
+ * @param <E> the class to cache against the current threads classloader
+ */
+public class ClassLoaderCache<E> {
+
+ // The cache map keyed by classloader
+ private Map<ClassLoader, E> classLoaderMap
+ = Collections.synchronizedMap(new HashMap<ClassLoader, E>());
+
+ /**
+ * Return the cached variable for the current thread classloader.
+ *
+ * @return the cached variable for the current thread classloader.
+ */
+ public E get() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return classLoaderMap.get(cl);
+ }
+
+ /**
+ * Set the cached variable on the current thread classloader.
+ *
+ * @param e the cached variable for the current thread classloader.
+ */
+ public void put(E e) {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ classLoaderMap.put(cl, e);
+ }
+
+ /**
+ * Clear the classloader map cache.
+ */
+ public void clear() {
+ classLoaderMap.clear();
+ }
+
+}
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=1384772&r1=1384771&r2=1384772&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 Fri Sep 14 13:34:58 2012
@@ -69,19 +69,13 @@ import org.apache.commons.lang.Validate;
*/
public class MessagesMap implements 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>>>());
+ /** Cache of resource bundle and locales which were not found, with support for multiple class loaders. */
+ private static final ClassLoaderCache<Set<String>> NOT_FOUND_CLASSLOADER_CACHE
+ = new ClassLoaderCache<Set<String>>();
+
+ /** Provides a synchronized cache of get value reflection methods, with support for multiple class loaders. */
+ protected static final ClassLoaderCache<Map<CacheKey, Map<String, String>>> MESSAGES_CLASSLOADER_CACHE
+ = new ClassLoaderCache<Map<CacheKey, Map<String, String>>>();
/** The cache key set load lock. */
protected static final Object CACHE_LOAD_LOCK = new Object();
@@ -381,24 +375,20 @@ public class MessagesMap implements Map<
// Private Methods --------------------------------------------------------
protected static Set<String> getNotFoundCache() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
-
- Set<String> notFoundCache = NOT_FOUND_CLASSLOADER_CACHE.get(cl);
+ Set<String> notFoundCache = NOT_FOUND_CLASSLOADER_CACHE.get();
if (notFoundCache == null) {
notFoundCache = new HashSet<String>();
- NOT_FOUND_CLASSLOADER_CACHE.put(cl, notFoundCache);
+ NOT_FOUND_CLASSLOADER_CACHE.put(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);
+ Map<CacheKey, Map<String, String>> messagesCache = MESSAGES_CLASSLOADER_CACHE.get();
if (messagesCache == null) {
messagesCache = new ConcurrentHashMap<CacheKey, Map<String, String>>();
- MESSAGES_CLASSLOADER_CACHE.put(cl, messagesCache);
+ MESSAGES_CLASSLOADER_CACHE.put(messagesCache);
}
return messagesCache;