Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
904d0cb2
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,发现更多精彩内容 >>
提交
904d0cb2
编写于
3月 14, 2016
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
调整代码结构。完善context相关内容。#36
上级
c64ce242
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
56 addition
and
20 deletion
+56
-20
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassConstructorInterceptor.java
...lking/plugin/interceptor/ClassConstructorInterceptor.java
+3
-10
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java
...ywalking/plugin/interceptor/EnhanceClazz4Interceptor.java
+3
-6
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhancedClassInstanceContext.java
...king/plugin/interceptor/EnhancedClassInstanceContext.java
+17
-2
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/FieldGetter.java
...m/ai/cloud/skywalking/plugin/interceptor/FieldGetter.java
+5
-0
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/FieldSetter.java
...m/ai/cloud/skywalking/plugin/interceptor/FieldSetter.java
+5
-0
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/InterceptorContext.java
...oud/skywalking/plugin/interceptor/InterceptorContext.java
+4
-0
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/InterceptorDefine.java
...loud/skywalking/plugin/interceptor/InterceptorDefine.java
+16
-0
skywalking-api/src/test/java/test/ai/cloud/plugin/TestAroundInterceptor.java
...test/java/test/ai/cloud/plugin/TestAroundInterceptor.java
+3
-2
未找到文件。
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassConstructorInterceptor.java
浏览文件 @
904d0cb2
...
...
@@ -24,21 +24,14 @@ public class ClassConstructorInterceptor {
@FieldProxy
(
EnhanceClazz4Interceptor
.
contextAttrName
)
FieldSetter
accessor
,
@AllArguments
Object
[]
allArguments
)
{
try
{
accessor
.
setValue
(
new
EnhancedClassInstanceContext
());
EnhancedClassInstanceContext
context
=
new
EnhancedClassInstanceContext
();
accessor
.
setValue
(
context
);
ConstructorContext
interceptorContext
=
new
ConstructorContext
(
allArguments
);
interceptor
.
onConstruct
(
null
,
interceptorContext
);
interceptor
.
onConstruct
(
context
,
interceptorContext
);
}
catch
(
Throwable
t
)
{
logger
.
error
(
"ClassConstructorInterceptor failue."
,
t
);
}
}
public
interface
FieldGetter
{
Object
getValue
();
}
public
interface
FieldSetter
{
void
setValue
(
Object
value
);
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java
浏览文件 @
904d0cb2
...
...
@@ -19,8 +19,6 @@ import org.apache.logging.log4j.LogManager;
import
org.apache.logging.log4j.Logger
;
import
com.ai.cloud.skywalking.plugin.PluginCfg
;
import
com.ai.cloud.skywalking.plugin.interceptor.ClassConstructorInterceptor.FieldGetter
;
import
com.ai.cloud.skywalking.plugin.interceptor.ClassConstructorInterceptor.FieldSetter
;
public
class
EnhanceClazz4Interceptor
{
private
static
Logger
logger
=
LogManager
...
...
@@ -76,15 +74,14 @@ public class EnhanceClazz4Interceptor {
ClassLoadingStrategy
.
Default
.
INJECTION
).
getLoaded
();
/**
*
to classloader.
<br/>
*
create a new class using origin classname.
<br/>
*
* new class need:<br/>
* 1.add field '_$EnhancedClassInstanceContext' of type
* EnhancedClassInstanceContext <br/>
*
* 2.intercept constructor and method if required by
* interceptorDefineClass. use '@FieldValue' get
* '_$EnhancedClassInstanceContext' ref<br/>
* 2.intercept constructor by default, and intercept method which it's required by
* interceptorDefineClass. <br/>
*/
IAroundInterceptor
interceptor
=
define
.
instance
();
...
...
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhancedClassInstanceContext.java
浏览文件 @
904d0cb2
package
com.ai.cloud.skywalking.plugin.interceptor
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* 被增强的类实例,需扩展的context属性,用于在不同的方法,或者构造函数间保存实例
...
...
@@ -12,7 +12,22 @@ import java.util.Map;
public
class
EnhancedClassInstanceContext
{
public
static
final
String
FIELD_NAME
=
"_$EnhancedClassInstanceContext"
;
private
Map
<
Object
,
Object
>
context
=
new
HashMap
<
Object
,
Object
>();
private
Map
<
Object
,
Object
>
context
=
new
Concurrent
HashMap
<
Object
,
Object
>();
public
void
set
(
Object
key
,
Object
value
){
context
.
put
(
key
,
value
);
}
public
Object
get
(
Object
key
){
return
context
.
get
(
key
);
}
public
boolean
isContain
(
Object
key
){
return
context
.
containsKey
(
key
);
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
get
(
Object
key
,
Class
<
T
>
type
){
return
(
T
)
this
.
get
(
key
);
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/FieldGetter.java
0 → 100644
浏览文件 @
904d0cb2
package
com.ai.cloud.skywalking.plugin.interceptor
;
public
interface
FieldGetter
{
Object
getValue
();
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/FieldSetter.java
0 → 100644
浏览文件 @
904d0cb2
package
com.ai.cloud.skywalking.plugin.interceptor
;
public
interface
FieldSetter
{
void
setValue
(
Object
value
);
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/InterceptorContext.java
浏览文件 @
904d0cb2
...
...
@@ -16,6 +16,10 @@ public class InterceptorContext {
return
this
.
allArguments
;
}
public
String
methodName
(){
return
methodName
;
}
public
Object
inst
(){
return
objInst
;
}
...
...
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/InterceptorDefine.java
浏览文件 @
904d0cb2
package
com.ai.cloud.skywalking.plugin.interceptor
;
public
interface
InterceptorDefine
{
/**
* 返回要被增强的类,应当返回类全名
*
* @return
*/
public
String
getBeInterceptedClassName
();
/**
* 返回需要被增强的方法列表
*
* @return
*/
public
String
[]
getBeInterceptedMethods
();
/**
* 返回增强拦截器的实现<br/>
* 每个拦截器在同一个被增强类的内部,保持单例
*
* @return
*/
public
IAroundInterceptor
instance
();
}
skywalking-api/src/test/java/test/ai/cloud/plugin/TestAroundInterceptor.java
浏览文件 @
904d0cb2
...
...
@@ -9,17 +9,18 @@ public class TestAroundInterceptor implements IAroundInterceptor {
@Override
public
void
onConstruct
(
EnhancedClassInstanceContext
context
,
ConstructorContext
interceptorContext
)
{
context
.
set
(
"test.key"
,
"123"
);
System
.
out
.
println
(
"onConstruct, args size="
+
interceptorContext
.
allArguments
().
length
);
}
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InterceptorContext
interceptorContext
)
{
System
.
out
.
println
(
"beforeMethod : "
+
context
);
System
.
out
.
println
(
"beforeMethod : "
+
context
.
get
(
"test.key"
,
String
.
class
)
);
}
@Override
public
void
afterMethod
(
EnhancedClassInstanceContext
context
,
InterceptorContext
interceptorContext
)
{
System
.
out
.
println
(
"afterMethod: "
+
context
);
System
.
out
.
println
(
"afterMethod: "
+
context
.
get
(
"test.key"
,
String
.
class
)
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录