Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gdyjdao
SkyWalking
提交
c1b92fd3
S
SkyWalking
项目概览
gdyjdao
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c1b92fd3
编写于
10月 16, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add comment for InterceptorInstanceLoader
上级
2b1829ba
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
12 deletion
+28
-12
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java
...m/agent/core/plugin/loader/InterceptorInstanceLoader.java
+28
-12
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java
浏览文件 @
c1b92fd3
...
...
@@ -28,6 +28,7 @@ import java.util.HashMap;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.locks.ReentrantLock
;
import
org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
...
...
@@ -58,8 +59,23 @@ public class InterceptorInstanceLoader {
private
static
Map
<
ClassLoader
,
ClassLoader
>
EXTEND_PLUGIN_CLASSLOADERS
=
new
HashMap
<
ClassLoader
,
ClassLoader
>();
/**
* Load an instance of interceptor, and keep it singleton.
* Create {@link AgentClassLoader} for each targetClassLoader, as an extend classloader.
* It can load interceptor classes from plugins, activations folders.
*
* @param className
* @param targetClassLoader
* @param <T>
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
* @throws AgentPackageNotFoundException
*/
public
static
<
T
>
T
load
(
String
className
,
ClassLoader
targetClassLoader
)
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
,
ClassNotFoundException
,
AgentPackageNotFoundException
{
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
,
ClassNotFoundException
,
AgentPackageNotFoundException
{
if
(
targetClassLoader
==
null
)
{
targetClassLoader
=
InterceptorInstanceLoader
.
class
.
getClassLoader
();
}
...
...
@@ -82,7 +98,7 @@ public class InterceptorInstanceLoader {
}
}
return
(
T
)
inst
;
return
(
T
)
inst
;
}
/**
...
...
@@ -98,7 +114,7 @@ public class InterceptorInstanceLoader {
* @throws ClassNotFoundException
*/
public
static
<
T
>
T
load0
(
String
className
,
ClassLoader
targetClassLoader
)
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
,
ClassNotFoundException
{
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
,
ClassNotFoundException
{
if
(
targetClassLoader
==
null
)
{
targetClassLoader
=
InterceptorInstanceLoader
.
class
.
getClassLoader
();
}
...
...
@@ -130,14 +146,14 @@ public class InterceptorInstanceLoader {
}
}
return
(
T
)
inst
;
return
(
T
)
inst
;
}
/**
* load class from class binary files.
* Most likely all the interceptor implementations should be loaded by this.
*
* @param className interceptor class name.
* @param className
interceptor class name.
* @param targetClassLoader the classloader, which should load the interceptor.
* @param <T>
* @return interceptor instance.
...
...
@@ -146,7 +162,7 @@ public class InterceptorInstanceLoader {
* @throws InstantiationException
*/
private
static
<
T
>
T
loadBinary
(
String
className
,
ClassLoader
targetClassLoader
)
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
{
ClassLoader
targetClassLoader
)
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
{
String
path
=
"/"
+
className
.
replace
(
'.'
,
'/'
).
concat
(
".class"
);
byte
[]
data
=
null
;
BufferedInputStream
is
=
null
;
...
...
@@ -186,21 +202,21 @@ public class InterceptorInstanceLoader {
}
defineClassMethod
.
setAccessible
(
true
);
logger
.
debug
(
"load binary code of {} to classloader {}"
,
className
,
targetClassLoader
);
Class
<?>
type
=
(
Class
<?>)
defineClassMethod
.
invoke
(
targetClassLoader
,
className
,
data
,
0
,
data
.
length
,
null
);
return
(
T
)
type
.
newInstance
();
Class
<?>
type
=
(
Class
<?>)
defineClassMethod
.
invoke
(
targetClassLoader
,
className
,
data
,
0
,
data
.
length
,
null
);
return
(
T
)
type
.
newInstance
();
}
/**
* Find loaded class in the current classloader.
* Just in case some classes have already been loaded for some reason.
*
* @param className interceptor class name.
* @param className
interceptor class name.
* @param targetClassLoader the classloader, which should load the interceptor.
* @param <T>
* @return interceptor instance.
*/
private
static
<
T
>
T
findLoadedClass
(
String
className
,
ClassLoader
targetClassLoader
)
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
{
ClassLoader
targetClassLoader
)
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
{
Method
defineClassMethod
=
null
;
Class
<?>
targetClassLoaderType
=
targetClassLoader
.
getClass
();
while
(
defineClassMethod
==
null
&&
targetClassLoaderType
!=
null
)
{
...
...
@@ -211,10 +227,10 @@ public class InterceptorInstanceLoader {
}
}
defineClassMethod
.
setAccessible
(
true
);
Class
<?>
type
=
(
Class
<?>)
defineClassMethod
.
invoke
(
targetClassLoader
,
className
);
Class
<?>
type
=
(
Class
<?>)
defineClassMethod
.
invoke
(
targetClassLoader
,
className
);
if
(
type
==
null
)
{
return
null
;
}
return
(
T
)
type
.
newInstance
();
return
(
T
)
type
.
newInstance
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录