Package com.thoughtworks.paranamer
Class CachingParanamer
- java.lang.Object
-
- com.thoughtworks.paranamer.CachingParanamer
-
- All Implemented Interfaces:
Paranamer
- Direct Known Subclasses:
CachingParanamer.WithoutWeakReferences
public class CachingParanamer extends java.lang.Object implements Paranamer
Implementation of Paranamer which delegate to another Paranamer implementation, adding caching functionality to speed up usage. It also uses a WeakHashmap as an implementation detail (wrapped in Collections.synchronizedMap(..)), to allow large usages to garbage collect things as big as whole classloaders (after working through all the refs that originated from that classloader). Tomcat and other 'containers' do this during hot application deployment, undeployment and most importantly for Paranamer redeployment. Basically, this will allow a perm-gen usage keeps growing scenario.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CachingParanamer.WithoutWeakReferences
This implementation has a better concurrent design (ConcurrentHashMap) which has a better strategy to implement concurrency: segments instead of synchronized.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
__PARANAMER_DATA
private Paranamer
delegate
private java.util.Map<java.lang.reflect.AccessibleObject,java.lang.String[]>
methodCache
-
Fields inherited from interface com.thoughtworks.paranamer.Paranamer
EMPTY_NAMES
-
-
Constructor Summary
Constructors Constructor Description CachingParanamer()
Uses a DefaultParanamer as the implementation it delegates to.CachingParanamer(Paranamer delegate)
Specify a Paranamer instance to delegates to.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]
lookupParameterNames(java.lang.reflect.AccessibleObject methodOrConstructor)
Lookup the parameter names of a given method.java.lang.String[]
lookupParameterNames(java.lang.reflect.AccessibleObject methodOrCtor, boolean throwExceptionIfMissing)
Lookup the parameter names of a given method.protected java.util.Map<java.lang.reflect.AccessibleObject,java.lang.String[]>
makeMethodCache()
-
-
-
Field Detail
-
__PARANAMER_DATA
public static final java.lang.String __PARANAMER_DATA
- See Also:
- Constant Field Values
-
delegate
private final Paranamer delegate
-
methodCache
private final java.util.Map<java.lang.reflect.AccessibleObject,java.lang.String[]> methodCache
-
-
Constructor Detail
-
CachingParanamer
public CachingParanamer()
Uses a DefaultParanamer as the implementation it delegates to.
-
CachingParanamer
public CachingParanamer(Paranamer delegate)
Specify a Paranamer instance to delegates to.- Parameters:
delegate
- the paranamer instance to use
-
-
Method Detail
-
makeMethodCache
protected java.util.Map<java.lang.reflect.AccessibleObject,java.lang.String[]> makeMethodCache()
-
lookupParameterNames
public java.lang.String[] lookupParameterNames(java.lang.reflect.AccessibleObject methodOrConstructor)
Description copied from interface:Paranamer
Lookup the parameter names of a given method.- Specified by:
lookupParameterNames
in interfaceParanamer
- Parameters:
methodOrConstructor
- theMethod
orConstructor
for which the parameter names are looked up.- Returns:
- A list of the parameter names.
-
lookupParameterNames
public java.lang.String[] lookupParameterNames(java.lang.reflect.AccessibleObject methodOrCtor, boolean throwExceptionIfMissing)
Description copied from interface:Paranamer
Lookup the parameter names of a given method.- Specified by:
lookupParameterNames
in interfaceParanamer
- Parameters:
methodOrCtor
- theMethod
orConstructor
for which the parameter names are looked up.throwExceptionIfMissing
- whether to throw an exception if no Paranamer data found (versus return null).- Returns:
- A list of the parameter names.
-
-