提交 2189ce51 编写于 作者: wu-sheng's avatar wu-sheng

提供一个TracingBootstrap的实现方式的指导

上级 f08ca13a
...@@ -2,42 +2,44 @@ package com.ai.cloud.skywalking.plugin; ...@@ -2,42 +2,44 @@ package com.ai.cloud.skywalking.plugin;
import com.ai.cloud.skywalking.logging.LogManager; import com.ai.cloud.skywalking.logging.LogManager;
import com.ai.cloud.skywalking.logging.Logger; import com.ai.cloud.skywalking.logging.Logger;
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassEnhancePluginDefine;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
/** /**
* 替代应用函数的main函数入口,确保在程序入口处运行 <br/> * 替代应用函数的main函数入口,确保在程序入口处运行 <br/>
* 用于替代-javaagent的另一种模式 <br/> * 用于替代-javaagent的另一种模式 <br/>
* * 主要用于插件的本地化调试与运行<br/>
* @author wusheng *
* *
* @author wusheng
*/ */
public class TracingBootstrap { public class TracingBootstrap {
private static Logger logger = LogManager.getLogger(TracingBootstrap.class); private static Logger logger = LogManager.getLogger(TracingBootstrap.class);
private TracingBootstrap() { private TracingBootstrap() {
} }
public static void main(String[] args) throws IllegalAccessException, public static void main(String[] args)
IllegalArgumentException, InvocationTargetException, throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
NoSuchMethodException, SecurityException, ClassNotFoundException { SecurityException, ClassNotFoundException {
if (args.length == 0) { if (args.length == 0) {
throw new RuntimeException( throw new RuntimeException("bootstrap failure. need args[0] to be main class.");
"bootstrap failure. need args[0] to be main class."); }
}
PluginBootstrap bootstrap = new PluginBootstrap();
try { Map<String, ClassEnhancePluginDefine> pluginDefineMap = bootstrap.loadPlugins();
PluginBootstrap bootstrap = new PluginBootstrap();
bootstrap.loadPlugins(); for(String enhanceClassName : pluginDefineMap.keySet()){
} catch (Throwable t) { //init ctClass
logger.error("PluginBootstrap start failure.", t); //enhance class
} }
String[] newArgs = Arrays.copyOfRange(args, 1, args.length); String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
Class.forName(args[0]).getMethod("main", String[].class) Class.forName(args[0]).getMethod("main", String[].class).invoke(null, new Object[] {newArgs});
.invoke(null, new Object[]{newArgs}); }
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册