Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
5d224c3f
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,发现更多精彩内容 >>
提交
5d224c3f
编写于
1月 18, 2016
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.修改span的反序列化程序,增加可读性。
上级
14c021d9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
207 addition
and
160 deletion
+207
-160
skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java
.../src/main/java/com/ai/cloud/skywalking/protocol/Span.java
+207
-160
未找到文件。
skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java
浏览文件 @
5d224c3f
...
...
@@ -8,165 +8,212 @@ import java.util.logging.Logger;
public
class
Span
extends
SpanData
{
private
Logger
logger
=
Logger
.
getLogger
(
Span
.
class
.
getName
());
public
Span
()
{
}
public
Span
(
String
traceId
,
String
applicationID
,
String
userId
)
{
this
.
traceId
=
traceId
;
this
.
applicationId
=
applicationID
;
this
.
userId
=
userId
;
}
public
Span
(
String
traceId
,
String
parentLevelId
,
int
levelId
,
String
applicationID
,
String
userId
)
{
this
.
traceId
=
traceId
;
this
.
applicationId
=
applicationID
;
this
.
parentLevel
=
parentLevelId
;
this
.
userId
=
userId
;
this
.
levelId
=
levelId
;
}
public
Span
(
String
originData
)
{
String
[]
fieldValues
=
originData
.
split
(
SPAN_FIELD_SPILT_PATTERN
);
traceId
=
fieldValues
[
0
].
trim
();
parentLevel
=
fieldValues
[
1
].
trim
();
levelId
=
Integer
.
valueOf
(
fieldValues
[
2
]);
viewPointId
=
fieldValues
[
3
].
trim
();
startDate
=
Long
.
valueOf
(
fieldValues
[
4
]);
cost
=
Long
.
parseLong
(
fieldValues
[
5
]);
address
=
fieldValues
[
6
].
trim
();
statusCode
=
Byte
.
valueOf
(
fieldValues
[
7
].
trim
());
exceptionStack
=
fieldValues
[
8
].
trim
().
replaceAll
(
SPAN_ATTR_SPILT_CHARACTER
,
NEW_LINE_CHARACTER_PATTERN
);
spanType
=
fieldValues
[
9
];
isReceiver
=
Boolean
.
valueOf
(
fieldValues
[
10
]);
businessKey
=
fieldValues
[
11
].
trim
().
replaceAll
(
SPAN_ATTR_SPILT_CHARACTER
,
NEW_LINE_CHARACTER_PATTERN
);
processNo
=
fieldValues
[
12
].
trim
();
applicationId
=
fieldValues
[
13
].
trim
();
userId
=
fieldValues
[
14
].
trim
();
if
(
fieldValues
.
length
>
15
)
{
callType
=
fieldValues
[
15
].
trim
();
}
this
.
originData
=
originData
;
}
@Override
public
String
toString
()
{
StringBuilder
toStringValue
=
new
StringBuilder
();
toStringValue
.
append
(
traceId
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
parentLevel
))
{
toStringValue
.
append
(
parentLevel
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
levelId
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
viewPointId
))
{
toStringValue
.
append
(
viewPointId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
startDate
+
SPAN_FIELD_SPILT_PATTERN
);
toStringValue
.
append
(
cost
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
address
))
{
toStringValue
.
append
(
address
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
statusCode
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
exceptionStack
))
{
// 换行符在各个系统中表现不一致,
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue
.
append
(
exceptionStack
.
replaceAll
(
CARRIAGE_RETURN_CHARACTER_PATTERN
,
""
).
replaceAll
(
NEW_LINE_CHARACTER_PATTERN
,
SPAN_ATTR_SPILT_CHARACTER
)
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
spanType
+
SPAN_FIELD_SPILT_PATTERN
);
toStringValue
.
append
(
isReceiver
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
businessKey
))
{
// 换行符在各个系统中表现不一致,
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue
.
append
(
businessKey
.
replaceAll
(
CARRIAGE_RETURN_CHARACTER_PATTERN
,
""
).
replaceAll
(
NEW_LINE_CHARACTER_PATTERN
,
SPAN_ATTR_SPILT_CHARACTER
)
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
processNo
))
{
toStringValue
.
append
(
processNo
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
applicationId
))
{
toStringValue
.
append
(
applicationId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
userId
))
{
toStringValue
.
append
(
userId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
callType
);
return
toStringValue
.
toString
();
}
protected
boolean
isNonBlank
(
String
str
)
{
return
str
!=
null
&&
str
.
length
()
>
0
;
}
public
void
handleException
(
Throwable
e
,
Set
<
String
>
exclusiveExceptionSet
,
int
maxExceptionStackLength
)
{
ByteArrayOutputStream
buf
=
null
;
StringBuilder
expMessage
=
new
StringBuilder
();
try
{
buf
=
new
ByteArrayOutputStream
();
Throwable
causeException
=
e
;
while
(
causeException
!=
null
&&
(
causeException
.
getCause
()
!=
null
||
expMessage
.
length
()
<
maxExceptionStackLength
))
{
causeException
.
printStackTrace
(
new
java
.
io
.
PrintWriter
(
buf
,
true
));
expMessage
.
append
(
buf
.
toString
());
causeException
=
causeException
.
getCause
();
}
}
finally
{
try
{
buf
.
close
();
}
catch
(
IOException
ioe
)
{
logger
.
log
(
Level
.
ALL
,
"Close exception stack input stream failed"
,
ioe
);
}
}
this
.
exceptionStack
=
expMessage
.
toString
();
if
(!
exclusiveExceptionSet
.
contains
(
e
.
getClass
().
getName
()))
{
this
.
statusCode
=
1
;
}
}
private
Logger
logger
=
Logger
.
getLogger
(
Span
.
class
.
getName
());
public
Span
()
{
}
public
Span
(
String
traceId
,
String
applicationID
,
String
userId
)
{
this
.
traceId
=
traceId
;
this
.
applicationId
=
applicationID
;
this
.
userId
=
userId
;
}
public
Span
(
String
traceId
,
String
parentLevelId
,
int
levelId
,
String
applicationID
,
String
userId
)
{
this
.
traceId
=
traceId
;
this
.
applicationId
=
applicationID
;
this
.
parentLevel
=
parentLevelId
;
this
.
userId
=
userId
;
this
.
levelId
=
levelId
;
}
public
Span
(
String
originData
)
{
String
[]
fieldValues
=
originData
.
split
(
SPAN_FIELD_SPILT_PATTERN
);
int
index
=
0
;
while
(
this
.
setValueByIndex
(
fieldValues
,
index
))
{
index
++;
}
this
.
originData
=
originData
;
}
private
boolean
setValueByIndex
(
String
[]
fieldValues
,
int
index
)
{
if
(
fieldValues
.
length
>
index
)
{
switch
(
index
)
{
case
0
:
traceId
=
fieldValues
[
0
].
trim
();
break
;
case
1
:
parentLevel
=
fieldValues
[
1
].
trim
();
break
;
case
2
:
levelId
=
Integer
.
valueOf
(
fieldValues
[
2
]);
break
;
case
3
:
viewPointId
=
fieldValues
[
3
].
trim
();
break
;
case
4
:
startDate
=
Long
.
valueOf
(
fieldValues
[
4
]);
break
;
case
5
:
cost
=
Long
.
parseLong
(
fieldValues
[
5
]);
break
;
case
6
:
address
=
fieldValues
[
6
].
trim
();
break
;
case
7
:
statusCode
=
Byte
.
valueOf
(
fieldValues
[
7
].
trim
());
break
;
case
8
:
exceptionStack
=
fieldValues
[
8
].
trim
().
replaceAll
(
SPAN_ATTR_SPILT_CHARACTER
,
NEW_LINE_CHARACTER_PATTERN
);
break
;
case
9
:
spanType
=
fieldValues
[
9
];
break
;
case
10
:
isReceiver
=
Boolean
.
valueOf
(
fieldValues
[
10
]);
break
;
case
11
:
businessKey
=
fieldValues
[
11
].
trim
().
replaceAll
(
SPAN_ATTR_SPILT_CHARACTER
,
NEW_LINE_CHARACTER_PATTERN
);
break
;
case
12
:
processNo
=
fieldValues
[
12
].
trim
();
break
;
case
13
:
applicationId
=
fieldValues
[
13
].
trim
();
break
;
case
14
:
userId
=
fieldValues
[
14
].
trim
();
break
;
case
15
:
callType
=
fieldValues
[
15
].
trim
();
break
;
default
:
return
false
;
}
return
true
;
}
else
{
return
false
;
}
}
@Override
public
String
toString
()
{
StringBuilder
toStringValue
=
new
StringBuilder
();
toStringValue
.
append
(
traceId
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
parentLevel
))
{
toStringValue
.
append
(
parentLevel
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
levelId
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
viewPointId
))
{
toStringValue
.
append
(
viewPointId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
startDate
+
SPAN_FIELD_SPILT_PATTERN
);
toStringValue
.
append
(
cost
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
address
))
{
toStringValue
.
append
(
address
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
statusCode
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
exceptionStack
))
{
// 换行符在各个系统中表现不一致,
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue
.
append
(
exceptionStack
.
replaceAll
(
CARRIAGE_RETURN_CHARACTER_PATTERN
,
""
).
replaceAll
(
NEW_LINE_CHARACTER_PATTERN
,
SPAN_ATTR_SPILT_CHARACTER
)
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
spanType
+
SPAN_FIELD_SPILT_PATTERN
);
toStringValue
.
append
(
isReceiver
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
businessKey
))
{
// 换行符在各个系统中表现不一致,
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue
.
append
(
businessKey
.
replaceAll
(
CARRIAGE_RETURN_CHARACTER_PATTERN
,
""
).
replaceAll
(
NEW_LINE_CHARACTER_PATTERN
,
SPAN_ATTR_SPILT_CHARACTER
)
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
processNo
))
{
toStringValue
.
append
(
processNo
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
applicationId
))
{
toStringValue
.
append
(
applicationId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
userId
))
{
toStringValue
.
append
(
userId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
callType
);
return
toStringValue
.
toString
();
}
protected
boolean
isNonBlank
(
String
str
)
{
return
str
!=
null
&&
str
.
length
()
>
0
;
}
public
void
handleException
(
Throwable
e
,
Set
<
String
>
exclusiveExceptionSet
,
int
maxExceptionStackLength
)
{
ByteArrayOutputStream
buf
=
null
;
StringBuilder
expMessage
=
new
StringBuilder
();
try
{
buf
=
new
ByteArrayOutputStream
();
Throwable
causeException
=
e
;
while
(
causeException
!=
null
&&
(
causeException
.
getCause
()
!=
null
||
expMessage
.
length
()
<
maxExceptionStackLength
))
{
causeException
.
printStackTrace
(
new
java
.
io
.
PrintWriter
(
buf
,
true
));
expMessage
.
append
(
buf
.
toString
());
causeException
=
causeException
.
getCause
();
}
}
finally
{
try
{
buf
.
close
();
}
catch
(
IOException
ioe
)
{
logger
.
log
(
Level
.
ALL
,
"Close exception stack input stream failed"
,
ioe
);
}
}
this
.
exceptionStack
=
expMessage
.
toString
();
if
(!
exclusiveExceptionSet
.
contains
(
e
.
getClass
().
getName
()))
{
this
.
statusCode
=
1
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录