5
5
* you may not use this file except in compliance with the License.
6
6
* You may obtain a copy of the License at
7
7
*
8
- * http://www.apache.org/licenses/LICENSE-2.0
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
9
*
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
37
37
* @author Rossen Stoyanchev
38
38
* @since 4.0
39
39
*/
40
- public abstract class AbstractMessageChannel implements MessageChannel , BeanNameAware , InterceptableChannel {
40
+ public abstract class AbstractMessageChannel implements MessageChannel , InterceptableChannel , BeanNameAware {
41
41
42
42
protected final Log logger = LogFactory .getLog (getClass ());
43
43
@@ -50,22 +50,23 @@ public AbstractMessageChannel() {
50
50
this .beanName = getClass ().getSimpleName () + "@" + ObjectUtils .getIdentityHexString (this );
51
51
}
52
52
53
+
53
54
/**
54
- * {@inheritDoc}
55
- * <p>Used primarily for logging purposes.
55
+ * A message channel uses the bean name primarily for logging purposes.
56
56
*/
57
57
@ Override
58
58
public void setBeanName (String name ) {
59
59
this .beanName = name ;
60
60
}
61
61
62
62
/**
63
- * @return the name for this channel.
63
+ * Return the bean name for this message channel.
64
64
*/
65
65
public String getBeanName () {
66
66
return this .beanName ;
67
67
}
68
68
69
+
69
70
@ Override
70
71
public void setInterceptors (List <ChannelInterceptor > interceptors ) {
71
72
this .interceptors .clear ();
@@ -82,10 +83,6 @@ public void addInterceptor(int index, ChannelInterceptor interceptor) {
82
83
this .interceptors .add (index , interceptor );
83
84
}
84
85
85
- /**
86
- * {@inheritDoc}
87
- * <p>The returned list is read-only.
88
- */
89
86
@ Override
90
87
public List <ChannelInterceptor > getInterceptors () {
91
88
return Collections .unmodifiableList (this .interceptors );
@@ -101,6 +98,7 @@ public ChannelInterceptor removeInterceptor(int index) {
101
98
return this .interceptors .remove (index );
102
99
}
103
100
101
+
104
102
@ Override
105
103
public final boolean send (Message <?> message ) {
106
104
return send (message , INDEFINITE_TIMEOUT );
@@ -129,7 +127,8 @@ public final boolean send(Message<?> message, long timeout) {
129
127
throw new MessageDeliveryException (message ,"Failed to send message to " + this , ex );
130
128
}
131
129
catch (Error ex ) {
132
- MessageDeliveryException ex2 = new MessageDeliveryException (message , "Failed to send message to " + this , ex );
130
+ MessageDeliveryException ex2 =
131
+ new MessageDeliveryException (message , "Failed to send message to " + this , ex );
133
132
chain .triggerAfterSendCompletion (message , this , sent , ex2 );
134
133
throw ex2 ;
135
134
}
@@ -153,21 +152,22 @@ protected class ChannelInterceptorChain {
153
152
154
153
private int receiveInterceptorIndex = -1 ;
155
154
156
-
157
155
public Message <?> applyPreSend (Message <?> message , MessageChannel channel ) {
156
+ Message <?> messageToUse = message ;
158
157
for (ChannelInterceptor interceptor : interceptors ) {
159
- message = interceptor .preSend (message , channel );
160
- if (message == null ) {
158
+ Message <?> resolvedMessage = interceptor .preSend (messageToUse , channel );
159
+ if (resolvedMessage == null ) {
161
160
String name = interceptor .getClass ().getSimpleName ();
162
161
if (logger .isDebugEnabled ()) {
163
162
logger .debug (name + " returned null from preSend, i.e. precluding the send." );
164
163
}
165
- triggerAfterSendCompletion (message , channel , false , null );
164
+ triggerAfterSendCompletion (messageToUse , channel , false , null );
166
165
return null ;
167
166
}
167
+ messageToUse = resolvedMessage ;
168
168
this .sendInterceptorIndex ++;
169
169
}
170
- return message ;
170
+ return messageToUse ;
171
171
}
172
172
173
173
public void applyPostSend (Message <?> message , MessageChannel channel , boolean sent ) {
@@ -216,11 +216,12 @@ public void triggerAfterReceiveCompletion(Message<?> message, MessageChannel cha
216
216
interceptor .afterReceiveCompletion (message , channel , ex );
217
217
}
218
218
catch (Throwable ex2 ) {
219
- logger .error ("Exception from afterReceiveCompletion in " + interceptor , ex2 );
219
+ if (logger .isErrorEnabled ()) {
220
+ logger .error ("Exception from afterReceiveCompletion in " + interceptor , ex2 );
221
+ }
220
222
}
221
223
}
222
224
}
223
-
224
225
}
225
226
226
- }
227
+ }
0 commit comments