提交 8c70efcc 编写于 作者: wu-sheng's avatar wu-sheng

修改afterMethod接口,以及相关的依赖实现。允许afterMethod复写方法的返回值,用于进行特定的类包装。#36

上级 904d0cb2
......@@ -45,15 +45,17 @@ public class ClassMethodInterceptor {
logger.error("class[{}] before method[{}] intercept failue:{}",
obj.getClass(), method.getName(), t.getMessage(), t);
}
Object ret = null;
try {
return zuper.call();
ret = zuper.call();
} finally {
try {
interceptor.afterMethod(instanceContext, interceptorContext);
ret = interceptor.afterMethod(instanceContext, interceptorContext, ret);
} catch (Throwable t) {
logger.error("class[{}] after method[{}] intercept failue:{}",
obj.getClass(), method.getName(), t.getMessage(), t);
}
}
return ret;
}
}
......@@ -5,7 +5,7 @@ public interface IAroundInterceptor {
public void beforeMethod(EnhancedClassInstanceContext context, InterceptorContext interceptorContext);
public void afterMethod(EnhancedClassInstanceContext context, InterceptorContext interceptorContext);
public Object afterMethod(EnhancedClassInstanceContext context, InterceptorContext interceptorContext, Object ret);
}
......@@ -8,12 +8,19 @@ import com.ai.cloud.skywalking.plugin.TracingBootstrap;
public class PluginMainTest {
@Test
public void testMain() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException{
TracingBootstrap.main(new String[]{"test.ai.cloud.plugin.PluginMainTest"});
public void testMain() throws IllegalAccessException,
IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SecurityException, ClassNotFoundException {
TracingBootstrap
.main(new String[] { "test.ai.cloud.plugin.PluginMainTest" });
}
public static void main(String[] args){
public static void main(String[] args) {
long start = System.currentTimeMillis();
BeInterceptedClass inst = new BeInterceptedClass();
inst.printabc();
long end = System.currentTimeMillis();
System.out.println(end - start + "ms");
}
}
......@@ -19,8 +19,9 @@ public class TestAroundInterceptor implements IAroundInterceptor {
}
@Override
public void afterMethod(EnhancedClassInstanceContext context, InterceptorContext interceptorContext) {
public Object afterMethod(EnhancedClassInstanceContext context, InterceptorContext interceptorContext, Object ret) {
System.out.println("afterMethod: " + context.get("test.key", String.class));
return ret;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册