修复大量方法的编译警告

This commit is contained in:
wusheng 2016-06-08 10:18:23 +08:00
parent 5559261516
commit 6ad8cb4aa7
17 changed files with 64 additions and 109 deletions

View File

@ -1,9 +1,10 @@
package com.ai.cloud.skywalking.plugin.interceptor;
import com.ai.cloud.skywalking.plugin.PluginCfg;
import com.ai.cloud.skywalking.util.StringUtil;
import static net.bytebuddy.matcher.ElementMatchers.any;
import java.util.List;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
@ -13,12 +14,12 @@ import net.bytebuddy.implementation.SuperMethodCall;
import net.bytebuddy.implementation.bind.annotation.FieldProxy;
import net.bytebuddy.pool.TypePool;
import net.bytebuddy.pool.TypePool.Resolution;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import static net.bytebuddy.matcher.ElementMatchers.any;
import com.ai.cloud.skywalking.plugin.PluginCfg;
import com.ai.cloud.skywalking.util.StringUtil;
public class EnhanceClazz4Interceptor {
private static Logger logger = LogManager
@ -115,15 +116,15 @@ public class EnhanceClazz4Interceptor {
FieldGetter.class,
FieldSetter.class))));
MethodNameMatcher[] methodNameList = define.getBeInterceptedMethods();
MethodNameMatcher[] methodMatchers = define.getBeInterceptedMethodsMatchers();
ClassMethodInterceptor classMethodInterceptor = new ClassMethodInterceptor(
interceptor);
for (MethodNameMatcher method : methodNameList) {
for (MethodNameMatcher methodMatcher : methodMatchers) {
logger.debug("prepare to enhance class {} method [{}] ",
enhanceOriginClassName, method.getMethodMatchDescribe());
enhanceOriginClassName, methodMatcher.getMethodMatchDescribe());
newClassBuilder = newClassBuilder.method(
method.<MethodDescription>builderMatcher()).intercept(
methodMatcher.builderMatcher()).intercept(
MethodDelegation.to(classMethodInterceptor));
}

View File

@ -1,45 +0,0 @@
package com.ai.cloud.skywalking.plugin.interceptor;
public class InterceptPoint {
private String methodName;
private int argNum = -1;
private Class<?>[] argTypeArray;
public InterceptPoint(String methodName) {
super();
this.methodName = methodName;
}
public InterceptPoint(String methodName, int argNum) {
this(methodName);
this.argNum = argNum;
}
public InterceptPoint(String methodName, Class<?>... args) {
this(methodName);
this.argTypeArray = args;
}
public String getMethodName() {
return methodName;
}
public int getArgNum() {
return argNum;
}
public Class<?>[] getArgTypeArray() {
return argTypeArray;
}
public void setArgNum(int argNum) {
this.argNum = argNum;
}
public void setArgTypeList(Class<?>... args){
argTypeArray = args;
}
}

View File

