Merge pull request #70 from ascrutae/fix/#69
Thank @raphw for the review.
This commit is contained in:
commit
96e013021c
|
|
@ -1,9 +1,5 @@
|
|||
package com.a.eye.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
import static net.bytebuddy.jar.asm.Opcodes.ACC_PRIVATE;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.plugin.AbstractClassEnhancePluginDefine;
|
||||
|
|
@ -18,6 +14,9 @@ import net.bytebuddy.implementation.bind.annotation.FieldProxy;
|
|||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
|
||||
import static net.bytebuddy.jar.asm.Opcodes.ACC_PRIVATE;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePluginDefine {
|
||||
private static ILog logger = LogManager.getLogger(ClassEnhancePluginDefine.class);
|
||||
|
||||
|
|
@ -66,12 +65,17 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
/**
|
||||
* 2. enhance constructors
|
||||
*/
|
||||
newClassBuilder = newClassBuilder.constructor(ElementMatchers.<MethodDescription>any())
|
||||
.intercept(SuperMethodCall.INSTANCE.andThen(
|
||||
MethodDelegation.to(new DefaultClassConstructorInterceptor())
|
||||
.appendParameterBinder(FieldProxy.Binder.install(FieldGetter.class, FieldSetter.class))));
|
||||
|
||||
if (existedConstructorInterceptPoint) {
|
||||
for (ConstructorInterceptPoint constructorInterceptPoint : constructorInterceptPoints) {
|
||||
newClassBuilder = newClassBuilder.constructor(constructorInterceptPoint.getConstructorMatcher())
|
||||
.intercept(SuperMethodCall.INSTANCE.andThen(
|
||||
MethodDelegation.to(new ClassConstructorInterceptor(constructorInterceptPoint.getConstructorInterceptor()))
|
||||
.appendParameterBinder(FieldProxy.Binder.install(FieldGetter.class, FieldSetter.class))));
|
||||
MethodDelegation.to(new ClassConstructorInterceptor(constructorInterceptPoint.getConstructorInterceptor()))
|
||||
.appendParameterBinder(FieldProxy.Binder.install(FieldGetter.class, FieldSetter.class))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package com.a.eye.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.FieldProxy;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
import net.bytebuddy.implementation.bind.annotation.This;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/12/6.
|
||||
*/
|
||||
public class DefaultClassConstructorInterceptor {
|
||||
private static ILog logger = LogManager
|
||||
.getLogger(ClassConstructorInterceptor.class);
|
||||
|
||||
@RuntimeType
|
||||
public void intercept(
|
||||
@This Object obj,
|
||||
@FieldProxy(ClassEnhancePluginDefine.contextAttrName) FieldSetter accessor,
|
||||
@AllArguments Object[] allArguments) {
|
||||
try {
|
||||
EnhancedClassInstanceContext context = new EnhancedClassInstanceContext();
|
||||
accessor.setValue(context);
|
||||
} catch (Throwable t) {
|
||||
logger.error("ClassConstructorInterceptor failure.", t);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue