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

This commit is contained in:
wusheng 2016-07-26 09:56:30 +08:00
parent f08ca13a15
commit 2189ce5190
1 changed files with 25 additions and 23 deletions

View File

@ -2,42 +2,44 @@ package com.ai.cloud.skywalking.plugin;
import com.ai.cloud.skywalking.logging.LogManager;
import com.ai.cloud.skywalking.logging.Logger;
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassEnhancePluginDefine;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Map;
/**
* 替代应用函数的main函数入口确保在程序入口处运行 <br/>
* 用于替代-javaagent的另一种模式 <br/>
*
* @author wusheng
* 主要用于插件的本地化调试与运行<br/>
*
*
* @author wusheng
*/
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,
IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SecurityException, ClassNotFoundException {
if (args.length == 0) {
throw new RuntimeException(
"bootstrap failure. need args[0] to be main class.");
}
public static void main(String[] args)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
SecurityException, ClassNotFoundException {
if (args.length == 0) {
throw new RuntimeException("bootstrap failure. need args[0] to be main class.");
}
try {
PluginBootstrap bootstrap = new PluginBootstrap();
bootstrap.loadPlugins();
} catch (Throwable t) {
logger.error("PluginBootstrap start failure.", t);
}
PluginBootstrap bootstrap = new PluginBootstrap();
Map<String, ClassEnhancePluginDefine> pluginDefineMap = bootstrap.loadPlugins();
String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
for(String enhanceClassName : pluginDefineMap.keySet()){
//init ctClass
//enhance class
}
Class.forName(args[0]).getMethod("main", String[].class)
.invoke(null, new Object[]{newArgs});
}
String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
Class.forName(args[0]).getMethod("main", String[].class).invoke(null, new Object[] {newArgs});
}
}