Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
ddf87505
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ddf87505
编写于
4月 04, 2014
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update MessageHeaders constructor
Following discussion with Gary. Issue: SPR-11468
上级
1eee339c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
11 deletion
+24
-11
spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java
...in/java/org/springframework/messaging/MessageHeaders.java
+22
-9
spring-messaging/src/test/java/org/springframework/messaging/MessageHeadersTests.java
...va/org/springframework/messaging/MessageHeadersTests.java
+2
-2
未找到文件。
spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java
浏览文件 @
ddf87505
...
...
@@ -34,6 +34,7 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.util.AlternativeJdkIdGenerator
;
import
org.springframework.util.Assert
;
import
org.springframework.util.IdGenerator
;
/**
...
...
@@ -96,24 +97,36 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
private
final
Map
<
String
,
Object
>
headers
;
/**
* Constructs a minimal {@link MessageHeaders} with zero headers.
*/
protected
MessageHeaders
()
{
this
.
headers
=
new
HashMap
<
String
,
Object
>();
}
/**
* Consructs a {@link MessageHeaders} from the headers map; adding (or
* overwriting) the {@link #ID} and {@link #TIMESTAMP} headers.
* @param headers
The map.
* @param headers
a map with headers to add
*/
public
MessageHeaders
(
Map
<
String
,
Object
>
headers
)
{
this
(
headers
,
((
idGenerator
!=
null
)
?
idGenerator
:
defaultIdGenerator
).
generateId
(),
System
.
currentTimeMillis
());
}
/**
* Constructor allowing a sub-class to access the (mutable) header map as well
* to provide the ID and TIMESTAMP header values.
*
* @param headers a map with headers to add
* @param id the value for the {@link #ID} header, never {@code null}
* @param timestamp the value for the {@link #TIMESTAMP} header,
* or {@code null} meaning no timestamp header
*/
protected
MessageHeaders
(
Map
<
String
,
Object
>
headers
,
UUID
id
,
Long
timestamp
)
{
Assert
.
notNull
(
id
,
"'id' is required"
);
this
.
headers
=
(
headers
!=
null
)
?
new
HashMap
<
String
,
Object
>(
headers
)
:
new
HashMap
<
String
,
Object
>();
this
.
headers
.
put
(
ID
,
((
idGenerator
!=
null
)
?
idGenerator
:
defaultIdGenerator
).
generateId
());
this
.
headers
.
put
(
TIMESTAMP
,
System
.
currentTimeMillis
());
this
.
headers
.
put
(
ID
,
id
);
if
(
timestamp
!=
null
)
{
this
.
headers
.
put
(
TIMESTAMP
,
timestamp
);
}
}
protected
Map
<
String
,
Object
>
getRawHeaders
()
{
return
this
.
headers
;
}
...
...
spring-messaging/src/test/java/org/springframework/messaging/MessageHeadersTests.java
浏览文件 @
ddf87505
...
...
@@ -142,13 +142,13 @@ public class MessageHeadersTests {
}
@Test
public
void
sub
class
()
{
public
void
sub
ClassWithCustomIdAndNoTimestamp
()
{
final
AtomicLong
id
=
new
AtomicLong
();
@SuppressWarnings
(
"serial"
)
class
MyMH
extends
MessageHeaders
{
public
MyMH
()
{
this
.
getRawHeaders
().
put
(
ID
,
new
UUID
(
0
,
id
.
incrementAndGet
())
);
super
(
null
,
new
UUID
(
0
,
id
.
incrementAndGet
()),
null
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录