From 8c70efcc6cd2888fdc6f7eca449038e7304b7860 Mon Sep 17 00:00:00 2001 From: wusheng Date: Mon, 14 Mar 2016 17:32:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9afterMethod=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E5=8F=8A=E7=9B=B8=E5=85=B3=E7=9A=84=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=AE=9E=E7=8E=B0=E3=80=82=E5=85=81=E8=AE=B8afterMeth?= =?UTF-8?q?od=E5=A4=8D=E5=86=99=E6=96=B9=E6=B3=95=E7=9A=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=EF=BC=8C=E7=94=A8=E4=BA=8E=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E7=89=B9=E5=AE=9A=E7=9A=84=E7=B1=BB=E5=8C=85=E8=A3=85=E3=80=82?= =?UTF-8?q?#36?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/ClassMethodInterceptor.java | 6 ++++-- .../plugin/interceptor/IAroundInterceptor.java | 2 +- .../java/test/ai/cloud/plugin/PluginMainTest.java | 15 +++++++++++---- .../ai/cloud/plugin/TestAroundInterceptor.java | 3 ++- 4 files changed, 18 insertions(+), 8 deletions(-) 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 35435799bd..c8f2e46487 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 50cc929dac..26ddbb3cef 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 77fc86b228..fd67b57596 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 f822e0ff8a..c0993108f9 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; } } -- GitLab