Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
97c1fc3b
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 1 年多
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
97c1fc3b
编写于
11月 30, 2015
作者:
Z
zhangxin10
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.添加拷贝类上的注解以及方法和参数注解
2.修改jdbc插件的编译级别
上级
9d47acbf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
83 addition
and
17 deletion
+83
-17
skywalking-sdk-plugin/jdbc-plugin/pom.xml
skywalking-sdk-plugin/jdbc-plugin/pom.xml
+1
-1
skywalking-sdk-plugin/spring-plugin/pom.xml
skywalking-sdk-plugin/spring-plugin/pom.xml
+11
-0
skywalking-sdk-plugin/spring-plugin/src/main/java/com/ai/cloud/skywalking/plugin/spring/TracingEnhanceProcessor.java
...oud/skywalking/plugin/spring/TracingEnhanceProcessor.java
+71
-16
未找到文件。
skywalking-sdk-plugin/jdbc-plugin/pom.xml
浏览文件 @
97c1fc3b
...
...
@@ -33,7 +33,7 @@
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
5.1.36
</version>
<scope>
test
</scope>
<scope>
compile
</scope>
</dependency>
</dependencies>
</project>
skywalking-sdk-plugin/spring-plugin/pom.xml
浏览文件 @
97c1fc3b
...
...
@@ -40,6 +40,12 @@
<version>
3.2.0.RELEASE
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
<version>
3.2.0.RELEASE
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
...
...
@@ -64,5 +70,10 @@
<version>
${project.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
<version>
3.2.9.RELEASE
</version>
</dependency>
</dependencies>
</project>
skywalking-sdk-plugin/spring-plugin/src/main/java/com/ai/cloud/skywalking/plugin/spring/TracingEnhanceProcessor.java
浏览文件 @
97c1fc3b
...
...
@@ -3,6 +3,7 @@ package com.ai.cloud.skywalking.plugin.spring;
import
com.ai.cloud.skywalking.buriedpoint.LocalBuriedPointSender
;
import
com.ai.cloud.skywalking.model.Identification
;
import
javassist.*
;
import
javassist.bytecode.*
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
...
...
@@ -10,12 +11,17 @@ import java.lang.reflect.Constructor;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.concurrent.ThreadLocalRandom
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
TracingEnhanceProcessor
implements
BeanPostProcessor
{
public
Object
postProcessBeforeInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
private
Logger
logger
=
Logger
.
getLogger
(
TracingEnhanceProcessor
.
class
.
getName
());
public
Object
postProcessAfterInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
List
<
Method
>
methods
=
new
ArrayList
<
Method
>();
for
(
Method
method
:
bean
.
getClass
().
getMethods
())
{
if
(
method
.
isAnnotationPresent
(
Tracing
.
class
))
{
...
...
@@ -24,9 +30,12 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
}
if
(
methods
.
size
()
>
0
)
{
try
{
ClassPool
mPool
=
new
ClassPool
(
true
);
ClassPool
mPool
=
ClassPool
.
getDefault
();
mPool
.
appendClassPath
(
new
ClassClassPath
(
bean
.
getClass
()));
//创建代理类
CtClass
mCtc
=
createProxyClass
(
bean
,
mPool
);
//拷贝类上注解
copyClassesAnnotations
(
bean
,
mPool
,
mCtc
);
//代理类继承所有的被代理的接口
inheritanceAllInterfaces
(
bean
,
mPool
,
mCtc
);
//
...
...
@@ -45,9 +54,13 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
result
.
append
(
generateException
(
method
));
// 生成方法体
result
.
append
(
generateMethodBody
(
bean
,
method
));
// TODO 注解
// TODO 参数注解
mCtc
.
addMethod
(
CtMethod
.
make
(
result
.
toString
(),
mCtc
));
CtMethod
dest
=
CtMethod
.
make
(
result
.
toString
(),
mCtc
);
// 拷贝方法上的注解
CtMethod
origin
=
convertMethod2CtMethod
(
bean
,
mPool
,
method
);
copyAllAnnotation
(
origin
.
getMethodInfo
(),
dest
.
getMethodInfo
());
mCtc
.
addMethod
(
dest
);
}
mCtc
.
addConstructor
(
CtNewConstructor
.
make
(
"public "
+
mCtc
.
getSimpleName
()
+
"("
+
LocalBuriedPointSender
.
class
.
getName
()
+
" buriedPoint, "
+
bean
.
getClass
().
getName
()
+
" realBean){"
+
...
...
@@ -57,23 +70,69 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
Constructor
<?>
constructor
=
classes
.
getConstructor
(
LocalBuriedPointSender
.
class
,
bean
.
getClass
());
return
constructor
.
newInstance
(
new
LocalBuriedPointSender
(),
bean
);
}
catch
(
CannotCompileException
e
)
{
e
.
printStackTrace
(
);
logger
.
log
(
Level
.
ALL
,
"Failed to create the instance of the class["
+
beanName
+
"]"
,
e
);
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
(
);
logger
.
log
(
Level
.
ALL
,
"Failed to create the instance of the class["
+
beanName
+
"]"
,
e
);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
(
);
logger
.
log
(
Level
.
ALL
,
"Failed to create the instance of the class["
+
beanName
+
"]"
,
e
);
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
(
);
logger
.
log
(
Level
.
ALL
,
"Failed to create the instance of the class["
+
beanName
+
"]"
,
e
);
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
(
);
logger
.
log
(
Level
.
ALL
,
"Failed to create the instance of the class["
+
beanName
+
"]"
,
e
);
}
catch
(
NotFoundException
e
)
{
e
.
printStackTrace
(
);
logger
.
log
(
Level
.
ALL
,
"Failed to create the instance of the class["
+
beanName
+
"]"
,
e
);
}
}
return
bean
;
}
public
Object
postProcessBeforeInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
return
bean
;
}
private
CtMethod
convertMethod2CtMethod
(
Object
bean
,
ClassPool
mPool
,
Method
method
)
throws
NotFoundException
{
int
i
=
0
;
CtClass
ctClass
=
mPool
.
get
(
bean
.
getClass
().
getName
());
CtClass
[]
parameterClass
=
new
CtClass
[
method
.
getParameterTypes
().
length
];
for
(
Class
methodClass
:
method
.
getParameterTypes
())
{
parameterClass
[
i
++]
=
mPool
.
get
(
methodClass
.
getName
());
}
return
ctClass
.
getDeclaredMethod
(
method
.
getName
(),
parameterClass
);
}
private
void
copyClassesAnnotations
(
Object
bean
,
ClassPool
mPool
,
CtClass
mCtc
)
throws
NotFoundException
{
// 拷贝类上注解
CtClass
originCtClass
=
mPool
.
get
(
bean
.
getClass
().
getName
());
AnnotationsAttribute
annotations
=
(
AnnotationsAttribute
)
originCtClass
.
getClassFile
().
getAttribute
(
AnnotationsAttribute
.
visibleTag
);
AttributeInfo
newAnnotations
=
annotations
.
copy
(
mCtc
.
getClassFile
().
getConstPool
(),
Collections
.
EMPTY_MAP
);
mCtc
.
getClassFile
().
addAttribute
(
newAnnotations
);
}
private
void
copyAllAnnotation
(
MethodInfo
origin
,
MethodInfo
dest
)
{
AnnotationsAttribute
annotations
=
(
AnnotationsAttribute
)
origin
.
getAttribute
(
AnnotationsAttribute
.
visibleTag
);
ParameterAnnotationsAttribute
pannotations
=
(
ParameterAnnotationsAttribute
)
origin
.
getAttribute
(
ParameterAnnotationsAttribute
.
visibleTag
);
ExceptionsAttribute
exAt
=
(
ExceptionsAttribute
)
origin
.
getAttribute
(
ExceptionsAttribute
.
tag
);
SignatureAttribute
sigAt
=
(
SignatureAttribute
)
origin
.
getAttribute
(
SignatureAttribute
.
tag
);
if
(
annotations
!=
null
)
{
AttributeInfo
newAnnotations
=
annotations
.
copy
(
dest
.
getConstPool
(),
Collections
.
EMPTY_MAP
);
dest
.
addAttribute
(
newAnnotations
);
}
if
(
pannotations
!=
null
)
{
AttributeInfo
newAnnotations
=
pannotations
.
copy
(
dest
.
getConstPool
(),
Collections
.
EMPTY_MAP
);
dest
.
addAttribute
(
newAnnotations
);
}
if
(
sigAt
!=
null
)
{
AttributeInfo
newAnnotations
=
sigAt
.
copy
(
dest
.
getConstPool
(),
Collections
.
EMPTY_MAP
);
dest
.
addAttribute
(
newAnnotations
);
}
if
(
exAt
!=
null
)
{
AttributeInfo
newAnnotations
=
exAt
.
copy
(
dest
.
getConstPool
(),
Collections
.
EMPTY_MAP
);
dest
.
addAttribute
(
newAnnotations
);
}
}
private
String
generateMethodBody
(
Object
bean
,
Method
method
)
{
StringBuilder
result
=
new
StringBuilder
();
result
.
append
(
"{"
);
...
...
@@ -160,7 +219,7 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
}
private
CtClass
createProxyClass
(
Object
bean
,
ClassPool
mPool
)
{
return
mPool
.
makeClass
(
bean
.
getClass
().
get
Simple
Name
()
+
"$EnhanceBySWTracing$"
+
ThreadLocalRandom
.
current
().
nextInt
(
100
));
return
mPool
.
makeClass
(
bean
.
getClass
().
getName
()
+
"$EnhanceBySWTracing$"
+
ThreadLocalRandom
.
current
().
nextInt
(
100
));
}
private
void
inheritanceAllInterfaces
(
Object
bean
,
ClassPool
mPool
,
CtClass
mCtc
)
throws
NotFoundException
{
...
...
@@ -168,8 +227,4 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
mCtc
.
addInterface
(
mPool
.
get
(
classes
.
getClass
().
getName
()));
}
}
public
Object
postProcessAfterInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
return
bean
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录