Commit 8c70efcc authored by 吴晟's avatar 吴晟
Browse files

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

parent 904d0cb2
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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;
	}
}
+1 −1
Original line number Diff line number Diff line
@@ -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);
	
	
}
+11 −4
Original line number Diff line number Diff line
@@ -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) {
		long start = System.currentTimeMillis();

		BeInterceptedClass inst = new BeInterceptedClass();
		inst.printabc();
		long end = System.currentTimeMillis();
		System.out.println(end - start + "ms");
	}
}
+2 −1
Original line number Diff line number Diff line
@@ -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;
	}

}