增加一个见证者类的代码。用于后期标定不同版本的插件使用。
This commit is contained in:
parent
2f86b1b3ee
commit
3ee2676268
|
|
@ -1,27 +1,26 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor;
|
||||
|
||||
import static com.ai.cloud.skywalking.plugin.PluginBootstrap.CLASS_TYPE_POOL;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.plugin.IPlugin;
|
||||
import com.ai.cloud.skywalking.plugin.PluginException;
|
||||
import com.ai.cloud.skywalking.util.StringUtil;
|
||||
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.Resolution;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.IPlugin;
|
||||
import com.ai.cloud.skywalking.plugin.PluginException;
|
||||
import com.ai.cloud.skywalking.util.StringUtil;
|
||||
import static com.ai.cloud.skywalking.plugin.PluginBootstrap.CLASS_TYPE_POOL;
|
||||
|
||||
public abstract class AbstractClassEnhancePluginDefine implements IPlugin {
|
||||
private static Logger logger = LogManager.getLogger(AbstractClassEnhancePluginDefine.class);
|
||||
|
||||
@Override
|
||||
public void define() throws PluginException {
|
||||
String interceptorDefineClassName = this.getClass().getName();
|
||||
|
||||
String enhanceOriginClassName = getBeInterceptedClassName();
|
||||
private static Logger logger = LogManager.getLogger(AbstractClassEnhancePluginDefine.class);
|
||||
|
||||
@Override
|
||||
public void define() throws PluginException {
|
||||
String interceptorDefineClassName = this.getClass().getName();
|
||||
|
||||
String enhanceOriginClassName = enhanceClassName();
|
||||
if (StringUtil.isEmpty(enhanceOriginClassName)) {
|
||||
logger.warn("classname of being intercepted is not defined by {}.",
|
||||
interceptorDefineClassName);
|
||||
|
|
@ -38,13 +37,27 @@ public abstract class AbstractClassEnhancePluginDefine implements IPlugin {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* find witness classes for enhance class
|
||||
*/
|
||||
String[] witnessClasses = witnessClasses();
|
||||
if(witnessClasses != null) {
|
||||
for (String witnessClass : witnessClasses) {
|
||||
Resolution witnessClassResolution = CLASS_TYPE_POOL.describe(witnessClass);
|
||||
if (!witnessClassResolution.isResolved()) {
|
||||
logger.warn("enhance class {} by plugin {} is not working. Because witness class {} is not existed.", enhanceOriginClassName, interceptorDefineClassName, witnessClass);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* find origin class source code for interceptor
|
||||
*/
|
||||
DynamicType.Builder<?> newClassBuilder = new ByteBuddy()
|
||||
.rebase(resolution.resolve(),
|
||||
ClassFileLocator.ForClassLoader.ofClassPath());
|
||||
|
||||
|
||||
newClassBuilder = this.enhance(enhanceOriginClassName, newClassBuilder);
|
||||
|
||||
/**
|
||||
|
|
@ -59,14 +72,24 @@ public abstract class AbstractClassEnhancePluginDefine implements IPlugin {
|
|||
|
||||
logger.debug("enhance class {} by {} completely.",
|
||||
enhanceOriginClassName, interceptorDefineClassName);
|
||||
}
|
||||
|
||||
protected abstract DynamicType.Builder<?> enhance(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回要被增强的类,应当返回类全名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getBeInterceptedClassName();
|
||||
protected abstract DynamicType.Builder<?> enhance(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException;
|
||||
|
||||
/**
|
||||
* 返回要被增强的类,应当返回类全名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String enhanceClassName();
|
||||
|
||||
/**
|
||||
* 返回一个类名的列表
|
||||
* 如果列表中的类在JVM中存在,则enhance可以会尝试生效
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String[] witnessClasses(){
|
||||
return new String[]{};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.PrivateMethodMatcher;
|
|||
*/
|
||||
public class TestMatcherDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
public String getBeInterceptedClassName() {
|
||||
public String enhanceClassName() {
|
||||
return "test.ai.cloud.matcher.TestMatcherClass";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
|||
public class TestInterceptorDefine extends ClassEnhancePluginDefine {
|
||||
|
||||
@Override
|
||||
public String getBeInterceptedClassName() {
|
||||
public String enhanceClassName() {
|
||||
return "test.ai.cloud.plugin.BeInterceptedClass";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class DubboPluginDefine extends ClassStaticMethodsEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String getBeInterceptedClassName() {
|
||||
protected String enhanceClassName() {
|
||||
return "com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
|||
public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine {
|
||||
|
||||
@Override
|
||||
public String getBeInterceptedClassName() {
|
||||
public String enhanceClassName() {
|
||||
return "org.apache.http.impl.client.AbstractHttpClient";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class DefaultRequestDirectorPluginDefine extends HttpClientPluginDefine {
|
|||
* since 4.3, this class is Deprecated.
|
||||
*/
|
||||
@Override
|
||||
public String getBeInterceptedClassName() {
|
||||
public String enhanceClassName() {
|
||||
return "org.apache.http.impl.client.DefaultRequestDirector";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class InternalHttpClientPluginDefine extends HttpClientPluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getBeInterceptedClassName() {
|
||||
public String enhanceClassName() {
|
||||
return "org.apache.http.impl.client.InternalHttpClient";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class MinimalHttpClientPluginDefine extends HttpClientPluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getBeInterceptedClassName() {
|
||||
public String enhanceClassName() {
|
||||
return "org.apache.http.impl.client.MinimalHttpClient";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.AnyMethodsMatcher;
|
|||
public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
@Override
|
||||
public String getBeInterceptedClassName() {
|
||||
public String enhanceClassName() {
|
||||
return "redis.clients.jedis.JedisCluster";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
|||
public class JedisPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
@Override
|
||||
public String getBeInterceptedClassName() {
|
||||
public String enhanceClassName() {
|
||||
return "redis.clients.jedis.Jedis";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue