mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-19 17:56:41 +10:00
[강운덕] [LUCYSUS-1744] mysql byte code수정 기능 추가.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@599 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package com.profiler.util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MetaObject {
|
||||
|
||||
private final Logger logger = Logger.getLogger(MetaObject.class.getName());
|
||||
|
||||
private String methodName;
|
||||
private Class[] args;
|
||||
// 이것을 class loading시 정적 타임에서 생성해 둘수 없는가?
|
||||
private Method methodRef;
|
||||
|
||||
private Object defaultReturnValue = null;
|
||||
|
||||
public MetaObject(String methodName, Class... args) {
|
||||
this.methodName = methodName;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public MetaObject(Object defaultReturnValue, String methodName, Class... args) {
|
||||
this.methodName = methodName;
|
||||
this.args = args;
|
||||
this.defaultReturnValue = defaultReturnValue;
|
||||
}
|
||||
|
||||
public Object invoke(Object target, Object... args) {
|
||||
if (target == null) {
|
||||
return defaultReturnValue;
|
||||
}
|
||||
|
||||
Method method = this.methodRef;
|
||||
if (method == null) {
|
||||
// 멀티쓰레드에서 중복 엑세스해도 별 문제 없을것임.
|
||||
Class aClass = target.getClass();
|
||||
method = getMethod(aClass);
|
||||
this.methodRef = method;
|
||||
}
|
||||
return invoke(method, target, args);
|
||||
}
|
||||
|
||||
private Object invoke(Method method, Object target, Object[] args) {
|
||||
if (method == null) {
|
||||
return defaultReturnValue;
|
||||
}
|
||||
try {
|
||||
return method.invoke(target, args);
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.log(Level.WARNING, "invoke fail", e);
|
||||
return defaultReturnValue;
|
||||
} catch (InvocationTargetException e) {
|
||||
logger.log(Level.WARNING, "invoke fail", e);
|
||||
return defaultReturnValue;
|
||||
}
|
||||
}
|
||||
|
||||
private Method getMethod(Class aClass) {
|
||||
try {
|
||||
return aClass.getDeclaredMethod(this.methodName, this.args);
|
||||
} catch (NoSuchMethodException e) {
|
||||
logger.warning(this.methodName + Arrays.toString(this.args) + " not found cls:" + aClass);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user