Package org.apache.hadoop.util.dynamic
Class BindingUtils
java.lang.Object
org.apache.hadoop.util.dynamic.BindingUtils
Utility methods to assist binding to Hadoop APIs through reflection.
Source:
org.apache.parquet.hadoop.util.wrapped.io.BindingUtils.-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanavailable(DynMethods.UnboundMethod method) Is a method available?static voidRequire a method to be available.static <T> TextractIOEs(Supplier<T> call) Invoke the supplier, catching anyUncheckedIOExceptionraised, extracting the inner IOException and rethrowing it.static booleanimplemented(DynMethods.UnboundMethod... methods) Given a sequence of methods, verify that they are all available.static Class<?>loadClass(ClassLoader cl, String className) Load a class by name.static Class<?>Load a class by name.static Class<?>loadClassSafely(String className) Load a class by name.static <T> DynMethods.UnboundMethodloadInvocation(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.static <T> DynMethods.UnboundMethodloadStaticMethod(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.static DynMethods.UnboundMethodCreate a no-op method.
-
Method Details
-
loadClass
Load a class by name.- Parameters:
className- classname- Returns:
- the class or null if it could not be loaded.
-
loadClassSafely
Load a class by name.- Parameters:
className- classname- Returns:
- the class.
- Throws:
RuntimeException- if the class was not found.
-
loadClass
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 nameparameterTypes- 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 anIllegalStateExceptionis 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 nameparameterTypes- parameters- Returns:
- the method or a no-op.
- Throws:
IllegalStateException- if the method is not static.
-
noop
Create a no-op method.- Parameters:
name- method name- Returns:
- a no-op method.
-
implemented
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
Is a method available?- Parameters:
method- method to probe- Returns:
- true iff the method is found and loaded.
-
extractIOEs
Invoke the supplier, catching anyUncheckedIOExceptionraised, 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.
-