修改afterMethod接口,以及相关的依赖实现。允许afterMethod复写方法的返回值,用于进行特定的类包装。#36
This commit is contained in:
parent
904d0cb205
commit
8c70efcc6c
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue