Author: tv
Date: Wed Aug 1 20:25:58 2018
New Revision: 1837257
URL: http://svn.apache.org/viewvc?rev=1837257&view=rev
Log:
Remove dependency on commons-collections
Modified:
turbine/core/trunk/src/java/org/apache/turbine/modules/ActionEvent.java
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java
Modified:
turbine/core/trunk/src/java/org/apache/turbine/modules/ActionEvent.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/ActionEvent.java?rev=1837257&r1=1837256&r2=1837257&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/ActionEvent.java
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/ActionEvent.java Wed
Aug 1 20:25:58 2018
@@ -20,13 +20,12 @@ package org.apache.turbine.modules;
*/
import java.lang.annotation.Annotation;
-
-
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
-import org.apache.commons.collections.map.MultiKeyMap;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -120,7 +119,7 @@ public abstract class ActionEvent extend
/**
* Cache for the methods to invoke
*/
- private MultiKeyMap/* <String, Method> */ methodCache = new
MultiKeyMap/* <String, Method> */();
+ private ConcurrentMap<String, Method> methodCache = new
ConcurrentHashMap<String, Method>();
/**
* Retrieve a method of the given name and signature. The value is
cached.
@@ -134,7 +133,13 @@ public abstract class ActionEvent extend
*/
protected Method getMethod(String name, Class<?>[] signature,
ParameterParser pp) throws NoSuchMethodException
{
- Method method = (Method) this.methodCache.get(name, signature);
+ StringBuilder cacheKey = new StringBuilder(name);
+ for (Class<?> clazz : signature)
+ {
+ cacheKey.append(':').append(clazz.getCanonicalName());
+ }
+
+ Method method = this.methodCache.get(cacheKey.toString());
if (method == null)
{
@@ -167,7 +172,11 @@ public abstract class ActionEvent extend
method = getClass().getMethod(METHOD_NAME_PREFIX +
StringUtils.capitalize(tmp), signature);
}
- this.methodCache.put(name, signature, method);
+ Method oldMethod =
this.methodCache.putIfAbsent(cacheKey.toString(), method);
+ if (oldMethod != null)
+ {
+ method = oldMethod;
+ }
}
return method;
Modified:
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java?rev=1837257&r1=1837256&r2=1837257&view=diff
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java
(original)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java
Wed Aug 1 20:25:58 2018
@@ -26,9 +26,10 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
-import org.apache.commons.collections.map.LRUMap;
-import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration2.Configuration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.turbine.Turbine;
@@ -63,10 +64,10 @@ public class TurbineAssemblerBrokerServi
private Map<Class<?>, List<?>> factories = null;
/** A cache that holds the generated Assemblers */
- private Map<String, Assembler> assemblerCache = null;
+ private ConcurrentMap<String, Assembler> assemblerCache = null;
/** A cache that holds the Loaders */
- private Map<Class<?>, Loader<? extends Assembler>> loaderCache = null;
+ private ConcurrentMap<Class<?>, Loader<? extends Assembler>> loaderCache =
null;
/** Caching on/off */
private boolean isCaching;
@@ -114,11 +115,7 @@ public class TurbineAssemblerBrokerServi
registerFactory(af);
}
// these must be passed to the VM
- catch (ThreadDeath e)
- {
- throw e;
- }
- catch (OutOfMemoryError e)
+ catch (ThreadDeath | OutOfMemoryError e)
{
throw e;
}
@@ -138,7 +135,6 @@ public class TurbineAssemblerBrokerServi
*
* @throws InitializationException if problems occur while registering the
factories
*/
- @SuppressWarnings("unchecked") // as long as commons-collections does not
use generics
@Override
public void init()
throws InitializationException
@@ -175,8 +171,8 @@ public class TurbineAssemblerBrokerServi
.getInt(TurbineConstants.MODULE_CACHE_SIZE_KEY,
TurbineConstants.MODULE_CACHE_SIZE_DEFAULT);
- assemblerCache = new LRUMap(cacheSize);
- loaderCache = new LRUMap(cacheSize);
+ assemblerCache = new ConcurrentHashMap<String,
Assembler>(cacheSize);
+ loaderCache = new ConcurrentHashMap<Class<?>, Loader<? extends
Assembler>>(cacheSize);
}
setInit(true);
@@ -221,11 +217,17 @@ public class TurbineAssemblerBrokerServi
if (isCaching && assemblerCache.containsKey(key))
{
assembler = (T) assemblerCache.get(key);
- log.debug("Found " + key + " in the cache!");
+ if (log.isDebugEnabled())
+ {
+ log.debug("Found " + key + " in the cache!");
+ }
}
else
{
- log.debug("Loading " + key);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Loading " + key);
+ }
List<AssemblerFactory<T>> facs = getFactoryGroup(type);
for (Iterator<AssemblerFactory<T>> it = facs.iterator();
(assembler == null) && it.hasNext();)
@@ -250,7 +252,11 @@ public class TurbineAssemblerBrokerServi
if (isCaching)
{
- assemblerCache.put(key, assembler);
+ T oldAssembler = (T) assemblerCache.putIfAbsent(key,
assembler);
+ if (oldAssembler != null)
+ {
+ assembler = oldAssembler;
+ }
}
}
}