diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassMethodInterceptor.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassMethodInterceptor.java index 35435799bd8de93cc66089821fcc7919470dc06b..c8f2e46487a8445cee4be8a779a18be505c3dd0f 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassMethodInterceptor.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassMethodInterceptor.java @@ -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; } } diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/IAroundInterceptor.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/IAroundInterceptor.java index 50cc929dac54182d6eff1b84835523eb3eb94af7..26ddbb3cef8370b4f3058e688444b0726cd58d58 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/IAroundInterceptor.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/IAroundInterceptor.java @@ -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); } diff --git a/skywalking-api/src/test/java/test/ai/cloud/plugin/PluginMainTest.java b/skywalking-api/src/test/java/test/ai/cloud/plugin/PluginMainTest.java index 77fc86b228829320db797f9330b21c51db589b0c..fd67b5759637c5bece2cac1080584fe73ee280c0 100644 --- a/skywalking-api/src/test/java/test/ai/cloud/plugin/PluginMainTest.java +++ b/skywalking-api/src/test/java/test/ai/cloud/plugin/PluginMainTest.java @@ -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"); } } diff --git a/skywalking-api/src/test/java/test/ai/cloud/plugin/TestAroundInterceptor.java b/skywalking-api/src/test/java/test/ai/cloud/plugin/TestAroundInterceptor.java index f822e0ff8a18f808f4a2ecaad9eb48600c5f9b88..c0993108f95acfe9dd972e13bbb140533e5c6a9a 100644 --- a/skywalking-api/src/test/java/test/ai/cloud/plugin/TestAroundInterceptor.java +++ b/skywalking-api/src/test/java/test/ai/cloud/plugin/TestAroundInterceptor.java @@ -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; } }