refactory MultiClassNameMatch code
This commit is contained in:
parent
97b577864f
commit
c6e593f6f4
|
|
@ -17,14 +17,12 @@
|
|||
*/
|
||||
|
||||
|
||||
package org.apache.skywalking.apm.plugin.jdbc.mysql.define;
|
||||
package org.apache.skywalking.apm.agent.core.plugin.match;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.IndirectMatch;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInst
|
|||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
|
||||
|
||||
/**
|
||||
* {@link CallableInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the {@link
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.define;
|
|||
import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
|
||||
import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
|
||||
|
||||
/**
|
||||
* {@link DriverInstrumentation} presents that skywalking intercepts {@link com.mysql.jdbc.Driver}.
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.define;
|
|||
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
|
||||
import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
|
||||
|
||||
/**
|
||||
* {@link Mysql5xConnectionInstrumentation } interceptor {@link com.mysql.cj.jdbc.ConnectionImpl} and
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
|
|||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
|
||||
|
||||
/**
|
||||
* {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
|
|||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
|
||||
|
||||
/**
|
||||
* {@link StatementInstrumentation} intercepts the following methods in the {@link
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
|
||||
import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
|
||||
|
||||
/**
|
||||
* {@link AbstractJdbc2StatementInstrumentation} intercept the following methods that the class which extend {@link
|
||||
|
|
@ -61,18 +62,29 @@ public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsE
|
|||
new InstanceMethodsInterceptPoint() {
|
||||
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("execute").and(takesArguments(0))
|
||||
.or(named("execute").and(takesArguments(1)))
|
||||
.or(named("executeBatch"))
|
||||
.or(named("executeQuery").and(takesArguments(0)))
|
||||
.or(named("executeQuery").and(takesArguments(1)))
|
||||
.or(named("executeUpdate").and(takesArguments(0)))
|
||||
.or(named("executeUpdate").and(takesArguments(1)));
|
||||
.or(named("executeUpdate").and(takesArguments(0)));
|
||||
}
|
||||
|
||||
@Override public String getMethodsInterceptor() {
|
||||
return PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
|
||||
}
|
||||
|
||||
@Override public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("execute").and(takesArguments(1))
|
||||
.or(named("executeQuery").and(takesArguments(1)))
|
||||
.or(named("executeUpdate").and(takesArguments(1)));
|
||||
}
|
||||
|
||||
@Override public String getMethodsInterceptor() {
|
||||
return PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
|
||||
}
|
||||
|
||||
@Override public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
|
||||
import static org.apache.skywalking.apm.plugin.jdbc.postgresql.define.MultiClassNameMatch.byMultiClassMatch;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
|
||||
|
||||
/**
|
||||
* {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.skywalking.apm.plugin.jdbc.postgresql.define;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.IndirectMatch;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
/**
|
||||
* Match class with a given set of classes.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class MultiClassNameMatch implements IndirectMatch {
|
||||
|
||||
private List<String> matchClassNames;
|
||||
|
||||
private MultiClassNameMatch(String[] classNames) {
|
||||
if (classNames == null || classNames.length == 0) {
|
||||
throw new IllegalArgumentException("match class names is null");
|
||||
}
|
||||
this.matchClassNames = Arrays.asList(classNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher.Junction buildJunction() {
|
||||
ElementMatcher.Junction junction = null;
|
||||
for (String name : matchClassNames) {
|
||||
if (junction == null) {
|
||||
junction = named(name);
|
||||
} else {
|
||||
junction = junction.or(named(name));
|
||||
}
|
||||
}
|
||||
return junction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(TypeDescription typeDescription) {
|
||||
return matchClassNames.contains(typeDescription.getTypeName());
|
||||
}
|
||||
|
||||
public static ClassMatch byMultiClassMatch(String... classNames) {
|
||||
return new MultiClassNameMatch(classNames);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue