diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/AnyMethodMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/AnyMethodsMatcher.java similarity index 72% rename from skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/AnyMethodMatcher.java rename to skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/AnyMethodsMatcher.java index 8e6a31d45..12d1b5a86 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/AnyMethodMatcher.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/AnyMethodsMatcher.java @@ -1,14 +1,13 @@ package com.ai.cloud.skywalking.plugin.interceptor.matcher; -import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import static net.bytebuddy.matcher.ElementMatchers.any; -public class AnyMethodMatcher extends ExclusiveObjectDefaultMethodMatcher { +public class AnyMethodsMatcher extends ExclusiveObjectDefaultMethodsMatcher { - public AnyMethodMatcher() { + public AnyMethodsMatcher() { super("any method"); } diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/ExclusiveObjectDefaultMethodMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/ExclusiveObjectDefaultMethodMatcher.java deleted file mode 100644 index f0caa55c6..000000000 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/ExclusiveObjectDefaultMethodMatcher.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ai.cloud.skywalking.plugin.interceptor.matcher; - -import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.not; - -public abstract class ExclusiveObjectDefaultMethodMatcher extends MethodMatcher { - - private static final String[] EXCLUSIVE_DEFAULT_METHOD_NAME = new String[]{ - "finalize", "wait", "equals", - "toString", "hashCode", "getClass", - "clone", "notify", "notifyAll" - }; - - public ExclusiveObjectDefaultMethodMatcher(String methodMatchDescribe) { - super(methodMatchDescribe); - } - - @Override - public ElementMatcher.Junction buildMatcher() { - return this.match().and(excludeObjectDefaultMethod()); - } - - protected ElementMatcher.Junction excludeObjectDefaultMethod() { - ElementMatcher.Junction exclusiveMatcher = null; - for (String methodName : EXCLUSIVE_DEFAULT_METHOD_NAME) { - if (exclusiveMatcher == null) { - exclusiveMatcher = named(methodName); - continue; - } - - exclusiveMatcher = exclusiveMatcher.or(named(methodName)); - - } - return not(exclusiveMatcher); - } - - public abstract ElementMatcher.Junction match(); - - -} diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/ExclusiveObjectDefaultMethodsMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/ExclusiveObjectDefaultMethodsMatcher.java new file mode 100644 index 000000000..6da3fbf02 --- /dev/null +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/ExclusiveObjectDefaultMethodsMatcher.java @@ -0,0 +1,51 @@ +package com.ai.cloud.skywalking.plugin.interceptor.matcher; + +import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.not; + +public abstract class ExclusiveObjectDefaultMethodsMatcher extends MethodMatcher { + + private static final MethodMatcher[] EXCLUSIVE_DEFAULT_METHOD_NAME = new MethodMatcher[]{ + new SimpleMethodMatcher(Modifier.Public, "finalize", 0), + new SimpleMethodMatcher(Modifier.Public, "wait", long.class, int.class), + new SimpleMethodMatcher(Modifier.Public, "wait", long.class), + new SimpleMethodMatcher(Modifier.Public, "wait", 0), + new SimpleMethodMatcher(Modifier.Public, "equals", Object.class), + new SimpleMethodMatcher(Modifier.Public, "toString", 0), + new SimpleMethodMatcher(Modifier.Public, "hashCode", 0), + new SimpleMethodMatcher(Modifier.Public, "getClass", 0), + new SimpleMethodMatcher(Modifier.Public, "clone", 0), + new SimpleMethodMatcher(Modifier.Public, "notify", 0), + new SimpleMethodMatcher(Modifier.Public, "notifyAll", 0) + }; + + public ExclusiveObjectDefaultMethodsMatcher(String methodMatchDescribe) { + super(methodMatchDescribe); + } + + @Override + public ElementMatcher.Junction buildMatcher() { + return this.match().and(excludeObjectDefaultMethod()); + } + + protected ElementMatcher.Junction excludeObjectDefaultMethod() { + ElementMatcher.Junction exclusiveMatcher = null; + for (MethodMatcher methodMatcher : EXCLUSIVE_DEFAULT_METHOD_NAME) { + if (exclusiveMatcher == null) { + exclusiveMatcher = methodMatcher.buildMatcher(); + continue; + } + + exclusiveMatcher = exclusiveMatcher.or(methodMatcher.buildMatcher()); + + } + return not(exclusiveMatcher); + } + + public abstract ElementMatcher.Junction match(); + + +} diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodRegexMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodRegexMatcher.java index 61876eef3..451341cfc 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodRegexMatcher.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodRegexMatcher.java @@ -16,7 +16,7 @@ public class MethodRegexMatcher extends MethodMatcher { super(methodMatchDescribe, argNum); } - public MethodRegexMatcher(String methodMatchDescribe, Class[] argTypeArray) { + public MethodRegexMatcher(String methodMatchDescribe, Class... argTypeArray) { super(methodMatchDescribe, argTypeArray); } @@ -28,7 +28,7 @@ public class MethodRegexMatcher extends MethodMatcher { super(modifier, methodMatchDescribe, argNum); } - public MethodRegexMatcher(Modifier modifier, String methodMatchDescribe, Class[] argTypeArray) { + public MethodRegexMatcher(Modifier modifier, String methodMatchDescribe, Class... argTypeArray) { super(modifier, methodMatchDescribe, argTypeArray); } diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java index 55b544f54..120a04447 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java @@ -10,10 +10,7 @@ import java.util.List; import static net.bytebuddy.matcher.ElementMatchers.not; -/** - * Created by xin on 16-6-8. - */ -public class MethodsExclusiveMatcher extends ExclusiveObjectDefaultMethodMatcher { +public class MethodsExclusiveMatcher extends ExclusiveObjectDefaultMethodsMatcher { private List matchers = new ArrayList(); diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java index 6189d332e..d651475d5 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java @@ -29,7 +29,7 @@ public class SimpleMethodMatcher extends MethodMatcher { super(modifier, methodMatchDescribe, argNum); } - public SimpleMethodMatcher(Modifier modifier, String methodMatchDescribe, Class[] argTypeArray) { + public SimpleMethodMatcher(Modifier modifier, String methodMatchDescribe, Class... argTypeArray) { super(modifier, methodMatchDescribe, argTypeArray); } diff --git a/skywalking-api/src/test/java/test/ai/cloud/matcher/ExclusionMatcherTest.java b/skywalking-api/src/test/java/test/ai/cloud/matcher/ExclusionMatcherTest.java index 7f2334f47..c95a3b6c8 100644 --- a/skywalking-api/src/test/java/test/ai/cloud/matcher/ExclusionMatcherTest.java +++ b/skywalking-api/src/test/java/test/ai/cloud/matcher/ExclusionMatcherTest.java @@ -6,7 +6,7 @@ import com.ai.cloud.skywalking.plugin.PluginBootstrap; public class ExclusionMatcherTest extends TestCase{ - public void testMatcher() throws ClassNotFoundException, IllegalAccessException, InstantiationException { + public void testMatcher() throws ClassNotFoundException, IllegalAccessException, InstantiationException, InterruptedException { new PluginBootstrap().start(); TestMatcherClass testMatcherClass = (TestMatcherClass) Class.forName("test.ai.cloud.matcher.TestMatcherClass").newInstance(); @@ -15,6 +15,7 @@ public class ExclusionMatcherTest extends TestCase{ testMatcherClass.get("a"); testMatcherClass.find(); System.out.println(testMatcherClass.toString()); + testMatcherClass.equals(new TestMatcherClass()); } } diff --git a/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherClass.java b/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherClass.java index f4b2a86af..e646944e9 100644 --- a/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherClass.java +++ b/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherClass.java @@ -30,4 +30,10 @@ public class TestMatcherClass { public String toString() { return "Call toString()"; } + + @Override + public boolean equals(Object obj) { + System.out.println("equals(Object obj)"); + return true; + } } diff --git a/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherDefine.java b/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherDefine.java index 27cf7c78b..2c72e4943 100644 --- a/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherDefine.java +++ b/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherDefine.java @@ -3,7 +3,6 @@ package test.ai.cloud.matcher; import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor; import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine; import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher; -import com.ai.cloud.skywalking.plugin.interceptor.matcher.AnyMethodMatcher; import com.ai.cloud.skywalking.plugin.interceptor.matcher.MethodsExclusiveMatcher; import com.ai.cloud.skywalking.plugin.interceptor.matcher.PrivateMethodMatcher; import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher; @@ -26,7 +25,7 @@ public class TestMatcherDefine implements InterceptorDefine { }; //return new MethodMatcher[] { new SimpleMethodMatcher(Modifier.Public, "printabc", new Class[]{String.class, String.class}) }; //return new MethodMatcher[] { new PrivateMethodMatcher()}; - //return new MethodMatcher[]{new AnyMethodMatcher()}; + //return new MethodMatcher[]{new AnyMethodsMatcher()}; //return new MethodMatcher[]{new MethodsExclusiveMatcher(new SimpleMethodMatcher("set"), new SimpleMethodMatcher(MethodMatcher.Modifier.Public,"get"))}; }