refact constructor intercept again, suppor multi interceptPoints
This commit is contained in:
parent
97bd55f376
commit
9430d3dc4e
|
|
@ -1,9 +1,14 @@
|
|||
package com.a.eye.skywalking.plugin.interceptor;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/29.
|
||||
*/
|
||||
public interface ConstructorInterceptPoint{
|
||||
ElementMatcher.Junction<MethodDescription> getConstructorMatcher();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return represents a class name, the class instance must instanceof InstanceConstructorInterceptor.
|
||||
|
|
|
|||
|
|
@ -68,8 +68,7 @@ public abstract class MethodMatcher {
|
|||
}
|
||||
|
||||
public enum Modifier {
|
||||
Public, Default, Private, Protected,
|
||||
ClassLoadingStrategy;
|
||||
Public, Default, Private, Protected;
|
||||
|
||||
private ElementMatcher.Junction<MethodDescription> elementMatcher() {
|
||||
switch (this) {
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.interceptor.assist;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/29.
|
||||
*/
|
||||
public class DefaultConstructorInterceptor implements InstanceConstructorInterceptor {
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
// do nothing as default implements.
|
||||
}
|
||||
}
|
||||
|
|
@ -33,11 +33,11 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
}
|
||||
|
||||
private DynamicType.Builder<?> enhanceInstance(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
ConstructorInterceptPoint constructorInterceptPoint = getConstructorsInterceptPoint();
|
||||
ConstructorInterceptPoint[] constructorInterceptPoints = getConstructorsInterceptPoints();
|
||||
InstanceMethodsInterceptPoint[] instanceMethodsInterceptPoints = getInstanceMethodsInterceptPoints();
|
||||
|
||||
boolean existedConstructorInterceptPoint = false;
|
||||
if (constructorInterceptPoint != null) {
|
||||
if (constructorInterceptPoints != null && constructorInterceptPoints.length > 0) {
|
||||
existedConstructorInterceptPoint = true;
|
||||
}
|
||||
boolean existedMethodsInterceptPoints = false;
|
||||
|
|
@ -61,19 +61,25 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
* EnhancedClassInstanceContext <br/>
|
||||
*
|
||||
*/
|
||||
String constructorInterceptor;
|
||||
if (existedConstructorInterceptPoint) {
|
||||
constructorInterceptor = constructorInterceptPoint.getConstructorInterceptor();
|
||||
} else {
|
||||
constructorInterceptor = "com.a.eye.skywalking.plugin.interceptor.assist.DefaultConstructorInterceptor";
|
||||
}
|
||||
|
||||
newClassBuilder = newClassBuilder.defineField(contextAttrName, EnhancedClassInstanceContext.class, ACC_PRIVATE);
|
||||
|
||||
newClassBuilder = newClassBuilder.constructor(any()).intercept(SuperMethodCall.INSTANCE
|
||||
.andThen(MethodDelegation.to(new ClassConstructorInterceptor(constructorInterceptor)).appendParameterBinder(FieldProxy.Binder.install(FieldGetter.class, FieldSetter.class))));
|
||||
/**
|
||||
* 2. enhance constructors
|
||||
*/
|
||||
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))));
|
||||
}
|
||||
}
|
||||
|
||||
if(existedMethodsInterceptPoints) {
|
||||
|
||||
/**
|
||||
* 3. enhance instance methods
|
||||
*/
|
||||
if (existedMethodsInterceptPoints) {
|
||||
for (InstanceMethodsInterceptPoint instanceMethodsInterceptPoint : instanceMethodsInterceptPoints) {
|
||||
|
||||
String interceptor = instanceMethodsInterceptPoint.getMethodsInterceptor();
|
||||
|
|
@ -113,7 +119,7 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
return newClassBuilder;
|
||||
}
|
||||
|
||||
protected abstract ConstructorInterceptPoint getConstructorsInterceptPoint();
|
||||
protected abstract ConstructorInterceptPoint[] getConstructorsInterceptPoints();
|
||||
|
||||
protected abstract InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints();
|
||||
|
||||
|
|
@ -121,7 +127,7 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
private DynamicType.Builder<?> enhanceClass(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
StaticMethodsInterceptPoint[] staticMethodsInterceptPoints = getStaticMethodsInterceptPoints();
|
||||
|
||||
if(staticMethodsInterceptPoints == null || staticMethodsInterceptPoints.length == 0){
|
||||
if (staticMethodsInterceptPoints == null || staticMethodsInterceptPoints.length == 0) {
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public abstract class ClassStaticMethodsEnhancePluginDefine extends
|
|||
ClassEnhancePluginDefine {
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint(){
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints(){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
package com.a.eye.skywalking.context;
|
||||
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class CurrentThreadSpanStackTest {
|
||||
|
||||
@Test
|
||||
public void testStack(){
|
||||
Span rootSpan = new Span("test","test","Test");
|
||||
Span subSpan1 = new Span("test","0", 10, "test","Test");
|
||||
Span subSpan2 = new Span("test","0", 10, "test","Test");
|
||||
CurrentThreadSpanStack.push(rootSpan);
|
||||
|
||||
CurrentThreadSpanStack.push(subSpan1);
|
||||
Span span = CurrentThreadSpanStack.peek();
|
||||
assertEquals(0, span.getLevelId());
|
||||
CurrentThreadSpanStack.pop();
|
||||
|
||||
CurrentThreadSpanStack.push(subSpan2);
|
||||
span = CurrentThreadSpanStack.peek();
|
||||
assertEquals(1, span.getLevelId());
|
||||
CurrentThreadSpanStack.pop();
|
||||
|
||||
CurrentThreadSpanStack.pop();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package test.a.eye.cloud.assertspandata;
|
||||
|
||||
import com.a.eye.skywalking.buffer.ContextBuffer;
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.protocol.RequestSpan;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.testframework.api.RequestSpanAssert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-6.
|
||||
*/
|
||||
public class SDKGeneratedDataTest {
|
||||
|
||||
@Test
|
||||
public void traceTreeAssertTest() {
|
||||
Config.Consumer.MAX_CONSUMER = 0;
|
||||
Span testSpan = new Span("1.0b.1465224457414.7e57f54.22905.61.2691", "", 0, "test-application", "5");
|
||||
RequestSpan requestSpan =
|
||||
RequestSpan.RequestSpanBuilder.newBuilder(testSpan).viewPoint("http://hire.asiainfo.com/Aisse-Mobile-Web/aisseWorkPage/submitReimbursement").build();
|
||||
ContextBuffer.save(requestSpan);
|
||||
RequestSpanAssert.assertEquals(new String[][] {{"0", "http://hire.asiainfo.com/Aisse-Mobile-Web/aisseWorkPage/submitReimbursement", null}});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
package test.a.eye.cloud.checksum;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CheckSumTest {
|
||||
private static final int dataIndex = 2;
|
||||
private static final int MAX_TEST_COUNT = 100_000_00;
|
||||
|
||||
@Test
|
||||
public void TestAllXORSum() {
|
||||
String data = dataArray[dataIndex];
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (int i = 0; i < MAX_TEST_COUNT; i++) {
|
||||
intToBytes2(makeChecksum(data, 1));
|
||||
}
|
||||
System.out.println("All XOR check sum totalSize:" + MAX_TEST_COUNT + " cost :" + (((System.currentTimeMillis() - startTime))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test18XORSum() {
|
||||
String data = dataArray[dataIndex];
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (int i = 0; i < MAX_TEST_COUNT; i++) {
|
||||
intToBytes2(makeChecksum(data, 8));
|
||||
}
|
||||
System.out.println("All XOR check sum totalSize:" + MAX_TEST_COUNT + " cost :" + (((System.currentTimeMillis() - startTime))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test116XORSum() {
|
||||
String data = dataArray[dataIndex];
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (int i = 0; i < MAX_TEST_COUNT; i++) {
|
||||
intToBytes2(makeChecksum(data, 16));
|
||||
}
|
||||
System.out.println("All XOR check sum totalSize:" + MAX_TEST_COUNT + " cost :" + (((System.currentTimeMillis() - startTime))));
|
||||
}
|
||||
|
||||
public int makeChecksum(String data, int step) {
|
||||
char[] dataArray = data.toCharArray();
|
||||
int result = dataArray[0];
|
||||
for (int i = 0; i < dataArray.length; i = i + step) {
|
||||
result ^= dataArray[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte[] intToBytes2(int value) {
|
||||
byte[] src = new byte[4];
|
||||
src[0] = (byte) ((value >> 24) & 0xFF);
|
||||
src[1] = (byte) ((value >> 16) & 0xFF);
|
||||
src[2] = (byte) ((value >> 8) & 0xFF);
|
||||
src[3] = (byte) (value & 0xFF);
|
||||
return src;
|
||||
}
|
||||
|
||||
private static final String[] dataArray = new String[]{
|
||||
"1.0b.1463530404744.9576be7.22045.45.1480@~0@~0@~com.ai.aisse.controller.overtimeexpense.OvertimeExpenseC" +
|
||||
"ontroller.overtimeInit(com.ai.net.xss.wrapper.XssRequestWrapper,org.apache.catalina.connector.ResponseFa" +
|
||||
"cade,org.springframework.validation.support.BindingAwareModelMap)@~1463530404774@~5@~ITSC-MIS-LEV-web01/" +
|
||||
"10.1.31.12@~0@~ @~M@~false@~ @~22045@~aisse-mobile-web@~5@~L#&",
|
||||
"1.0b.1463539216140.50f8123.14804.265333.1493@~0.0.0@~3@~tracing:jdbc:oracle:thin:@10.1.1.61:1521:OAPROD(" +
|
||||
"aisse)@~1463539212130@~1@~ITSC-MIS-LEV-web01/10.1.31.12@~0@~ @~J@~false@~connection.commit@~10872@~aisse" +
|
||||
"-dubbo@~5@~L#&1.0b.1463539217412.50f8123.14804.52.1556@~0.0.0@~1@~com.ai.aisse.core.dao.impl.AisseItemLi" +
|
||||
"stTDaoImpl.queryAisseItemWorkMealTs(java.util.LinkedHashMap)@~1463539213376@~6@~ITSC-MIS-LEV-web01/10.1." +
|
||||
"31.12@~0@~ @~M@~false@~ @~10872@~aisse-dubbo@~5@~L#&1.0b.1463539217412.50f8123.14804.52.1556@~0.0.0@~2@~" +
|
||||
"tracing:jdbc:oracle:thin:@10.1.1.61:1521:OAPROD(aisse)@~1463539213384@~1@~ITSC-MIS-LEV-web01/10.1.31.12@" +
|
||||
"~0@~ @~J@~false@~connection.commit@~10872@~aisse-dubbo@~5@~L#&1.0b.1463539217412.50f8123.14804.52.1556@~" +
|
||||
"0.0@~0@~rest://10.1.31.12:20188/aisse/com.ai.aisse.core.rest.IAisseVoucherApi.queryAisseItemT(Map)@~1463" +
|
||||
"539213354@~32@~ITSC-MIS-LEV-web01/10.1.31.12@~0@~ @~D@~true@~ @~10872@~aisse-dubbo@~5@~S#&",
|
||||
"1.0b.1463540545212.3627470.24702.142.5@~ @~0@~Map com.ai.saas.comment.core.service.impl.EvalutionObjSvIm" +
|
||||
"pl.getCommentsParamters(RequestData)@~1463540545212@~32@~host-10-1-236-126/127.0.0.1@~1@~java.lang.Runti" +
|
||||
"meException: Value for ntAccount cannot be null#~ at com.ai.saas.comment.core.model.dto.EvalutionO" +
|
||||
"bjectResultCriteria$GeneratedCriteria.addCriterion(EvalutionObjectResultCriteria.java:116)#~ at com.a" +
|
||||
"i.saas.comment.core.model.dto.EvalutionObjectResultCriteria$GeneratedCriteria.andNtAccountEqualTo(Evalut" +
|
||||
"ionObjectResultCriteria.java:479)#~ at com.ai.saas.comment.core.model.dto.EvalutionObjectResultCrite" +
|
||||
"ria$Criteria.andNtAccountEqualTo(EvalutionObjectResultCriteria.java:1089)#~ at com.ai.saas.comment.c" +
|
||||
"ore.service.impl.EvalutionObjSvImpl.getCommentsParamters(EvalutionObjSvImpl.java:327)#~ at com.ai.saas.c" +
|
||||
"omment.core.service.impl.EvalutionObjSvImpl$$FastClassBySpringCGLIB$$e4328417.invoke(<generated>)#~" +
|
||||
"at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)#~ at org.springframework.a" +
|
||||
"op.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)#~ at org.s" +
|
||||
"pringframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)#~" +
|
||||
"at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(Transactio" +
|
||||
"nInterceptor.java:99)#~ at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWi" +
|
||||
"thinTransaction(TransactionAspectSupport.java:281)#~ at org.springframework.transaction.interceptor.T" +
|
||||
"ransactionInterceptor.invoke(TransactionInterceptor.java:96)#~ at org.springframework.aop.framework.Ref" +
|
||||
"lectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)#~ at org.springframework.aop.frame" +
|
||||
"work.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)#~ at com.ai.saas.c" +
|
||||
"omment.core.service.impl.EvalutionObjSvImpl$$EnhancerBySpringCGLIB$$9d683df1.getCommentsParamters(<gener" +
|
||||
"ated>)#~ at com.ai.saas.comment.core.service.impl.EvalutionObjSvImpl$$FastClassBySpringCGLIB$$e43" +
|
||||
"28417.invoke(<generated>)#~ at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:2" +
|
||||
"04)#~ at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAo" +
|
||||
"pProxy.java:720)#~ at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)#~ at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.p" +
|
||||
"roceed(MethodInvocationProceedingJoinPoint.java:85)#~ at com.a.eye.skywalking.plugin.spring.Tracing" +
|
||||
"Aspect.doTracing(TracingAspect.java:13)#~ at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown " +
|
||||
"Source)#~ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)" +
|
||||
"#~ at java.lang.reflect.Method.invoke(Method.java:606)#~ at org.springframework.aop.aspectj.Abstr" +
|
||||
"actAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)#~ at org.springfra" +
|
||||
"mework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)#~ at org.s" +
|
||||
"pringframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)#~ at org.springfra" +
|
||||
"mework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)#~ at org.s" +
|
||||
"pringframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)#~" +
|
||||
" at com.ai.saas.comment.core.service.impl.EvalutionObjSvImpl$$EnhancerBySpringCGLIB$$312c8477.get" +
|
||||
"CommentsParamters(<generated>)#~ at com.ai.saas.comment.core.api.impl.ObjectCommentApiImpl.getCom" +
|
||||
"mentsParamters(ObjectCommentApiImpl.java:43)#~ at com.alibaba.dubbo.common.bytecode.Wrapper5.invokeMeth" +
|
||||
"od(Wrapper5.java)#~ at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(Javass" +
|
||||
"istProxyFactory.java:46)#~ at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxy" +
|
||||
"Invoker.java:72)#~ at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)#" +
|
||||
"~ at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)#~ at com.a" +
|
||||
"libaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)#~ at com.a" +
|
||||
"libaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)#~ at com.alibaba.dubbo.rpc.protoco" +
|
||||
"l.Pr@~M@~false@~ @~24702@~saas-comment-servers@~5@~L#&"
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
package test.a.eye.cloud.list;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-7-2.
|
||||
*/
|
||||
public class ArrayListTest {
|
||||
private List<String> data = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void initData() {
|
||||
data.add("AAAA");
|
||||
data.add("AAAAB");
|
||||
data.add("AAAAB");
|
||||
data.add("AAAAB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPop() {
|
||||
data.remove(data.size() - 1);
|
||||
assertEquals(data.size(), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPush() {
|
||||
data.add(data.size(), "BBBBB");
|
||||
assertEquals(data.get(data.size() - 1), "BBBBB");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package test.a.eye.cloud.logging;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LoggingTest {
|
||||
|
||||
EasyLogger easyLogger = LogManager.getLogger(LoggingTest.class);
|
||||
|
||||
@Test
|
||||
public void testNormalLogging() {
|
||||
easyLogger.debug("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorLogging() {
|
||||
easyLogger.error("Hello World", new RuntimeException("Failed message"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFile() {
|
||||
Config.Logging.MAX_LOG_FILE_LENGTH = 2400;
|
||||
easyLogger.error("Hello World", new RuntimeException("Failed message"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
package test.a.eye.cloud.matcher;
|
||||
|
||||
import com.a.eye.skywalking.plugin.AbstractClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.PluginBootstrap;
|
||||
import com.a.eye.skywalking.plugin.PluginDefineCategory;
|
||||
import com.a.eye.skywalking.plugin.PluginException;
|
||||
import junit.framework.TestCase;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.ClassFileLocator;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExclusionMatcherTest extends TestCase {
|
||||
@Test
|
||||
public void testMatcher()
|
||||
throws ClassNotFoundException, IllegalAccessException, InstantiationException, InterruptedException,
|
||||
PluginException {
|
||||
List<AbstractClassEnhancePluginDefine> pluginDefines = new PluginBootstrap().loadPlugins();
|
||||
|
||||
PluginDefineCategory category = PluginDefineCategory.category(pluginDefines);
|
||||
|
||||
|
||||
for (Map.Entry<String, AbstractClassEnhancePluginDefine> entry : category
|
||||
.getExactClassEnhancePluginDefineMapping().entrySet()) {
|
||||
DynamicType.Builder<?> newClassBuilder = new ByteBuddy()
|
||||
.rebase(TypePool.Default.ofClassPath().describe(entry.getKey()).resolve(),
|
||||
ClassFileLocator.ForClassLoader.ofClassPath());
|
||||
|
||||
newClassBuilder = entry.getValue().define(entry.getKey(), newClassBuilder);
|
||||
newClassBuilder.make().load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION)
|
||||
.getLoaded();
|
||||
}
|
||||
|
||||
TestMatcherClass testMatcherClass =
|
||||
(TestMatcherClass) Class.forName("TestMatcherClass").newInstance();
|
||||
|
||||
testMatcherClass.set();
|
||||
testMatcherClass.seta("a");
|
||||
testMatcherClass.get("a");
|
||||
testMatcherClass.find();
|
||||
System.out.println(testMatcherClass.toString());
|
||||
testMatcherClass.equals(new TestMatcherClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
package test.a.eye.cloud.matcher;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-8.
|
||||
*/
|
||||
public class TestAroundInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
System.out.println("before method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
System.out.println("after method");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package test.a.eye.cloud.matcher;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-8.
|
||||
*/
|
||||
public class TestMatcherClass {
|
||||
|
||||
public void set() {
|
||||
System.out.println("public set()");
|
||||
}
|
||||
|
||||
public void seta(String a) {
|
||||
System.out.println("public seta(String a)");
|
||||
set(a);
|
||||
}
|
||||
|
||||
private void set(String a) {
|
||||
System.out.println("private set(String a)");
|
||||
}
|
||||
|
||||
public void get(String a) {
|
||||
System.out.println("public get(String a)");
|
||||
}
|
||||
|
||||
public void find() {
|
||||
System.out.println("public find()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Call toString()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
System.out.println("equals(Object obj)");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
package test.a.eye.cloud.matcher;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.PrivateMethodMatcher;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-8.
|
||||
*/
|
||||
public class TestMatcherDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
public String enhanceClassName() {
|
||||
return "test.a.eye.cloud.matcher.TestMatcherClass";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
// return new MethodMatcher[]{
|
||||
// new PrivateMethodMatcher(),
|
||||
// new MethodsExclusiveMatcher(new SimpleMethodMatcher("set")),
|
||||
// new SimpleMethodMatcher(MethodMatcher.Modifier.Private, "set", 1)
|
||||
// };
|
||||
// return new MethodMatcher[] { new SimpleMethodMatcher(Modifier.Public, "printabc", new Class[]{String.class, String.class}) };
|
||||
return new MethodMatcher[] {new PrivateMethodMatcher()};
|
||||
//return new MethodMatcher[]{new AnyMethodsMatcher()};
|
||||
//return new MethodMatcher[]{new MethodsExclusiveMatcher(new SimpleMethodMatcher("set"), new SimpleMethodMatcher(MethodMatcher.Modifier.Public,"get"))};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "test.a.eye.cloud.matcher.TestAroundInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||
public class PluginMainTest {
|
||||
@Test
|
||||
public void testMain() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, PluginException {
|
||||
TracingBootstrap.main(new String[] {"PluginMainTest"});
|
||||
TracingBootstrap.main(new String[] {"test.a.eye.cloud.plugin.PluginMainTest"});
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
|
|
@ -17,7 +17,7 @@ public class PluginMainTest {
|
|||
SecurityException {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
BeInterceptedClass inst = (BeInterceptedClass) Class.forName("BeInterceptedClass").newInstance();
|
||||
BeInterceptedClass inst = (BeInterceptedClass) Class.forName("test.a.eye.cloud.plugin.BeInterceptedClass").newInstance();
|
||||
inst.printabc();
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println(end - start + "ms");
|
||||
|
|
|
|||
|
|
@ -8,12 +8,6 @@ import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult;
|
|||
|
||||
public class TestAroundInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override
|
||||
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, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
System.out.println("beforeMethod : " + context.get("test.key", String.class));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package test.a.eye.cloud.plugin;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
|
||||
|
|
@ -12,23 +15,37 @@ public class TestInterceptorDefine extends ClassEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MethodMatcher[] getInstanceMethodsMatchers() {
|
||||
return new MethodMatcher[] { new SimpleMethodMatcher("printabc") };
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInstanceMethodsInterceptor() {
|
||||
return "TestAroundInterceptor";
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
return new MethodMatcher[]{new SimpleMethodMatcher("printabc")};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "TestAroundInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MethodMatcher[] getStaticMethodsMatchers() {
|
||||
return new MethodMatcher[] { new SimpleMethodMatcher("call") };
|
||||
}
|
||||
protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
|
||||
return new StaticMethodsInterceptPoint[]{new StaticMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
return new MethodMatcher[]{new SimpleMethodMatcher("call")};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getStaticMethodsInterceptor() {
|
||||
return "TestStaticAroundInterceptor";
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "TestStaticAroundInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
package test.a.eye.cloud.serialize;
|
||||
|
||||
import com.a.eye.skywalking.buffer.ContextBuffer;
|
||||
import com.a.eye.skywalking.protocol.AckSpan;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.protocol.common.SpanType;
|
||||
|
||||
public class SerializeTest {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
while (true) {
|
||||
Span spandata = new Span("1.0b.1461060884539.7d6d06e.22489.1271.103", "", 0, "test-application", "test");
|
||||
spandata.setSpanType(SpanType.LOCAL);
|
||||
spandata.setStartDate(System.currentTimeMillis() - 1000 * 60);
|
||||
AckSpan requestSpan = new AckSpan(spandata);
|
||||
ContextBuffer.save(requestSpan);
|
||||
Thread.sleep(500);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ public class DubboPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint() {
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhan
|
|||
|
||||
public abstract class HttpClientPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint() {
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhan
|
|||
|
||||
public abstract class AbstractDatabasePluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint() {
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.a.eye.skywalking.plugin.jedis.v2;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-12.
|
||||
*/
|
||||
public class JedisClusterConstructorInterceptor4HostAndPortArg implements InstanceConstructorInterceptor {
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
StringBuilder redisConnInfo = new StringBuilder();
|
||||
HostAndPort hostAndPort = (HostAndPort) interceptorContext.allArguments()[0];
|
||||
redisConnInfo.append(hostAndPort.toString()).append(";");
|
||||
context.set(REDIS_CONN_INFO_KEY, redisConnInfo.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.a.eye.skywalking.plugin.jedis.v2;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-12.
|
||||
*/
|
||||
public class JedisClusterConstructorInterceptor4SetArg implements InstanceConstructorInterceptor {
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
StringBuilder redisConnInfo = new StringBuilder();
|
||||
Set<HostAndPort> hostAndPorts = (Set<HostAndPort>) interceptorContext.allArguments()[0];
|
||||
for (HostAndPort hostAndPort : hostAndPorts) {
|
||||
redisConnInfo.append(hostAndPort.toString()).append(";");
|
||||
}
|
||||
context.set(REDIS_CONN_INFO_KEY, redisConnInfo.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.jedis.v2;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-12.
|
||||
*/
|
||||
public class JedisClusterInterceptor extends JedisBaseInterceptor implements InstanceConstructorInterceptor {
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
StringBuilder redisConnInfo = new StringBuilder();
|
||||
if (interceptorContext.allArguments().length > 0) {
|
||||
if (interceptorContext.allArguments()[0] instanceof Set) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<HostAndPort> hostAndPorts = (Set<HostAndPort>) interceptorContext.allArguments()[0];
|
||||
for (HostAndPort hostAndPort : hostAndPorts) {
|
||||
redisConnInfo.append(hostAndPort.toString()).append(";");
|
||||
}
|
||||
} else if (interceptorContext.allArguments()[0] instanceof HostAndPort) {
|
||||
HostAndPort hostAndPort = (HostAndPort) interceptorContext.allArguments()[0];
|
||||
redisConnInfo.append(hostAndPort.toString()).append(";");
|
||||
}
|
||||
}
|
||||
context.set(REDIS_CONN_INFO_KEY, redisConnInfo.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.a.eye.skywalking.plugin.jedis.v2;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/12/1.
|
||||
*/
|
||||
public class JedisConstructorInterceptor4ShardInfoArg implements InstanceConstructorInterceptor {
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
String redisConnInfo;
|
||||
JedisShardInfo shardInfo = (JedisShardInfo) interceptorContext.allArguments()[0];
|
||||
redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort();
|
||||
context.set(REDIS_CONN_INFO_KEY, redisConnInfo);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.a.eye.skywalking.plugin.jedis.v2;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY;
|
||||
|
||||
public class JedisConstructorInterceptor4StringArg implements InstanceConstructorInterceptor {
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
String redisConnInfo;
|
||||
redisConnInfo = (String) interceptorContext.allArguments()[0];
|
||||
if (interceptorContext.allArguments().length > 1) {
|
||||
redisConnInfo += ":" + interceptorContext.allArguments()[1];
|
||||
}
|
||||
context.set(REDIS_CONN_INFO_KEY, redisConnInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.a.eye.skywalking.plugin.jedis.v2;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/12/1.
|
||||
*/
|
||||
public class JedisConstructorInterceptor4UriArg implements InstanceConstructorInterceptor {
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
String redisConnInfo;
|
||||
URI uri = (URI) interceptorContext.allArguments()[0];
|
||||
redisConnInfo = uri.getHost() + ":" + uri.getPort();
|
||||
context.set(REDIS_CONN_INFO_KEY, redisConnInfo);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.jedis.v2;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class JedisInterceptor extends JedisBaseInterceptor implements InstanceConstructorInterceptor {
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context,
|
||||
ConstructorInvokeContext interceptorContext) {
|
||||
String redisConnInfo = "";
|
||||
if (interceptorContext.allArguments().length > 0) {
|
||||
if (interceptorContext.allArguments()[0] instanceof String) {
|
||||
redisConnInfo = (String) interceptorContext.allArguments()[0];
|
||||
if (interceptorContext.allArguments().length > 1) {
|
||||
redisConnInfo += ":"
|
||||
+ (Integer) interceptorContext.allArguments()[1];
|
||||
}
|
||||
} else if (interceptorContext.allArguments()[0] instanceof JedisShardInfo) {
|
||||
JedisShardInfo shardInfo = (JedisShardInfo) interceptorContext
|
||||
.allArguments()[0];
|
||||
redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort();
|
||||
} else if (interceptorContext.allArguments()[0] instanceof URI) {
|
||||
URI uri = (URI) interceptorContext.allArguments()[0];
|
||||
redisConnInfo = uri.getHost() + ":" + uri.getPort();
|
||||
}
|
||||
}
|
||||
context.set(REDIS_CONN_INFO_KEY, redisConnInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ import com.a.eye.skywalking.plugin.interceptor.assist.SimpleObjectFirstInvokeInt
|
|||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
public abstract class JedisBaseInterceptor extends SimpleObjectFirstInvokeInterceptor {
|
||||
public class JedisMethodInterceptor extends SimpleObjectFirstInvokeInterceptor {
|
||||
protected static final String REDIS_CONN_INFO_KEY = "redisClusterConnInfo";
|
||||
|
||||
private static RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor();
|
||||
|
|
@ -5,6 +5,13 @@ import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint;
|
|||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.AnyMethodsMatcher;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
|
|
@ -14,29 +21,41 @@ public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginD
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint() {
|
||||
return new ConstructorInterceptPoint(){
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[] {new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> getConstructorMatcher() {
|
||||
return takesArgument(0, Set.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisClusterInterceptor";
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisClusterConstructorInterceptor4SetArg";
|
||||
}
|
||||
};
|
||||
}, new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> getConstructorMatcher() {
|
||||
return not(takesArgument(0, Set.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisClusterConstructorInterceptor4HostAndPortArg";
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
return new MethodMatcher[]{
|
||||
new AnyMethodsMatcher()
|
||||
};
|
||||
return new MethodMatcher[] {new AnyMethodsMatcher()};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisClusterInterceptor";
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,16 @@ package com.a.eye.skywalking.plugin.jedis.v2.define;
|
|||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.MethodsExclusiveMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.MethodsExclusiveMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.PrivateMethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
public class JedisPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
|
|
@ -16,37 +21,53 @@ public class JedisPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint() {
|
||||
return new ConstructorInterceptPoint() {
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[] {new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> getConstructorMatcher() {
|
||||
return takesArgument(0, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisInterceptor";
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorInterceptor4StringArg";
|
||||
}
|
||||
};
|
||||
}, new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> getConstructorMatcher() {
|
||||
return not(takesArgument(0, String.class).or(takesArgument(0, String.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorInterceptor4ShardInfoArgg";
|
||||
}
|
||||
}, new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> getConstructorMatcher() {
|
||||
return takesArgument(0, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorInterceptor4UriArg";
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
return new MethodMatcher[]{
|
||||
new MethodsExclusiveMatcher(
|
||||
new PrivateMethodMatcher(),
|
||||
new SimpleMethodMatcher("close"),
|
||||
new SimpleMethodMatcher("getDB"),
|
||||
new SimpleMethodMatcher("connect"),
|
||||
new SimpleMethodMatcher("setDataSource"),
|
||||
new SimpleMethodMatcher("resetState"),
|
||||
new SimpleMethodMatcher("clusterSlots"),
|
||||
new SimpleMethodMatcher("checkIsInMultiOrPipeline")
|
||||
)
|
||||
};
|
||||
return new MethodMatcher[] {new MethodsExclusiveMatcher(new PrivateMethodMatcher(), new SimpleMethodMatcher("close"), new SimpleMethodMatcher("getDB"),
|
||||
new SimpleMethodMatcher("connect"), new SimpleMethodMatcher("setDataSource"), new SimpleMethodMatcher("resetState"),
|
||||
new SimpleMethodMatcher("clusterSlots"), new SimpleMethodMatcher("checkIsInMultiOrPipeline"))};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisInterceptor";
|
||||
return "com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,9 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
public class JedisClusterTest {
|
||||
@Test
|
||||
public void test() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException,
|
||||
PluginException {
|
||||
TracingBootstrap.main(new String[] {"JedisClusterTest"});
|
||||
TracingBootstrap.main(new String[] {"com.a.eye.skywalking.plugin.jedis.v2.JedisClusterTest"});
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ClassNotFoundException, SQLException, InterruptedException {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.sql.SQLException;
|
||||
|
||||
public class JedisTest {
|
||||
@Test
|
||||
public void test() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException,
|
||||
PluginException {
|
||||
TracingBootstrap.main(new String[] {"JedisTest"});
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@ import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint;
|
|||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
|
||||
public class MotanClientDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
|
|
@ -13,29 +17,32 @@ public class MotanClientDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint() {
|
||||
return new ConstructorInterceptPoint() {
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[] {new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> getConstructorMatcher() {
|
||||
return any();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.motan.MotanClientInterceptor";
|
||||
}
|
||||
};
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
return new MethodMatcher[] {new SimpleMethodMatcher("call")};
|
||||
}
|
||||
return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
return new MethodMatcher[] {new SimpleMethodMatcher("call")};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.motan.MotanClientInterceptor";
|
||||
}
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.motan.MotanClientInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@ import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint;
|
|||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
|
||||
public class MotanServerDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
|
|
@ -14,18 +18,23 @@ public class MotanServerDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint() {
|
||||
return new ConstructorInterceptPoint() {
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[] {new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> getConstructorMatcher() {
|
||||
return any();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.motan.MotanServerInterceptor";
|
||||
}
|
||||
};
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
return new MethodMatcher[] {new SimpleMethodMatcher("call")};
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class TomcatPluginDefine extends ClassInstanceMethodsEnhancePluginDefine
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint getConstructorsInterceptPoint() {
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue