获取agent jar包路径的方法:

findPath();

private static File findPath() throws AgentPackageNotFoundException {
String classResourcePath = AgentPackagePath.class.getName().replaceAll("\\.", "/") + ".class";// .../.../.../.../.../AgentPackagePath.class URL resource = ClassLoader.getSystemClassLoader().getResource(classResourcePath);
// jar:file:/.../.../.../.../.../...jar!/.../.../.../.../.../AgentPackagePath.class
if (resource != null) {
String urlString = resource.toString();
int insidePathIndex = urlString.indexOf('!');
boolean isInJar = insidePathIndex > -1;
if (isInJar) {
urlString = urlString.substring(urlString.indexOf("file:"), insidePathIndex);
// urlString = file:/.../.../.../cat-agent.jar
File agentJarFile = null;
try {
agentJarFile = new File(new URL(urlString).toURI());
} catch (MalformedURLException e) {
...
}
if (agentJarFile.exists()) {
return agentJarFile.getParentFile();
}
} else {
...
}
}
...
}

加载plugin:

public List<AbstractClassEnhancePluginDefine> loadPlugins() throws AgentPackageNotFoundException {
AgentClassLoader.initDefaultLoader(); PluginResourcesResolver resolver = new PluginResourcesResolver();
List<URL> resources = resolver.getResources();
...
...
for (URL pluginUrl : resources) {
try {
PluginCfg.INSTANCE.load(pluginUrl.openStream());
} catch (Throwable t) {
...
}
} List<PluginDefine> pluginClassList = PluginCfg.INSTANCE.getPluginClassList(); List<AbstractClassEnhancePluginDefine> plugins = new ArrayList<AbstractClassEnhancePluginDefine>();
for (PluginDefine pluginDefine : pluginClassList) {
try {
...
AbstractClassEnhancePluginDefine plugin =
(AbstractClassEnhancePluginDefine)Class.forName(pluginDefine.getDefineClass(),
true,
AgentClassLoader.getDefault())
.newInstance();
plugins.add(plugin);
} catch (Throwable t) {
...
}
} plugins.addAll(DynamicPluginLoader.INSTANCE.load(AgentClassLoader.getDefault())); return plugins; } public List<URL> getResources() {
......
......
try {
urls = AgentClassLoader.getDefault().getResources("skywalking-plugin.def"); while (urls.hasMoreElements()) {
URL pluginUrl = urls.nextElement();
// pluginUrl = jar:file:/../.../activemq-5.x-plugin...jar!/cat-plugin.def
...
...
...
} ...
} catch (IOException e) {
...
}
return null;
} // PluginCfg.INSTANCE.load
void load(InputStream input) throws IOException {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String pluginDefine = null;
while ((pluginDefine = reader.readLine()) != null) {
try {
if (pluginDefine == null || pluginDefine.trim().length() == 0 || pluginDefine.startsWith("#")) {
continue;
}
PluginDefine plugin = PluginDefine.build(pluginDefine);
pluginClassList.add(plugin);
} catch (IllegalPluginDefineException e) {
logger.error(e, "Failed to format plugin({}) define.", pluginDefine);
}
}
} finally {
input.close();
}
}

skywalking 比较有意思的地方的更多相关文章

  1. Python一个有意思的地方:reduce、map、filter

    今天阅读了关于Python函数式编程的系列文章,地址在这里: http://www.cnblogs.com/huxi/archive/2011/06/24/2089358.html 里面提到了四个内建 ...

  2. 一行css代码调试中学到的javascript知识,很有意思

    现在到处都是JavaScript,每天都能知道点新东西.一旦你入了门,你总能从这里或是那里领悟到很多知识.今天我想分享Addy Osmani的一行代码 ,这行代码对于你调试你的CSS是很有用的.为了可 ...

  3. 十个有意思的Github Page

    1. Cooolis.github.io Cooolis是一个操作系统命令技巧备忘录 2. rfrd-tw.github.io 2018 台灣公投視覺化 3. confpad.github.io Co ...

  4. AutoMapper

    什么是AutoMapper? AutoMapper是一个对象和对象间的映射器.对象与对象的映射是通过转变一种类型的输入对象为一种不同类型的输出对象工作的.让AutoMapper有意思的地方在于它提供了 ...

  5. 我们为什么使用Node

    引言:Node 已经迅速成为一个可行并且真正高效的web 开发平台.在Node 诞生之前,在服务端运行JavasScript 是件不可思议的事情,并且对其他的脚本语言来说,要实现非阻塞I/O 通常需要 ...

  6. SQL Server-简单查询示例(十一)

    前言 本节我们讲讲一些简单查询语句示例以及需要注意的地方,简短的内容,深入的理解,Always to review the basics. EOMONTH 在SQL Server 2012的教程示例中 ...

  7. webParts与Web部件

    web部件是ASP.NET WebForm里面的服务器控件,它涵盖的内容比较多,鉴于这种状况的话鄙人不打算深究下去了,只是局限于了解web.config配置里面的配置内容则可. 那么也得稍微说说啥是W ...

  8. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  9. [个人翻译]Redis 集群教程(中)

    上一篇:http://www.cnblogs.com/li-peng/p/6143709.html 官方原文地址:https://redis.io/topics/cluster-tutorial  水 ...

随机推荐

  1. vue element-UI Form表单验证

    摘自官网 https://element.eleme.cn/#/zh-CN/component/form 保证prop的值等于v-model的值,并且初始化值,这样验证才好使. 可以自定义验证 < ...

  2. 三大框架 之 SSH整合

    目录 SSH整合 Spring整合web项目 在Servlet当中直接加载配置文件,获取对象 存在问题 解决方案 SSH整合 引入Jar包 引入配置文件 创建包结构 创建相关类 创建Customer业 ...

  3. NumPyArray

    import arcpy import numpy # Create a simple array from scratch using random values myArray = numpy.r ...

  4. Windows环境下的安装gcc(c语言环境)

    Windows 具有良好的界面和丰富的工具,所以目前 linux 开发的流程是, windows 下完成编码工作, linux 上实现编译工作. 为了提高工作效率,有必要在 windows 环境下搭建 ...

  5. Linux openkvm disk expansion

    How to Increase the size of a Linux LVM by expanding the virtual machine disk https://www.rootusers. ...

  6. ZingChart line 折线图表数据设置

    根据 x 坐标和 y 坐标一一对应进行设置 (x,y) { "type": "line", "series":[ {,],[,],[,],[ ...

  7. Win10 x64 pnglib Release

    Win10 x64 pnglib Release >------ 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 ------ > Checking Buil ...

  8. SQLite带参数处理方法

    /// <summary> /// 执行语法[新增 修改 删除] /// </summary> /// <param name="sqlText"&g ...

  9. 深入学习c++--智能指针(三) unique_ptr

    1. 几种智能指针 1. auto_ptr: c++11中推荐不使用他(放弃) 2. shared_ptr: 拥有共享对象所有权语义的智能指针 3. unique_ptr: 拥有独有对象所有权语义的智 ...

  10. 【Tomcat】Tomcat 基本使用(二)

    上一章介绍了Tomcat原理[Tomcat]Tomcat 原理架构(一),本章介绍Tomcat的基本使用 Tomcat端口设置 tomcat端口设置,在tomcat的配置文件目录下的server.xm ...