Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
f613c3b7
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
267
Star
16139
Fork
68
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f613c3b7
编写于
8月 11, 2017
作者:
Y
yukon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCKETMQ-259]Fix too many reflection calls when decode remoting command header
上级
f091203a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
12 deletion
+37
-12
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java
...rg/apache/rocketmq/remoting/protocol/RemotingCommand.java
+8
-12
remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingCommandTest.java
...pache/rocketmq/remoting/protocol/RemotingCommandTest.java
+29
-0
未找到文件。
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java
浏览文件 @
f613c3b7
...
...
@@ -43,7 +43,7 @@ public class RemotingCommand {
private
static
final
Map
<
Class
,
String
>
CANONICAL_NAME_CACHE
=
new
HashMap
<
Class
,
String
>();
// 1, Oneway
// 1, RESPONSE_COMMAND
private
static
final
Map
<
Field
,
Annotation
>
NOT_NULL_ANNOTATION_CACHE
=
new
HashMap
<
Field
,
Annotatio
n
>();
private
static
final
Map
<
Field
,
Boolean
>
NULLABLE_FIELD_CACHE
=
new
HashMap
<
Field
,
Boolea
n
>();
private
static
final
String
STRING_CANONICAL_NAME
=
String
.
class
.
getCanonicalName
();
private
static
final
String
DOUBLE_CANONICAL_NAME_1
=
Double
.
class
.
getCanonicalName
();
private
static
final
String
DOUBLE_CANONICAL_NAME_2
=
double
.
class
.
getCanonicalName
();
...
...
@@ -252,11 +252,9 @@ public class RemotingCommand {
try
{
String
value
=
this
.
extFields
.
get
(
fieldName
);
if
(
null
==
value
)
{
Annotation
annotation
=
getNotNullAnnotation
(
field
);
if
(
annotation
!=
null
)
{
if
(!
isFieldNullable
(
field
))
{
throw
new
RemotingCommandException
(
"the custom field <"
+
fieldName
+
"> is null"
);
}
continue
;
}
...
...
@@ -305,16 +303,14 @@ public class RemotingCommand {
return
field
;
}
private
Annotation
getNotNullAnnotation
(
Field
field
)
{
Annotation
annotation
=
NOT_NULL_ANNOTATION_CACHE
.
get
(
field
);
if
(
annotation
==
null
)
{
annotation
=
field
.
getAnnotation
(
CFNotNull
.
class
);
synchronized
(
NOT_NULL_ANNOTATION_CACHE
)
{
NOT_NULL_ANNOTATION_CACHE
.
put
(
field
,
annotation
);
private
boolean
isFieldNullable
(
Field
field
)
{
if
(!
NULLABLE_FIELD_CACHE
.
containsKey
(
field
))
{
Annotation
annotation
=
field
.
getAnnotation
(
CFNotNull
.
class
);
synchronized
(
NULLABLE_FIELD_CACHE
)
{
NULLABLE_FIELD_CACHE
.
put
(
field
,
annotation
==
null
);
}
}
return
annotation
;
return
NULLABLE_FIELD_CACHE
.
get
(
field
)
;
}
private
String
getCanonicalName
(
Class
clazz
)
{
...
...
remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingCommandTest.java
浏览文件 @
f613c3b7
...
...
@@ -16,8 +16,11 @@
*/
package
org.apache.rocketmq.remoting.protocol
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.nio.ByteBuffer
;
import
org.apache.rocketmq.remoting.CommandCustomHeader
;
import
org.apache.rocketmq.remoting.annotation.CFNotNull
;
import
org.apache.rocketmq.remoting.exception.RemotingCommandException
;
import
org.junit.Test
;
...
...
@@ -179,6 +182,32 @@ public class RemotingCommandTest {
assertThat
(((
ExtFieldsHeader
)
decodedHeader
).
isBooleanValue
()).
isEqualTo
(
true
);
assertThat
(((
ExtFieldsHeader
)
decodedHeader
).
getDoubleValue
()).
isBetween
(
0.617
,
0.619
);
}
@Test
public
void
testNotNullField
()
throws
Exception
{
RemotingCommand
remotingCommand
=
new
RemotingCommand
();
Method
method
=
RemotingCommand
.
class
.
getDeclaredMethod
(
"isFieldNullable"
,
Field
.
class
);
method
.
setAccessible
(
true
);
Field
nullString
=
FieldTestClass
.
class
.
getDeclaredField
(
"nullString"
);
assertThat
(
method
.
invoke
(
remotingCommand
,
nullString
)).
isEqualTo
(
false
);
Field
nullableString
=
FieldTestClass
.
class
.
getDeclaredField
(
"nullable"
);
assertThat
(
method
.
invoke
(
remotingCommand
,
nullableString
)).
isEqualTo
(
true
);
Field
value
=
FieldTestClass
.
class
.
getDeclaredField
(
"value"
);
assertThat
(
method
.
invoke
(
remotingCommand
,
value
)).
isEqualTo
(
false
);
}
}
class
FieldTestClass
{
@CFNotNull
String
nullString
=
null
;
String
nullable
=
null
;
@CFNotNull
String
value
=
"NotNull"
;
}
class
SampleCommandCustomHeader
implements
CommandCustomHeader
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录