Package org.apache.hadoop.hbase.util
Class ReflectedFunctionCache<I,R>
java.lang.Object
org.apache.hadoop.hbase.util.ReflectedFunctionCache<I,R>
- Type Parameters:
I
- the input argument type for the resolved functionsR
- the return type for the resolved functions
Cache to hold resolved Functions of a specific signature, generated through reflection. These can
be (relatively) costly to create, but then are much faster than typical Method.invoke calls when
executing. The cache is built-up on demand as calls are made to new classes. The functions are
cached for the lifetime of the process. If a function cannot be created (security reasons, method
not found, etc), a fallback function is cached which always returns null. Callers to
getAndCallByName(String, Object)
should have handling for null return values.
An instance is created for a specified baseClass (i.e. Filter), argClass (i.e. byte[]), and static methodName to call. These are used to resolve a Function which delegates to that static method, if it is found.
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ClassLoader
private final ConcurrentMap<String,
Function<I, ? extends R>> private static final org.slf4j.Logger
private final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetAndCallByName
(String className, I argument) Get and execute the Function for the given className, passing the argument to the function and returning the result.loadFunction
(String className) private R
In order to use computeIfAbsent, we can't store nulls in our cache.
-
Field Details
-
LOG
-
lambdasByClass
-
baseClass
-
argClass
-
methodName
-
classLoader
-
-
Constructor Details
-
ReflectedFunctionCache
-
-
Method Details
-
getAndCallByName
Get and execute the Function for the given className, passing the argument to the function and returning the result.- Parameters:
className
- the full name of the class to lookupargument
- the argument to pass to the function, if found.- Returns:
- null if a function is not found for classname, otherwise the result of the function.
-
loadFunction
-
notFound
In order to use computeIfAbsent, we can't store nulls in our cache. So we store a lambda which resolves to null. The contract is that getAndCallByName returns null in this case.
-