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 functions
R - the return type for the resolved functions

@Private public final class ReflectedFunctionCache<I,R> extends Object
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 Details

  • Constructor Details

  • Method Details

    • getAndCallByName

      @Nullable public R getAndCallByName(String className, I argument)
      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 lookup
      argument - 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

      private Function<I,? extends R> loadFunction(String className)
    • notFound

      private R notFound(I argument)
      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.