Remove the field binders.
This commit is contained in:
parent
5bcc6fbf5c
commit
9037f13976
|
|
@ -104,9 +104,6 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
||||||
for (ConstructorInterceptPoint constructorInterceptPoint : constructorInterceptPoints) {
|
for (ConstructorInterceptPoint constructorInterceptPoint : constructorInterceptPoints) {
|
||||||
newClassBuilder = newClassBuilder.constructor(ElementMatchers.<MethodDescription>any()).intercept(SuperMethodCall.INSTANCE
|
newClassBuilder = newClassBuilder.constructor(ElementMatchers.<MethodDescription>any()).intercept(SuperMethodCall.INSTANCE
|
||||||
.andThen(MethodDelegation.withDefaultConfiguration()
|
.andThen(MethodDelegation.withDefaultConfiguration()
|
||||||
.withBinders(
|
|
||||||
FieldProxy.Binder.install(FieldGetter.class, FieldSetter.class)
|
|
||||||
)
|
|
||||||
.to(new ConstructorInter(constructorInterceptPoint.getConstructorInterceptor()))
|
.to(new ConstructorInter(constructorInterceptPoint.getConstructorInterceptor()))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -129,7 +126,6 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
||||||
.intercept(
|
.intercept(
|
||||||
MethodDelegation.withDefaultConfiguration()
|
MethodDelegation.withDefaultConfiguration()
|
||||||
.withBinders(
|
.withBinders(
|
||||||
FieldProxy.Binder.install(FieldGetter.class, FieldSetter.class),
|
|
||||||
Morph.Binder.install(OverrideCallable.class)
|
Morph.Binder.install(OverrideCallable.class)
|
||||||
)
|
)
|
||||||
.to(new InstMethodsInterWithOverrideArgs(interceptor))
|
.to(new InstMethodsInterWithOverrideArgs(interceptor))
|
||||||
|
|
@ -139,9 +135,6 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
||||||
newClassBuilder.method(not(isStatic()).and(instanceMethodsInterceptPoint.getMethodsMatcher()))
|
newClassBuilder.method(not(isStatic()).and(instanceMethodsInterceptPoint.getMethodsMatcher()))
|
||||||
.intercept(
|
.intercept(
|
||||||
MethodDelegation.withDefaultConfiguration()
|
MethodDelegation.withDefaultConfiguration()
|
||||||
.withBinders(
|
|
||||||
FieldProxy.Binder.install(FieldGetter.class, FieldSetter.class)
|
|
||||||
)
|
|
||||||
.to(new InstMethodsInter(interceptor))
|
.to(new InstMethodsInter(interceptor))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,19 +37,16 @@ public class ConstructorInter {
|
||||||
* Intercept the target constructor.
|
* Intercept the target constructor.
|
||||||
*
|
*
|
||||||
* @param obj target class instance.
|
* @param obj target class instance.
|
||||||
* @param dynamicFieldGetter a proxy to set the dynamic field
|
|
||||||
* @param dynamicFieldSetter a proxy to get the dynamic field
|
|
||||||
* @param allArguments all constructor arguments
|
* @param allArguments all constructor arguments
|
||||||
*/
|
*/
|
||||||
@RuntimeType
|
@RuntimeType
|
||||||
public void intercept(@This Object obj,
|
public void intercept(@This Object obj,
|
||||||
@FieldProxy(ClassEnhancePluginDefine.CONTEXT_ATTR_NAME) FieldSetter dynamicFieldSetter,
|
|
||||||
@FieldProxy(ClassEnhancePluginDefine.CONTEXT_ATTR_NAME) FieldGetter dynamicFieldGetter,
|
|
||||||
@AllArguments Object[] allArguments) {
|
@AllArguments Object[] allArguments) {
|
||||||
try {
|
try {
|
||||||
InstanceConstructorInterceptor interceptor = InterceptorInstanceLoader.load(constructorInterceptorClassName, obj.getClass().getClassLoader());
|
InstanceConstructorInterceptor interceptor = InterceptorInstanceLoader.load(constructorInterceptorClassName, obj.getClass().getClassLoader());
|
||||||
|
EnhancedInstance targetObject = (EnhancedInstance)obj;
|
||||||
|
|
||||||
interceptor.onConstruct(obj, allArguments, dynamicFieldSetter, dynamicFieldGetter);
|
interceptor.onConstruct(targetObject, allArguments);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
logger.error("ConstructorInter failure.", t);
|
logger.error("ConstructorInter failure.", t);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,7 @@ package org.skywalking.apm.agent.core.plugin.interceptor.enhance;
|
||||||
* @author wusheng
|
* @author wusheng
|
||||||
*/
|
*/
|
||||||
public interface EnhancedInstance {
|
public interface EnhancedInstance {
|
||||||
Object _getSkyWalkingDynamicFiled();
|
Object getSkyWalkingDynamicField();
|
||||||
|
|
||||||
|
void setSkyWalkingDynamicField();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package org.skywalking.apm.agent.core.plugin.interceptor.enhance;
|
|
||||||
|
|
||||||
public interface FieldGetter {
|
|
||||||
Object getValue();
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package org.skywalking.apm.agent.core.plugin.interceptor.enhance;
|
|
||||||
|
|
||||||
public interface FieldSetter {
|
|
||||||
void setValue(Object value);
|
|
||||||
}
|
|
||||||
|
|
@ -42,8 +42,6 @@ public class InstMethodsInterWithOverrideArgs {
|
||||||
* @param obj target class instance.
|
* @param obj target class instance.
|
||||||
* @param allArguments all method arguments
|
* @param allArguments all method arguments
|
||||||
* @param method method description.
|
* @param method method description.
|
||||||
* @param dynamicFieldGetter a proxy to set the dynamic field
|
|
||||||
* @param dynamicFieldSetter a proxy to get the dynamic field
|
|
||||||
* @param zuper the origin call ref.
|
* @param zuper the origin call ref.
|
||||||
* @return the return value of target instance method.
|
* @return the return value of target instance method.
|
||||||
* @throws Exception only throw exception because of zuper.call() or unexpected exception in sky-walking ( This is a
|
* @throws Exception only throw exception because of zuper.call() or unexpected exception in sky-walking ( This is a
|
||||||
|
|
@ -53,18 +51,15 @@ public class InstMethodsInterWithOverrideArgs {
|
||||||
public Object intercept(@This Object obj,
|
public Object intercept(@This Object obj,
|
||||||
@AllArguments Object[] allArguments,
|
@AllArguments Object[] allArguments,
|
||||||
@Origin Method method,
|
@Origin Method method,
|
||||||
@FieldProxy(ClassEnhancePluginDefine.CONTEXT_ATTR_NAME) FieldSetter dynamicFieldSetter,
|
|
||||||
@FieldProxy(ClassEnhancePluginDefine.CONTEXT_ATTR_NAME) FieldGetter dynamicFieldGetter,
|
|
||||||
@Morph(defaultMethod = true) OverrideCallable zuper
|
@Morph(defaultMethod = true) OverrideCallable zuper
|
||||||
) throws Throwable {
|
) throws Throwable {
|
||||||
InstanceMethodsAroundInterceptor interceptor = InterceptorInstanceLoader
|
InstanceMethodsAroundInterceptor interceptor = InterceptorInstanceLoader
|
||||||
.load(instanceMethodsAroundInterceptorClassName, obj.getClass().getClassLoader());
|
.load(instanceMethodsAroundInterceptorClassName, obj.getClass().getClassLoader());
|
||||||
|
EnhancedInstance targetObject = (EnhancedInstance)obj;
|
||||||
|
|
||||||
MethodInterceptResult result = new MethodInterceptResult();
|
MethodInterceptResult result = new MethodInterceptResult();
|
||||||
try {
|
try {
|
||||||
interceptor.beforeMethod(obj, method.getName(), allArguments, method.getParameterTypes(),
|
interceptor.beforeMethod(targetObject, method.getName(), allArguments, method.getParameterTypes(),
|
||||||
dynamicFieldSetter,
|
|
||||||
dynamicFieldGetter,
|
|
||||||
result);
|
result);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
logger.error(t, "class[{}] before method[{}] intercept failure", obj.getClass(), method.getName());
|
logger.error(t, "class[{}] before method[{}] intercept failure", obj.getClass(), method.getName());
|
||||||
|
|
@ -79,9 +74,7 @@ public class InstMethodsInterWithOverrideArgs {
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
try {
|
try {
|
||||||
interceptor.handleMethodException(obj, method.getName(), allArguments, method.getParameterTypes(),
|
interceptor.handleMethodException(targetObject, method.getName(), allArguments, method.getParameterTypes(),
|
||||||
dynamicFieldSetter,
|
|
||||||
dynamicFieldGetter,
|
|
||||||
t);
|
t);
|
||||||
} catch (Throwable t2) {
|
} catch (Throwable t2) {
|
||||||
logger.error(t2, "class[{}] handle method[{}] exception failure", obj.getClass(), method.getName());
|
logger.error(t2, "class[{}] handle method[{}] exception failure", obj.getClass(), method.getName());
|
||||||
|
|
@ -89,9 +82,7 @@ public class InstMethodsInterWithOverrideArgs {
|
||||||
throw t;
|
throw t;
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
ret = interceptor.afterMethod(obj, method.getName(), allArguments, method.getParameterTypes(),
|
ret = interceptor.afterMethod(targetObject, method.getName(), allArguments, method.getParameterTypes(),
|
||||||
dynamicFieldSetter,
|
|
||||||
dynamicFieldGetter,
|
|
||||||
ret);
|
ret);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
logger.error(t, "class[{}] after method[{}] intercept failure", obj.getClass(), method.getName());
|
logger.error(t, "class[{}] after method[{}] intercept failure", obj.getClass(), method.getName());
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,5 @@ public interface InstanceConstructorInterceptor {
|
||||||
/**
|
/**
|
||||||
* Called before the origin constructor invocation.
|
* Called before the origin constructor invocation.
|
||||||
*/
|
*/
|
||||||
void onConstruct(Object objInst,
|
void onConstruct(Object objInst, Object[] allArguments);
|
||||||
Object[] allArguments,
|
|
||||||
FieldSetter dynamicFieldSetter,
|
|
||||||
FieldGetter dynamicFieldGetter);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,7 @@ public interface InstanceMethodsAroundInterceptor {
|
||||||
* @param result change this result, if you want to truncate the method.
|
* @param result change this result, if you want to truncate the method.
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
void beforeMethod(Object objInst, String methodName, Object[] allArguments, Class<?>[] argumentsTypes,
|
void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||||
FieldSetter dynamicFieldSetter,
|
|
||||||
FieldGetter dynamicFieldGetter,
|
|
||||||
MethodInterceptResult result) throws Throwable;
|
MethodInterceptResult result) throws Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -25,9 +23,7 @@ public interface InstanceMethodsAroundInterceptor {
|
||||||
* @return the method's actual return value.
|
* @return the method's actual return value.
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
Object afterMethod(Object objInst, String methodName, Object[] allArguments, Class<?>[] argumentsTypes,
|
Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||||
FieldSetter dynamicFieldSetter,
|
|
||||||
FieldGetter dynamicFieldGetter,
|
|
||||||
Object ret) throws Throwable;
|
Object ret) throws Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -35,8 +31,6 @@ public interface InstanceMethodsAroundInterceptor {
|
||||||
*
|
*
|
||||||
* @param t the exception occur.
|
* @param t the exception occur.
|
||||||
*/
|
*/
|
||||||
void handleMethodException(Object objInst, String methodName, Object[] allArguments, Class<?>[] argumentsTypes,
|
void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||||
FieldSetter dynamicFieldSetter,
|
|
||||||
FieldGetter dynamicFieldGetter,
|
|
||||||
Throwable t);
|
Throwable t);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue