重命名部分类名,规范化接口参数。#36
This commit is contained in:
parent
03e006bffa
commit
4f606cabfe
|
|
@ -26,7 +26,7 @@ public class ClassConstructorInterceptor {
|
|||
try {
|
||||
EnhancedClassInstanceContext context = new EnhancedClassInstanceContext();
|
||||
accessor.setValue(context);
|
||||
ConstructorContext interceptorContext = new ConstructorContext(
|
||||
ConstructorInvokeContext interceptorContext = new ConstructorInvokeContext(obj,
|
||||
allArguments);
|
||||
interceptor.onConstruct(context, interceptorContext);
|
||||
} catch (Throwable t) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class ClassMethodInterceptor {
|
|||
@SuperCall Callable<?> zuper,
|
||||
@FieldValue(EnhanceClazz4Interceptor.contextAttrName) EnhancedClassInstanceContext instanceContext)
|
||||
throws Exception {
|
||||
InterceptorContext interceptorContext = new InterceptorContext(obj,
|
||||
MethodInvokeContext interceptorContext = new MethodInvokeContext(obj,
|
||||
method.getName(), allArguments);
|
||||
try {
|
||||
interceptor.beforeMethod(instanceContext, interceptorContext);
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor;
|
||||
|
||||
public class ConstructorContext {
|
||||
private Object[] allArguments;
|
||||
|
||||
ConstructorContext(Object[] allArguments) {
|
||||
this.allArguments = allArguments;
|
||||
}
|
||||
|
||||
public Object[] allArguments(){
|
||||
return this.allArguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor;
|
||||
|
||||
public class ConstructorInvokeContext {
|
||||
/**
|
||||
* 代理对象实例
|
||||
*/
|
||||
private Object objInst;
|
||||
/**
|
||||
* 构造函数参数
|
||||
*/
|
||||
private Object[] allArguments;
|
||||
|
||||
ConstructorInvokeContext(Object objInst, Object[] allArguments) {
|
||||
this.objInst = objInst;
|
||||
this.allArguments = allArguments;
|
||||
}
|
||||
|
||||
public Object inst(){
|
||||
return objInst;
|
||||
}
|
||||
|
||||
public Object[] allArguments(){
|
||||
return this.allArguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor;
|
||||
|
||||
public interface IAroundInterceptor {
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorContext interceptorContext);
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext);
|
||||
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InterceptorContext interceptorContext);
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, MethodInvokeContext interceptorContext);
|
||||
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InterceptorContext interceptorContext, Object ret);
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, MethodInvokeContext interceptorContext, Object ret);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,26 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor;
|
||||
|
||||
|
||||
public class InterceptorContext {
|
||||
/**
|
||||
* 方法执行拦截上下文
|
||||
*
|
||||
* @author wusheng
|
||||
*
|
||||
*/
|
||||
public class MethodInvokeContext {
|
||||
/**
|
||||
* 代理类实例
|
||||
*/
|
||||
private Object objInst;
|
||||
/**
|
||||
* 方法名称
|
||||
*/
|
||||
private String methodName;
|
||||
/**
|
||||
* 方法参数
|
||||
*/
|
||||
private Object[] allArguments;
|
||||
|
||||
InterceptorContext(Object objInst, String methodName, Object[] allArguments) {
|
||||
MethodInvokeContext(Object objInst, String methodName, Object[] allArguments) {
|
||||
this.objInst = objInst;
|
||||
this.methodName = methodName;
|
||||
this.allArguments = allArguments;
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
package test.ai.cloud.plugin;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.ConstructorContext;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.ConstructorInvokeContext;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.InterceptorContext;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.MethodInvokeContext;
|
||||
|
||||
public class TestAroundInterceptor implements IAroundInterceptor {
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorContext interceptorContext) {
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
context.set("test.key", "123");
|
||||
System.out.println("onConstruct, args size=" + interceptorContext.allArguments().length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InterceptorContext interceptorContext) {
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, MethodInvokeContext interceptorContext) {
|
||||
System.out.println("beforeMethod : " + context.get("test.key", String.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InterceptorContext interceptorContext, Object ret) {
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, MethodInvokeContext interceptorContext, Object ret) {
|
||||
System.out.println("afterMethod: " + context.get("test.key", String.class));
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue