Package org.apache.hadoop.hbase.util
Class ReflectionUtils
java.lang.Object
org.apache.hadoop.hbase.util.ReflectionUtils
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Constructor<T>
findConstructor
(Class<T> type, Object... paramTypes) static ClassLoader
static Field
static <I,
R> Function<I, R> getOneArgStaticMethodAsFunction
(Class<?> lookupClazz, String methodName, Class<I> argumentClazz, Class<R> returnValueClass) Creates a Function which can be called to performantly execute a reflected static method.private static Class<?>[]
getParameterTypes
(Object[] params) private static String
getTaskName
(long id, String name) static <T> T
instantiate
(String className, Constructor<T> ctor, Object... ctorArgs) static <T> T
instantiateWithCustomCtor
(String className, Class<?>[] ctorArgTypes, Object[] ctorArgs) static Object
invokeMethod
(Object obj, String methodName, Object... params) Get and invoke the target method from the given object with given parametersstatic void
logThreadInfo
(org.slf4j.Logger log, String title, long minInterval) Log the current thread stacks at INFO level.static <T> T
newInstance
(Class<T> type, Object... params) static <T> T
newInstance
(String className, Object... params) (package private) static void
printThreadInfo
(PrintStream stream, String title) Print all of the thread's information and stack traces.
-
Field Details
-
previousLogTime
-
threadBean
-
-
Constructor Details
-
ReflectionUtils
public ReflectionUtils()
-
-
Method Details
-
instantiateWithCustomCtor
public static <T> T instantiateWithCustomCtor(String className, Class<?>[] ctorArgTypes, Object[] ctorArgs) -
instantiate
-
newInstance
-
getClassLoader
-
newInstance
-
findConstructor
-
logThreadInfo
Log the current thread stacks at INFO level.- Parameters:
log
- the logger that logs the stack tracetitle
- a descriptive title for the call stacksminInterval
- the minimum time from the last
-
printThreadInfo
Print all of the thread's information and stack traces.- Parameters:
stream
- the stream totitle
- a string title for the stack trace
-
getTaskName
-
getOneArgStaticMethodAsFunction
public static <I,R> Function<I,R> getOneArgStaticMethodAsFunction(Class<?> lookupClazz, String methodName, Class<I> argumentClazz, Class<R> returnValueClass) throws Throwable Creates a Function which can be called to performantly execute a reflected static method. The creation of the Function itself may not be fast, but executing that method thereafter should be much faster thaninvokeMethod(Object, String, Object...)
.- Parameters:
lookupClazz
- the class to find the static method inmethodName
- the method nameargumentClazz
- the type of the argumentreturnValueClass
- the type of the return value- Returns:
- a function which when called executes the requested static method.
- Throws:
Throwable
- exception types from the underlying reflection
-
invokeMethod
Get and invoke the target method from the given object with given parameters- Parameters:
obj
- the object to get and invoke method frommethodName
- the name of the method to invokeparams
- the parameters for the method to invoke- Returns:
- the return value of the method invocation
-
getParameterTypes
-
getModifiersField
-