Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
04638c51
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,发现更多精彩内容 >>
提交
04638c51
编写于
2月 19, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename and refactor SimapleObjectFirstInvokeInterceptor to NoCocurrencyAceessObject
上级
7e640311
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
68 addition
and
86 deletion
+68
-86
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/assist/NoCocurrencyAceessObject.java
...g/plugin/interceptor/assist/NoCocurrencyAceessObject.java
+46
-0
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/assist/SimpleObjectFirstInvokeInterceptor.java
...nterceptor/assist/SimpleObjectFirstInvokeInterceptor.java
+0
-42
skywalking-sniffer/skywalking-api/src/test/java/test/a/eye/cloud/api/TimeTest.java
...king-api/src/test/java/test/a/eye/cloud/api/TimeTest.java
+0
-25
skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java
...ye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java
+22
-19
未找到文件。
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/assist/NoCocurrencyAceessObject.java
0 → 100644
浏览文件 @
04638c51
package
com.a.eye.skywalking.plugin.interceptor.assist
;
import
com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.plugin.interceptor.InterceptorException
;
import
com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
/**
* {@link NoCocurrencyAceessObject} is an abstract class,
* works for class's methods call each others, which these methods should be intercepted.
*
* At this scenario, only the first access should be intercepted.
*
* @author wusheng
*/
public
abstract
class
NoCocurrencyAceessObject
implements
InstanceMethodsAroundInterceptor
{
protected
String
invokeCounterKey
=
"__$invokeCounterKey"
;
protected
Object
invokeCounterInstLock
=
new
Object
();
public
void
whenEnter
(
EnhancedClassInstanceContext
context
,
Runnable
runnable
)
{
if
(!
context
.
isContain
(
invokeCounterKey
))
{
synchronized
(
invokeCounterInstLock
)
{
if
(!
context
.
isContain
(
invokeCounterKey
))
{
context
.
set
(
invokeCounterKey
,
0
);
}
}
}
int
counter
=
context
.
get
(
invokeCounterKey
,
Integer
.
class
);
if
(++
counter
==
1
){
runnable
.
run
();
}
}
public
void
whenExist
(
EnhancedClassInstanceContext
context
,
Runnable
runnable
)
{
if
(!
context
.
isContain
(
invokeCounterKey
))
{
throw
new
InterceptorException
(
"key=invokeCounterKey not found is context. unexpected situation."
);
}
int
counter
=
context
.
get
(
invokeCounterKey
,
Integer
.
class
);
if
(--
counter
==
0
){
runnable
.
run
();
}
}
}
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/plugin/interceptor/assist/SimpleObjectFirstInvokeInterceptor.java
已删除
100644 → 0
浏览文件 @
7e640311
package
com.a.eye.skywalking.plugin.interceptor.assist
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.plugin.interceptor.InterceptorException
;
import
com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
/**
* 用于首次拦截方法调用,避免方法内部的方法调用被多次拦截。
*
* @author wusheng
*
*/
public
abstract
class
SimpleObjectFirstInvokeInterceptor
implements
InstanceMethodsAroundInterceptor
{
protected
String
invokeCounterKey
=
"__$invokeCounterKey"
;
protected
Object
invokeCounterInstLock
=
new
Object
();
public
boolean
isFirstBeforeMethod
(
EnhancedClassInstanceContext
context
)
{
if
(!
context
.
isContain
(
invokeCounterKey
))
{
synchronized
(
invokeCounterInstLock
)
{
if
(!
context
.
isContain
(
invokeCounterKey
))
{
context
.
set
(
invokeCounterKey
,
new
AtomicInteger
(
0
));
}
}
}
AtomicInteger
counter
=
context
.
get
(
invokeCounterKey
,
AtomicInteger
.
class
);
return
counter
.
incrementAndGet
()
==
1
;
}
public
boolean
isLastAfterMethod
(
EnhancedClassInstanceContext
context
)
{
if
(!
context
.
isContain
(
invokeCounterKey
))
{
throw
new
InterceptorException
(
"key=invokeCounterKey not found is context. unexpected failue."
);
}
AtomicInteger
counter
=
context
.
get
(
invokeCounterKey
,
AtomicInteger
.
class
);
return
counter
.
decrementAndGet
()
==
0
;
}
}
skywalking-sniffer/skywalking-api/src/test/java/test/a/eye/cloud/api/TimeTest.java
已删除
100644 → 0
浏览文件 @
7e640311
package
test.a.eye.cloud.api
;
import
org.junit.Test
;
import
com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor
;
import
com.a.eye.skywalking.model.Identification
;
import
com.a.eye.skywalking.model.Identification.IdentificationBuilder
;
public
class
TimeTest
{
@Test
public
void
test
(){
RPCClientInvokeMonitor
sender
=
new
RPCClientInvokeMonitor
();
long
start
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
IdentificationBuilder
builder
=
Identification
.
newBuilder
()
.
viewPoint
(
"1111"
);
sender
.
beforeInvoke
(
builder
.
build
());
sender
.
afterInvoke
();
}
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
end
-
start
+
"ms"
);
}
}
skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java
浏览文件 @
04638c51
package
com.a.eye.skywalking.plugin.jedis.v2
;
import
com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor
;
import
com.a.eye.skywalking.model.Identification
;
import
com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.plugin.interceptor.assist.
SimpleObjectFirstInvokeInterceptor
;
import
com.a.eye.skywalking.plugin.interceptor.assist.
NoCocurrencyAceessObject
;
import
com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult
;
public
class
JedisMethodInterceptor
extends
SimpleObjectFirstInvokeInterceptor
{
public
class
JedisMethodInterceptor
extends
NoCocurrencyAceessObject
{
protected
static
final
String
REDIS_CONN_INFO_KEY
=
"redisClusterConnInfo"
;
private
static
RPCClientInvokeMonitor
rpcClientInvokeMonitor
=
new
RPCClientInvokeMonitor
();
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
if
(
this
.
isFirstBeforeMethod
(
context
))
{
/**
* redis server wouldn't process rpc context. ignore the
* return(ContextData) of sender's beforeSend
*/
Identification
.
IdentificationBuilder
builder
=
Identification
this
.
whenEnter
(
context
,
new
Runnable
()
{
@Override
public
void
run
()
{
/**
* redis server wouldn't process rpc context. ignore the
* return(ContextData) of sender's beforeSend
*/
Identification
.
IdentificationBuilder
builder
=
Identification
.
newBuilder
()
.
viewPoint
(
context
.
get
(
REDIS_CONN_INFO_KEY
,
String
.
class
)
+
" "
+
interceptorContext
.
methodName
())
context
.
get
(
REDIS_CONN_INFO_KEY
,
String
.
class
)
+
" "
+
interceptorContext
.
methodName
())
.
spanType
(
RedisBuriedPointType
.
INSTANCE
);
if
(
interceptorContext
.
allArguments
().
length
>
0
if
(
interceptorContext
.
allArguments
().
length
>
0
&&
interceptorContext
.
allArguments
()[
0
]
instanceof
String
)
{
builder
.
businessKey
(
"key="
builder
.
businessKey
(
"key="
+
interceptorContext
.
allArguments
()[
0
]);
}
rpcClientInvokeMonitor
.
beforeInvoke
(
builder
.
build
());
}
rpcClientInvokeMonitor
.
beforeInvoke
(
builder
.
build
());
}
});
}
@Override
public
Object
afterMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
Object
ret
)
{
if
(
this
.
isLastAfterMethod
(
context
))
{
rpcClientInvokeMonitor
.
afterInvoke
();
}
this
.
whenExist
(
context
,
new
Runnable
(){
@Override
public
void
run
()
{
rpcClientInvokeMonitor
.
afterInvoke
();
}
});
return
ret
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录