Class BindingUtils

java.lang.Object
org.apache.hadoop.util.dynamic.BindingUtils

@LimitedPrivate("testing") @Unstable public final class BindingUtils extends Object
Utility methods to assist binding to Hadoop APIs through reflection. Source: org.apache.parquet.hadoop.util.wrapped.io.BindingUtils.
  • Method Details

    • loadClass

      public static Class<?> loadClass(String className)
      Load a class by name.
      Parameters:
      className - classname
      Returns:
      the class or null if it could not be loaded.
    • loadClassSafely

      public static Class<?> loadClassSafely(String className)
      Load a class by name.
      Parameters:
      className - classname
      Returns:
      the class.
      Throws:
      RuntimeException - if the class was not found.
    • loadClass

      public static Class<?> loadClass(ClassLoader cl, String className)
      Load a class by name.
      Parameters:
      cl - classloader to use.
      className - classname
      Returns:
      the class or null if it could not be loaded.
    • loadInvocation

      public static <T> DynMethods.UnboundMethod loadInvocation(Class<?> source, Class<? extends T> returnType, String name, Class<?>... parameterTypes)
      Get an invocation from the source class, which will be unavailable() if the class is null or the method isn't found.
      Type Parameters:
      T - return type
      Parameters:
      source - source. If null, the method is a no-op.
      returnType - return type class (unused)
      name - method name
      parameterTypes - parameters
      Returns:
      the method or "unavailable"
    • loadStaticMethod

      public static <T> DynMethods.UnboundMethod loadStaticMethod(Class<?> source, Class<? extends T> returnType, String name, Class<?>... parameterTypes)
      Load a static method from the source class, which will be a noop() if the class is null or the method isn't found. If the class and method are not found, then an IllegalStateException is raised on the basis that this means that the binding class is broken, rather than missing/out of date.
      Type Parameters:
      T - return type
      Parameters:
      source - source. If null, the method is a no-op.
      returnType - return type class (unused)
      name - method name
      parameterTypes - parameters
      Returns:
      the method or a no-op.
      Throws:
      IllegalStateException - if the method is not static.
    • noop

      public static DynMethods.UnboundMethod noop(String name)
      Create a no-op method.
      Parameters:
      name - method name
      Returns:
      a no-op method.
    • implemented

      public static boolean implemented(DynMethods.UnboundMethod... methods)
      Given a sequence of methods, verify that they are all available.
      Parameters:
      methods - methods
      Returns:
      true if they are all implemented
    • checkAvailable

      public static void checkAvailable(DynMethods.UnboundMethod method) throws UnsupportedOperationException
      Require a method to be available.
      Parameters:
      method - method to probe
      Throws:
      UnsupportedOperationException - if the method was not found.
    • available

      public static boolean available(DynMethods.UnboundMethod method)
      Is a method available?
      Parameters:
      method - method to probe
      Returns:
      true iff the method is found and loaded.
    • extractIOEs

      public static <T> T extractIOEs(Supplier<T> call) throws IOException
      Invoke the supplier, catching any UncheckedIOException raised, extracting the inner IOException and rethrowing it.
      Type Parameters:
      T - type of result
      Parameters:
      call - call to invoke
      Returns:
      result
      Throws:
      IOException - if the call raised an IOException wrapped by an UncheckedIOException.