Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
7a85827c
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,发现更多精彩内容 >>
提交
7a85827c
编写于
7月 02, 2013
作者:
P
Phillip Webb
提交者:
Rossen Stoyanchev
7月 03, 2013
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish messaging code
Minor formatting and Javadoc changes.
上级
0a68c993
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
71 addition
and
52 deletion
+71
-52
spring-context/src/main/java/org/springframework/messaging/Message.java
.../src/main/java/org/springframework/messaging/Message.java
+7
-0
spring-context/src/main/java/org/springframework/messaging/MessageChannel.java
...in/java/org/springframework/messaging/MessageChannel.java
+16
-16
spring-context/src/main/java/org/springframework/messaging/MessageHandler.java
...in/java/org/springframework/messaging/MessageHandler.java
+9
-8
spring-context/src/main/java/org/springframework/messaging/MessageHeaders.java
...in/java/org/springframework/messaging/MessageHeaders.java
+10
-7
spring-context/src/main/java/org/springframework/messaging/MessagingException.java
...ava/org/springframework/messaging/MessagingException.java
+1
-0
spring-context/src/main/java/org/springframework/messaging/PollableChannel.java
...n/java/org/springframework/messaging/PollableChannel.java
+9
-11
spring-context/src/main/java/org/springframework/messaging/SubscribableChannel.java
...va/org/springframework/messaging/SubscribableChannel.java
+4
-0
spring-context/src/main/java/org/springframework/messaging/annotation/MessageMapping.java
.../springframework/messaging/annotation/MessageMapping.java
+0
-1
spring-context/src/main/java/org/springframework/messaging/support/ErrorMessage.java
...a/org/springframework/messaging/support/ErrorMessage.java
+2
-0
spring-context/src/main/java/org/springframework/messaging/support/GenericMessage.java
...org/springframework/messaging/support/GenericMessage.java
+2
-0
spring-context/src/main/java/org/springframework/messaging/support/MessageBuilder.java
...org/springframework/messaging/support/MessageBuilder.java
+5
-2
spring-context/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java
...ingframework/messaging/support/MessageHeaderAccessor.java
+4
-5
spring-context/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java
...mework/messaging/support/NativeMessageHeaderAccessor.java
+2
-2
未找到文件。
spring-context/src/main/java/org/springframework/messaging/Message.java
浏览文件 @
7a85827c
...
@@ -22,11 +22,18 @@ package org.springframework.messaging;
...
@@ -22,11 +22,18 @@ package org.springframework.messaging;
* @author Mark Fisher
* @author Mark Fisher
* @author Arjen Poutsma
* @author Arjen Poutsma
* @since 4.0
* @since 4.0
* @see org.springframework.messaging.support.MessageBuilder
*/
*/
public
interface
Message
<
T
>
{
public
interface
Message
<
T
>
{
/**
* Returns message headers for the message (never {@code null}).
*/
MessageHeaders
getHeaders
();
MessageHeaders
getHeaders
();
/**
* Returns the message payload.
*/
T
getPayload
();
T
getPayload
();
}
}
spring-context/src/main/java/org/springframework/messaging/MessageChannel.java
浏览文件 @
7a85827c
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org.springframework.messaging
;
package
org.springframework.messaging
;
/**
/**
* Base channel interface defining common behavior for sending messages.
* Base channel interface defining common behavior for sending messages.
*
*
...
@@ -25,31 +24,32 @@ package org.springframework.messaging;
...
@@ -25,31 +24,32 @@ package org.springframework.messaging;
*/
*/
public
interface
MessageChannel
{
public
interface
MessageChannel
{
/**
* Constant for sending a message without a prescribed timeout.
*/
public
static
final
long
INDEFINITE_TIMEOUT
=
-
1
;
/**
/**
* Send a {@link Message} to this channel. May throw a RuntimeException for
* Send a {@link Message} to this channel. May throw a RuntimeException for
* non-recoverable errors. Otherwise, if the Message cannot be sent for a
* non-recoverable errors. Otherwise, if the Message cannot be sent for a non-fatal
* non-fatal reason this method will return 'false', and if the Message is
* reason this method will return 'false', and if the Message is sent successfully, it
* sent successfully, it will return 'true'.
* will return 'true'.
*
* <p>Depending on the implementation, this method may block indefinitely.
* To provide a maximum wait time, use {@link #send(Message, long)}.
*
*
* <p>Depending on the implementation, this method may block indefinitely. To provide a
* maximum wait time, use {@link #send(Message, long)}.
* @param message the {@link Message} to send
* @param message the {@link Message} to send
*
* @return whether or not the Message has been sent successfully
* @return whether or not the Message has been sent successfully
*/
*/
boolean
send
(
Message
<?>
message
);
boolean
send
(
Message
<?>
message
);
/**
/**
* Send a message, blocking until either the message is accepted or the
* Send a message, blocking until either the message is accepted or the specified
* specified timeout period elapses.
* timeout period elapses.
*
* @param message the {@link Message} to send
* @param message the {@link Message} to send
* @param timeout the timeout in milliseconds
* @param timeout the timeout in milliseconds or #INDEFINITE_TIMEOUT
*
* @return {@code true} if the message is sent successfully, {@code false} if the
* @return <code>true</code> if the message is sent successfully,
* specified timeout period elapses or the send is interrupted
* <code>false</code> if the specified timeout period elapses or
* the send is interrupted
*/
*/
boolean
send
(
Message
<?>
message
,
long
timeout
);
boolean
send
(
Message
<?>
message
,
long
timeout
);
...
...
spring-context/src/main/java/org/springframework/messaging/MessageHandler.java
浏览文件 @
7a85827c
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org.springframework.messaging
;
package
org.springframework.messaging
;
/**
/**
* Base interface for any component that handles Messages.
* Base interface for any component that handles Messages.
*
*
...
@@ -27,25 +26,27 @@ package org.springframework.messaging;
...
@@ -27,25 +26,27 @@ package org.springframework.messaging;
public
interface
MessageHandler
{
public
interface
MessageHandler
{
/**
/**
* TODO: exceptions
*
* Handles the message if possible. If the handler cannot deal with the
* Handles the message if possible. If the handler cannot deal with the
* message this will result in a
<code>MessageRejectedException</code>
e.g.
* message this will result in a
{@code MessageRejectedException}
e.g.
* in case of a Selective Consumer. When a consumer tries to handle a
* in case of a Selective Consumer. When a consumer tries to handle a
* message, but fails to do so, a
<code>MessageHandlingException</code>
is
* message, but fails to do so, a
{@code MessageHandlingException}
is
* thrown. In the last case it is recommended to treat the message as tainted
* thrown. In the last case it is recommended to treat the message as tainted
* and go into an error scenario.
* and go into an error scenario.
* <p>
* <p>
* When the handling results in a failure of another message being sent
* When the handling results in a failure of another message being sent
* (e.g. a "reply" message), that failure will trigger a
* (e.g. a "reply" message), that failure will trigger a
*
<code>MessageDeliveryException</code>
.
*
{@code MessageDeliveryException}
.
*
*
* @param message the message to be handled
* @param message the message to be handled
* reply related to the handling of the message
*/
void
handleMessage
(
Message
<?>
message
)
throws
MessagingException
;
/*
* TODO: exceptions
* @throws org.springframework.integration.MessageRejectedException if the handler doesn't accept the message
* @throws org.springframework.integration.MessageRejectedException if the handler doesn't accept the message
* @throws org.springframework.integration.MessageHandlingException when something fails during the handling
* @throws org.springframework.integration.MessageHandlingException when something fails during the handling
* @throws org.springframework.integration.MessageDeliveryException when this handler failed to deliver the
* @throws org.springframework.integration.MessageDeliveryException when this handler failed to deliver the
* reply related to the handling of the message
*/
*/
void
handleMessage
(
Message
<?>
message
)
throws
MessagingException
;
}
}
spring-context/src/main/java/org/springframework/messaging/MessageHeaders.java
浏览文件 @
7a85827c
...
@@ -34,16 +34,18 @@ import org.apache.commons.logging.Log;
...
@@ -34,16 +34,18 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
/**
/**
* The headers for a {@link Message}.<br>
* The headers for a {@link Message}
* IMPORTANT: This class is immutable. Any mutating operation (e.g., put(..), putAll(..) etc.)
* will throw {@link UnsupportedOperationException}
*
*
* <p>To create MessageHeaders instance use fluent MessageBuilder API
* <p><b>IMPORTANT</b>: This class is immutable. Any mutating operation
* <pre>
* (e.g., put(..), putAll(..) etc.) will throw {@link UnsupportedOperationException}.
*
* <p>To create MessageHeaders instance use fluent
* {@link org.springframework.messaging.support.MessageBuilder MessageBuilder} API
* <pre class="code">
* MessageBuilder.withPayload("foo").setHeader("key1", "value1").setHeader("key2", "value2");
* MessageBuilder.withPayload("foo").setHeader("key1", "value1").setHeader("key2", "value2");
* </pre>
* </pre>
* or create an instance of GenericMessage passing payload as {@link Object} and headers as a regular {@link Map}
* or create an instance of GenericMessage passing payload as {@link Object} and headers as a regular {@link Map}
* <pre>
* <pre
class="code"
>
* Map headers = new HashMap();
* Map headers = new HashMap();
* headers.put("key1", "value1");
* headers.put("key1", "value1");
* headers.put("key2", "value2");
* headers.put("key2", "value2");
...
@@ -54,6 +56,7 @@ import org.apache.commons.logging.LogFactory;
...
@@ -54,6 +56,7 @@ import org.apache.commons.logging.LogFactory;
* @author Mark Fisher
* @author Mark Fisher
* @author Gary Russell
* @author Gary Russell
* @since 4.0
* @since 4.0
* @see org.springframework.messaging.support.MessageBuilder
*/
*/
public
final
class
MessageHeaders
implements
Map
<
String
,
Object
>,
Serializable
{
public
final
class
MessageHeaders
implements
Map
<
String
,
Object
>,
Serializable
{
...
@@ -61,6 +64,7 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
...
@@ -61,6 +64,7 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
private
static
final
Log
logger
=
LogFactory
.
getLog
(
MessageHeaders
.
class
);
private
static
final
Log
logger
=
LogFactory
.
getLog
(
MessageHeaders
.
class
);
private
static
volatile
IdGenerator
idGenerator
=
null
;
private
static
volatile
IdGenerator
idGenerator
=
null
;
/**
/**
...
@@ -79,7 +83,6 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
...
@@ -79,7 +83,6 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
public
static
final
String
CONTENT_TYPE
=
"contentType"
;
public
static
final
String
CONTENT_TYPE
=
"contentType"
;
public
static
final
List
<
String
>
HEADER_NAMES
=
Arrays
.
asList
(
ID
,
TIMESTAMP
);
public
static
final
List
<
String
>
HEADER_NAMES
=
Arrays
.
asList
(
ID
,
TIMESTAMP
);
...
...
spring-context/src/main/java/org/springframework/messaging/MessagingException.java
浏览文件 @
7a85827c
...
@@ -59,6 +59,7 @@ public class MessagingException extends RuntimeException {
...
@@ -59,6 +59,7 @@ public class MessagingException extends RuntimeException {
this
.
failedMessage
=
message
;
this
.
failedMessage
=
message
;
}
}
public
Message
<?>
getFailedMessage
()
{
public
Message
<?>
getFailedMessage
()
{
return
this
.
failedMessage
;
return
this
.
failedMessage
;
}
}
...
...
spring-context/src/main/java/org/springframework/messaging/PollableChannel.java
浏览文件 @
7a85827c
...
@@ -16,9 +16,9 @@
...
@@ -16,9 +16,9 @@
package
org.springframework.messaging
;
package
org.springframework.messaging
;
/**
/**
* Interface for Message Channels from which Messages may be actively received through polling.
* Interface for Message Channels from which Messages may be actively received through
* polling.
*
*
* @author Mark Fisher
* @author Mark Fisher
* @since 4.0
* @since 4.0
...
@@ -27,19 +27,17 @@ public interface PollableChannel extends MessageChannel {
...
@@ -27,19 +27,17 @@ public interface PollableChannel extends MessageChannel {
/**
/**
* Receive a message from this channel, blocking indefinitely if necessary.
* Receive a message from this channel, blocking indefinitely if necessary.
*
* @return the next available {@link Message} or {@code null} if interrupted
* @return the next available {@link Message} or <code>null</code> if interrupted
*/
*/
Message
<?>
receive
();
Message
<?>
receive
();
/**
/**
* Receive a message from this channel, blocking until either a message is
* Receive a message from this channel, blocking until either a message is available
* available or the specified timeout period elapses.
* or the specified timeout period elapses.
*
* @param timeout the timeout in milliseconds or
* @param timeout the timeout in milliseconds
* {@link MessageChannel#INDEFINITE_TIMEOUT}.
*
* @return the next available {@link Message} or {@code null} if the specified timeout
* @return the next available {@link Message} or <code>null</code> if the
* period elapses or the message reception is interrupted
* specified timeout period elapses or the message reception is interrupted
*/
*/
Message
<?>
receive
(
long
timeout
);
Message
<?>
receive
(
long
timeout
);
...
...
spring-context/src/main/java/org/springframework/messaging/SubscribableChannel.java
浏览文件 @
7a85827c
...
@@ -29,11 +29,15 @@ public interface SubscribableChannel extends MessageChannel {
...
@@ -29,11 +29,15 @@ public interface SubscribableChannel extends MessageChannel {
/**
/**
* Register a {@link MessageHandler} as a subscriber to this channel.
* Register a {@link MessageHandler} as a subscriber to this channel.
* @return {@code true} if the channel was not already subscribed to the specified
* handler
*/
*/
boolean
subscribe
(
MessageHandler
handler
);
boolean
subscribe
(
MessageHandler
handler
);
/**
/**
* Remove a {@link MessageHandler} from the subscribers of this channel.
* Remove a {@link MessageHandler} from the subscribers of this channel.
* @return {@code true} if the channel was previously subscribed to the specified
* handler
*/
*/
boolean
unsubscribe
(
MessageHandler
handler
);
boolean
unsubscribe
(
MessageHandler
handler
);
...
...
spring-context/src/main/java/org/springframework/messaging/annotation/MessageMapping.java
浏览文件 @
7a85827c
...
@@ -22,7 +22,6 @@ import java.lang.annotation.Retention;
...
@@ -22,7 +22,6 @@ import java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
java.lang.annotation.Target
;
/**
/**
* @author Rossen Stoyanchev
* @author Rossen Stoyanchev
* @since 4.0
* @since 4.0
...
...
spring-context/src/main/java/org/springframework/messaging/support/ErrorMessage.java
浏览文件 @
7a85827c
...
@@ -25,11 +25,13 @@ import java.util.Map;
...
@@ -25,11 +25,13 @@ import java.util.Map;
* @author Mark Fisher
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Oleg Zhurakousky
* @since 4.0
* @since 4.0
* @see MessageBuilder
*/
*/
public
class
ErrorMessage
extends
GenericMessage
<
Throwable
>
{
public
class
ErrorMessage
extends
GenericMessage
<
Throwable
>
{
private
static
final
long
serialVersionUID
=
-
5470210965279837728L
;
private
static
final
long
serialVersionUID
=
-
5470210965279837728L
;
public
ErrorMessage
(
Throwable
payload
)
{
public
ErrorMessage
(
Throwable
payload
)
{
super
(
payload
);
super
(
payload
);
}
}
...
...
spring-context/src/main/java/org/springframework/messaging/support/GenericMessage.java
浏览文件 @
7a85827c
...
@@ -31,11 +31,13 @@ import org.springframework.util.ObjectUtils;
...
@@ -31,11 +31,13 @@ import org.springframework.util.ObjectUtils;
*
*
* @author Mark Fisher
* @author Mark Fisher
* @since 4.0
* @since 4.0
* @see MessageBuilder
*/
*/
public
class
GenericMessage
<
T
>
implements
Message
<
T
>,
Serializable
{
public
class
GenericMessage
<
T
>
implements
Message
<
T
>,
Serializable
{
private
static
final
long
serialVersionUID
=
-
9004496725833093406L
;
private
static
final
long
serialVersionUID
=
-
9004496725833093406L
;
private
final
T
payload
;
private
final
T
payload
;
private
final
MessageHeaders
headers
;
private
final
MessageHeaders
headers
;
...
...
spring-context/src/main/java/org/springframework/messaging/support/MessageBuilder.java
浏览文件 @
7a85827c
...
@@ -29,6 +29,8 @@ import org.springframework.util.Assert;
...
@@ -29,6 +29,8 @@ import org.springframework.util.Assert;
* @author Arjen Poutsma
* @author Arjen Poutsma
* @author Mark Fisher
* @author Mark Fisher
* @since 4.0
* @since 4.0
* @see GenericMessage
* @see ErrorMessage
*/
*/
public
final
class
MessageBuilder
<
T
>
{
public
final
class
MessageBuilder
<
T
>
{
...
@@ -49,6 +51,7 @@ public final class MessageBuilder<T> {
...
@@ -49,6 +51,7 @@ public final class MessageBuilder<T> {
this
.
headerAccessor
=
new
MessageHeaderAccessor
(
originalMessage
);
this
.
headerAccessor
=
new
MessageHeaderAccessor
(
originalMessage
);
}
}
/**
/**
* Create a builder for a new {@link Message} instance pre-populated with all of the
* Create a builder for a new {@link Message} instance pre-populated with all of the
* headers copied from the provided message. The payload of the provided Message will
* headers copied from the provided message. The payload of the provided Message will
...
@@ -73,8 +76,8 @@ public final class MessageBuilder<T> {
...
@@ -73,8 +76,8 @@ public final class MessageBuilder<T> {
}
}
/**
/**
* Set the value for the given header name. If the provided value is
<code>null</code>
* Set the value for the given header name. If the provided value is
{@code null},
*
,
the header will be removed.
* the header will be removed.
*/
*/
public
MessageBuilder
<
T
>
setHeader
(
String
headerName
,
Object
headerValue
)
{
public
MessageBuilder
<
T
>
setHeader
(
String
headerName
,
Object
headerValue
)
{
this
.
headerAccessor
.
setHeader
(
headerName
,
headerValue
);
this
.
headerAccessor
.
setHeader
(
headerName
,
headerValue
);
...
...
spring-context/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java
浏览文件 @
7a85827c
...
@@ -32,14 +32,13 @@ import org.springframework.util.ObjectUtils;
...
@@ -32,14 +32,13 @@ import org.springframework.util.ObjectUtils;
import
org.springframework.util.PatternMatchUtils
;
import
org.springframework.util.PatternMatchUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
* A base class for read/write access to {@link MessageHeaders}. Supports creation of new
* A base class for read/write access to {@link MessageHeaders}. Supports creation of new
* headers or modification of existing message headers.
* headers or modification of existing message headers.
*
<p>
*
*
Sub-classes can provide additional typed getters and setters for convenient access to
*
<p>Sub-classes can provide additional typed getters and setters for convenient access
*
specific headers. Getters and setters should delegate to {@link #getHeader(String)} or
*
to specific headers. Getters and setters should delegate to {@link #getHeader(String)}
* {@link #setHeader(String, Object)} respectively. At the end {@link #toMap()} can be
*
or
{@link #setHeader(String, Object)} respectively. At the end {@link #toMap()} can be
* used to obtain the resulting headers.
* used to obtain the resulting headers.
*
*
* @author Rossen Stoyanchev
* @author Rossen Stoyanchev
...
...
spring-context/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java
浏览文件 @
7a85827c
...
@@ -26,7 +26,6 @@ import org.springframework.util.LinkedMultiValueMap;
...
@@ -26,7 +26,6 @@ import org.springframework.util.LinkedMultiValueMap;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
/**
/**
* An extension of {@link MessageHeaderAccessor} that also provides read/write access to
* An extension of {@link MessageHeaderAccessor} that also provides read/write access to
* message headers from an external message source. Native message headers are kept
* message headers from an external message source. Native message headers are kept
...
@@ -37,9 +36,9 @@ import org.springframework.util.ObjectUtils;
...
@@ -37,9 +36,9 @@ import org.springframework.util.ObjectUtils;
*/
*/
public
class
NativeMessageHeaderAccessor
extends
MessageHeaderAccessor
{
public
class
NativeMessageHeaderAccessor
extends
MessageHeaderAccessor
{
public
static
final
String
NATIVE_HEADERS
=
"nativeHeaders"
;
public
static
final
String
NATIVE_HEADERS
=
"nativeHeaders"
;
// wrapped native headers
// wrapped native headers
private
final
Map
<
String
,
List
<
String
>>
originalNativeHeaders
;
private
final
Map
<
String
,
List
<
String
>>
originalNativeHeaders
;
...
@@ -63,6 +62,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
...
@@ -63,6 +62,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
this
.
originalNativeHeaders
=
initNativeHeaders
(
message
);
this
.
originalNativeHeaders
=
initNativeHeaders
(
message
);
}
}
private
static
Map
<
String
,
List
<
String
>>
initNativeHeaders
(
Message
<?>
message
)
{
private
static
Map
<
String
,
List
<
String
>>
initNativeHeaders
(
Message
<?>
message
)
{
if
(
message
!=
null
)
{
if
(
message
!=
null
)
{
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录