Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
852aec98
S
SkyWalking
项目概览
山不在高_有仙则灵
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
12
Star
0
Fork
2
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
852aec98
编写于
3月 10, 2016
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.增加构造函数拦截的测试。
上级
65679624
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
32 deletion
+62
-32
skywalking-api/src/test/java/test/ai/cloud/bytebuddy/ConstructorInterceptor.java
.../java/test/ai/cloud/bytebuddy/ConstructorInterceptor.java
+16
-0
skywalking-api/src/test/java/test/ai/cloud/bytebuddy/MethodInterceptor.java
.../test/java/test/ai/cloud/bytebuddy/MethodInterceptor.java
+4
-3
skywalking-api/src/test/java/test/ai/cloud/bytebuddy/SimulateMain.java
...i/src/test/java/test/ai/cloud/bytebuddy/SimulateMain.java
+33
-29
skywalking-api/src/test/java/test/ai/cloud/bytebuddy/TestClass.java
...-api/src/test/java/test/ai/cloud/bytebuddy/TestClass.java
+9
-0
未找到文件。
skywalking-api/src/test/java/test/ai/cloud/bytebuddy/ConstructorInterceptor.java
0 → 100644
浏览文件 @
852aec98
package
test.ai.cloud.bytebuddy
;
import
net.bytebuddy.implementation.bind.annotation.AllArguments
;
import
net.bytebuddy.implementation.bind.annotation.RuntimeType
;
import
net.bytebuddy.implementation.bind.annotation.This
;
public
class
ConstructorInterceptor
{
@RuntimeType
public
void
intercept
(
@AllArguments
Object
[]
allArguments
)
{
System
.
out
.
println
(
"ConstructorInterceptor size:"
+
allArguments
.
length
);
if
(
allArguments
.
length
>
0
){
System
.
out
.
println
(
"ConstructorInterceptor param[0]="
+
allArguments
[
0
]);
}
}
}
skywalking-api/src/test/java/test/ai/cloud/bytebuddy/Interceptor.java
→
skywalking-api/src/test/java/test/ai/cloud/bytebuddy/
Method
Interceptor.java
浏览文件 @
852aec98
...
...
@@ -7,12 +7,13 @@ import net.bytebuddy.implementation.bind.annotation.AllArguments;
import
net.bytebuddy.implementation.bind.annotation.Origin
;
import
net.bytebuddy.implementation.bind.annotation.RuntimeType
;
import
net.bytebuddy.implementation.bind.annotation.SuperCall
;
import
net.bytebuddy.implementation.bind.annotation.This
;
public
class
Interceptor
{
public
class
Method
Interceptor
{
@RuntimeType
public
Object
intercept
(
@AllArguments
Object
[]
allArguments
,
@Origin
Method
method
,
@SuperCall
Callable
<?>
zuper
){
public
Object
intercept
(
@
This
Object
obj
,
@
AllArguments
Object
[]
allArguments
,
@Origin
Method
method
,
@SuperCall
Callable
<?>
zuper
){
try
{
return
"
intercept_"
+
zuper
.
call
();
return
method
.
getName
()
+
":
intercept_"
+
zuper
.
call
();
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
...
...
skywalking-api/src/test/java/test/ai/cloud/bytebuddy/SimulateMain.java
浏览文件 @
852aec98
package
test.ai.cloud.bytebuddy
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
isConstructor
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
isMethod
;
import
net.bytebuddy.ByteBuddy
;
import
net.bytebuddy.dynamic.ClassFileLocator
;
import
net.bytebuddy.dynamic.loading.ClassLoadingStrategy
;
import
net.bytebuddy.implementation.MethodDelegation
;
import
net.bytebuddy.implementation.SuperMethodCall
;
import
net.bytebuddy.pool.TypePool
;
public
class
SimulateMain
{
public
static
void
main
(
String
[]
args
)
throws
NoSuchFieldException
,
SecurityException
,
InstantiationException
,
IllegalAccessException
{
TypePool
typePool
=
TypePool
.
Default
.
ofClassPath
();
Object
newClazzObj
=
new
ByteBuddy
()
.
redefine
(
typePool
.
describe
(
"test.ai.cloud.bytebuddy.TestClass"
)
.
resolve
(),
ClassFileLocator
.
ForClassLoader
.
ofClassPath
())
.
name
(
"test.ai.cloud.bytebuddy.TestClass$$Origin"
)
.
make
()
.
load
(
ClassLoader
.
getSystemClassLoader
(),
ClassLoadingStrategy
.
Default
.
INJECTION
).
getLoaded
().
newInstance
();
TestClass
t22
=
(
TestClass
)(
new
ByteBuddy
()
.
subclass
(
newClazzObj
.
getClass
())
.
method
(
named
(
"testA"
))
.
intercept
(
MethodDelegation
.
to
(
new
Interceptor
()))
Class
<?>
newClazz
=
new
ByteBuddy
()
.
redefine
(
typePool
.
describe
(
"test.ai.cloud.bytebuddy.TestClass"
)
.
resolve
(),
ClassFileLocator
.
ForClassLoader
.
ofClassPath
())
.
name
(
"test.ai.cloud.bytebuddy.TestClass$$Origin"
)
.
make
()
.
load
(
ClassLoader
.
getSystemClassLoader
(),
ClassLoadingStrategy
.
Default
.
INJECTION
).
getLoaded
();
TestClass
t22
=
(
TestClass
)
(
new
ByteBuddy
()
.
subclass
(
newClazz
)
.
method
(
isMethod
())
.
intercept
(
MethodDelegation
.
to
(
new
MethodInterceptor
()))
.
constructor
(
isConstructor
())
.
intercept
(
MethodDelegation
.
to
(
new
ConstructorInterceptor
()).
andThen
(
SuperMethodCall
.
INSTANCE
))
.
name
(
"test.ai.cloud.bytebuddy.TestClass"
)
.
make
()
.
load
(
ClassLoader
.
getSystemClassLoader
(),
ClassLoadingStrategy
.
Default
.
INJECTION
).
getLoaded
().
newInstance
());
ClassLoadingStrategy
.
Default
.
INJECTION
).
getLoaded
()
.
newInstance
());
//System.out.println(t22.testA("1"));
TestClass
t
=
new
TestClass
();
// System.out.println(t22.testA("1"));
TestClass
t
=
new
TestClass
(
"abc"
);
System
.
out
.
println
(
t
.
testA
(
"1"
));
TestClass
t2
=
null
;
try
{
t2
=
(
TestClass
)
Class
.
forName
(
"test.ai.cloud.bytebuddy.TestClass"
).
newInstance
();
}
catch
(
ClassNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
System
.
out
.
println
(
t2
.
testA
(
"1"
));
// TestClass t2 = null;
// try {
// t2 = (TestClass) Class.forName("test.ai.cloud.bytebuddy.TestClass")
// .newInstance();
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// System.out.println(t2.testA("1"));
}
}
skywalking-api/src/test/java/test/ai/cloud/bytebuddy/TestClass.java
浏览文件 @
852aec98
package
test.ai.cloud.bytebuddy
;
public
class
TestClass
{
public
TestClass
(){
//System.out.println("init:" + this.getClass().getName());
}
public
TestClass
(
String
tmp
){
//System.out.println("init:" + this.getClass().getName());
}
public
String
testA
(
String
aa
){
// throw new RuntimeException("adfasdfas");
return
"TestClass.testA"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录