@ -13,7 +13,7 @@ public interface InterceptorDefine {
*
* @return
*/
public MethodNameMatcher[] getBeInterceptedMethods();
public MethodNameMatcher[] getBeInterceptedMethodsMatchers();
/**
* 返回增强拦截器的实现<br/>

View File

@ -1,8 +1,9 @@
package com.ai.cloud.skywalking.plugin.interceptor;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
public abstract class MethodNameMatcher<T> {
public abstract class MethodNameMatcher {
private String methodMatchDescribe;
@ -24,7 +25,7 @@ public abstract class MethodNameMatcher<T> {
this.methodMatchDescribe = methodMatchDescribe;
}
public abstract <T> ElementMatcher<T> builderMatcher();
public abstract ElementMatcher<MethodDescription> builderMatcher();
protected String getMethodMatchDescribe() {
return methodMatchDescribe;

View File

@ -1,9 +1,10 @@
package com.ai.cloud.skywalking.plugin.interceptor.matcher;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import static net.bytebuddy.matcher.ElementMatchers.any;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import static net.bytebuddy.matcher.ElementMatchers.any;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
public class AnyMethodMatcher extends MethodNameMatcher {
@ -12,7 +13,7 @@ public class AnyMethodMatcher extends MethodNameMatcher {
}
@Override
public ElementMatcher builderMatcher() {
public ElementMatcher<MethodDescription> builderMatcher() {
return any();
}
}

View File

@ -1,9 +1,12 @@
package com.ai.cloud.skywalking.plugin.interceptor.matcher;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import static net.bytebuddy.matcher.ElementMatchers.*;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
public class ExclusionNameMatcher extends MethodNameMatcher {
@ -15,13 +18,13 @@ public class ExclusionNameMatcher extends MethodNameMatcher {
super(methodMatchDescribe, argNum);
}
public ExclusionNameMatcher(String methodMatchDescribe, Class[] argTypeArray) {
public ExclusionNameMatcher(String methodMatchDescribe, Class<?>[] argTypeArray) {
super(methodMatchDescribe, argTypeArray);
}
@Override
public ElementMatcher builderMatcher() {
ElementMatcher.Junction matcher = not(named(getMethodMatchDescribe()));
public ElementMatcher<MethodDescription> builderMatcher() {
ElementMatcher.Junction<MethodDescription> matcher = not(named(getMethodMatchDescribe()));
if (getArgTypeArray() != null) {
matcher.and(takesArguments(getArgTypeArray()));

View File

@ -1,10 +1,11 @@
package com.ai.cloud.skywalking.plugin.interceptor.matcher;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import net.bytebuddy.matcher.ElementMatcher;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
public class FullNameMatcher extends MethodNameMatcher {
@ -21,8 +22,8 @@ public class FullNameMatcher extends MethodNameMatcher {
}
@Override
public ElementMatcher builderMatcher() {
ElementMatcher.Junction matcher = named(getMethodMatchDescribe());
public ElementMatcher<MethodDescription> builderMatcher() {
ElementMatcher.Junction<MethodDescription> matcher = named(getMethodMatchDescribe());
if (getArgTypeArray() != null) {
matcher.and(takesArguments(getArgTypeArray()));

View File

@ -1,10 +1,11 @@
package com.ai.cloud.skywalking.plugin.interceptor.matcher;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import net.bytebuddy.matcher.ElementMatcher;
import static net.bytebuddy.matcher.ElementMatchers.nameMatches;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
public class RegexNameMatcher extends MethodNameMatcher {
@ -16,13 +17,13 @@ public class RegexNameMatcher extends MethodNameMatcher {
super(methodMatchDescribe, argNum);
}
public RegexNameMatcher(String methodMatchDescribe, Class[] argTypeArray) {
public RegexNameMatcher(String methodMatchDescribe, Class<?>[] argTypeArray) {
super(methodMatchDescribe, argTypeArray);
}
@Override
public ElementMatcher builderMatcher() {
ElementMatcher.Junction matcher = nameMatches(getMethodMatchDescribe());
public ElementMatcher<MethodDescription> builderMatcher() {
ElementMatcher.Junction<MethodDescription> matcher = nameMatches(getMethodMatchDescribe());
if (getArgTypeArray() != null) {
matcher.and(takesArguments(getArgTypeArray()));

View File

@ -1,6 +1,5 @@
package com.ai.cloud.skywalking.sender;
import com.ai.cloud.skywalking.util.ProtocolPackager;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
@ -19,10 +18,10 @@ import io.netty.handler.codec.bytes.ByteArrayEncoder;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import com.ai.cloud.skywalking.selfexamination.HeathReading;
import com.ai.cloud.skywalking.selfexamination.SDKHealthCollector;
import com.ai.cloud.skywalking.util.ProtocolPackager;
public class DataSender implements IDataSender {
private EventLoopGroup group;

View File

@ -1,7 +1,6 @@
package test.ai.cloud.plugin;
import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher;
@ -14,7 +13,7 @@ public class TestInterceptorDefine implements InterceptorDefine {
}
@Override
public MethodNameMatcher[] getBeInterceptedMethods() {
public MethodNameMatcher[] getBeInterceptedMethodsMatchers() {
return new MethodNameMatcher[] { new FullNameMatcher("printabc") };
}

View File

@ -1,11 +1,10 @@
package org.skywalking.httpClient.v4.plugin.dubbox.rest.attachment;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import org.skywalking.httpClient.v4.plugin.HttpClientExecuteInterceptor;
import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
public class DubboxRestHeadSetterAttachment implements InterceptorDefine {
@ -21,7 +20,7 @@ public class DubboxRestHeadSetterAttachment implements InterceptorDefine {
}
@Override
public MethodNameMatcher[] getBeInterceptedMethods() {
public MethodNameMatcher[] getBeInterceptedMethodsMatchers() {
return null;
}

View File

@ -1,6 +1,5 @@
package org.skywalking.httpClient.v4.plugin.define;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher;
@ -18,7 +17,7 @@ public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine {
*
*/
@Override
public MethodNameMatcher[] getBeInterceptedMethods() {
public MethodNameMatcher[] getBeInterceptedMethodsMatchers() {
return new MethodNameMatcher[] {
new FullNameMatcher("doExecute")};
}

View File

@ -1,6 +1,5 @@
package org.skywalking.httpClient.v4.plugin.define;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher;
@ -16,7 +15,7 @@ public class DefaultRequestDirectorPluginDefine extends HttpClientPluginDefine {
}
@Override
public MethodNameMatcher[] getBeInterceptedMethods() {
public MethodNameMatcher[] getBeInterceptedMethodsMatchers() {
return new MethodNameMatcher[] {
new FullNameMatcher("execute")};
}

View File

@ -5,7 +5,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher;
public class InternalHttpClientPluginDefine extends HttpClientPluginDefine {
@Override
public MethodNameMatcher[] getBeInterceptedMethods() {
public MethodNameMatcher[] getBeInterceptedMethodsMatchers() {
return new MethodNameMatcher[]{new FullNameMatcher("doExecute")};
}

View File

@ -5,7 +5,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher;
public class MinimalHttpClientPluginDefine extends HttpClientPluginDefine {
@Override
public MethodNameMatcher[] getBeInterceptedMethods() {
public MethodNameMatcher[] getBeInterceptedMethodsMatchers() {
return new MethodNameMatcher[]{new FullNameMatcher("doExecute")};
}

View File

@ -1,29 +1,27 @@
package org.skywalking.jedis.v2.plugin.define;
import org.skywalking.jedis.v2.plugin.JedisInterceptor;
import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import com.ai.cloud.skywalking.plugin.interceptor.matcher.ExclusionNameMatcher;
import org.skywalking.jedis.v2.plugin.JedisInterceptor;
import com.ai.cloud.skywalking.plugin.interceptor.matcher.AnyMethodMatcher;
public class JedisPluginDefine implements InterceptorDefine {
@Override
public String getBeInterceptedClassName() {
return "redis.clients.jedis.Jedis";
}
@Override
public String getBeInterceptedClassName() {
return "redis.clients.jedis.Jedis";
}
@Override
public MethodNameMatcher[] getBeInterceptedMethods() {
return new MethodNameMatcher[]{
new ExclusionNameMatcher("set"),
};
}
@Override
public MethodNameMatcher[] getBeInterceptedMethodsMatchers() {
return new MethodNameMatcher[] { new AnyMethodMatcher() };
}
@Override
public IAroundInterceptor instance() {
return new JedisInterceptor();
}
@Override
public IAroundInterceptor instance() {
return new JedisInterceptor();
}
}

View File

@ -1,7 +1,6 @@
package com.ai.cloud.skywalking.plugin.mysql;
import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine;
import com.ai.cloud.skywalking.plugin.interceptor.MethodNameMatcher;
import com.ai.cloud.skywalking.plugin.interceptor.matcher.FullNameMatcher;
@ -14,7 +13,7 @@ public class ConnectionPluginDefine implements InterceptorDefine {
}
@Override
public MethodNameMatcher[] getBeInterceptedMethods() {
public MethodNameMatcher[] getBeInterceptedMethodsMatchers() {
return new MethodNameMatcher[] { new FullNameMatcher("createStatement", 2),
new FullNameMatcher("prepareStatement", 3),
new FullNameMatcher("prepareCall", 3),