Skip to content

Commit 02403f6

Browse files
committed
Polishing
1 parent 11881ff commit 02403f6

File tree

10 files changed

+61
-75
lines changed

10 files changed

+61
-75
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/broker/OrderedMessageSender.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.messaging.simp.broker;
1718

1819
import java.util.Queue;
@@ -21,6 +22,7 @@
2122

2223
import org.apache.commons.logging.Log;
2324

25+
import org.springframework.lang.Nullable;
2426
import org.springframework.messaging.Message;
2527
import org.springframework.messaging.MessageChannel;
2628
import org.springframework.messaging.MessageHandler;
@@ -31,8 +33,8 @@
3133
import org.springframework.util.Assert;
3234

3335
/**
34-
* Submit messages to an ExecutorSubscribableChannel, one at a time. The channel
35-
* must have been configured with {@link #configureOutboundChannel}.
36+
* Submit messages to an {@link ExecutorSubscribableChannel}, one at a time.
37+
* The channel must have been configured with {@link #configureOutboundChannel}.
3638
*
3739
* @author Rossen Stoyanchev
3840
* @since 5.1
@@ -69,7 +71,6 @@ public boolean send(Message<?> message, long timeout) {
6971
}
7072

7173
private void trySend() {
72-
7374
// Take sendInProgress flag only if queue is not empty
7475
if (this.messages.isEmpty()) {
7576
return;
@@ -141,7 +142,9 @@ else if (channel instanceof ExecutorSubscribableChannel) {
141142
private static class CallbackInterceptor implements ExecutorChannelInterceptor {
142143

143144
@Override
144-
public void afterMessageHandled(Message<?> msg, MessageChannel ch, MessageHandler handler, Exception ex) {
145+
public void afterMessageHandled(
146+
Message<?> msg, MessageChannel ch, MessageHandler handler, @Nullable Exception ex) {
147+
145148
Runnable task = (Runnable) msg.getHeaders().get(OrderedMessageSender.COMPLETION_TASK_HEADER);
146149
if (task != null) {
147150
task.run();

spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -162,30 +162,6 @@ protected String getUserDestinationPrefix() {
162162
return this.userDestinationPrefix;
163163
}
164164

165-
/**
166-
* Whether the client must receive messages in the order of publication.
167-
* <p>By default messages sent to the {@code "clientOutboundChannel"} may
168-
* not be processed in the same order because the channel is backed by a
169-
* ThreadPoolExecutor that in turn does not guarantee processing in order.
170-
* <p>When this flag is set to {@code true} messages within the same session
171-
* will be sent to the {@code "clientOutboundChannel"} one at a time in
172-
* order to preserve the order of publication. Enable this only if needed
173-
* since there is some performance overhead to keep messages in order.
174-
* @param preservePublishOrder whether to publish in order
175-
* @since 5.1
176-
*/
177-
public void setPreservePublishOrder(boolean preservePublishOrder) {
178-
this.preservePublishOrder = preservePublishOrder;
179-
}
180-
181-
/**
182-
* Whether to ensure messages are received in the order of publication.
183-
* @since 5.1
184-
*/
185-
protected boolean isPreservePublishOrder() {
186-
return this.preservePublishOrder;
187-
}
188-
189165
/**
190166
* Configure the PathMatcher to use to match the destinations of incoming
191167
* messages to {@code @MessageMapping} and {@code @SubscribeMapping} methods.
@@ -225,6 +201,21 @@ public MessageBrokerRegistry setCacheLimit(int cacheLimit) {
225201
return this;
226202
}
227203

204+
/**
205+
* Whether the client must receive messages in the order of publication.
206+
* <p>By default messages sent to the {@code "clientOutboundChannel"} may
207+
* not be processed in the same order because the channel is backed by a
208+
* ThreadPoolExecutor that in turn does not guarantee processing in order.
209+
* <p>When this flag is set to {@code true} messages within the same session
210+
* will be sent to the {@code "clientOutboundChannel"} one at a time in
211+
* order to preserve the order of publication. Enable this only if needed
212+
* since there is some performance overhead to keep messages in order.
213+
* @since 5.1
214+
*/
215+
public MessageBrokerRegistry setPreservePublishOrder(boolean preservePublishOrder) {
216+
this.preservePublishOrder = preservePublishOrder;
217+
return this;
218+
}
228219

229220
@Nullable
230221
protected SimpleBrokerMessageHandler getSimpleBroker(SubscribableChannel brokerChannel) {

spring-messaging/src/main/java/org/springframework/messaging/support/ChannelInterceptor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,8 @@
2828
* @author Mark Fisher
2929
* @author Rossen Stoyanchev
3030
* @since 4.0
31+
* @see Message
32+
* @see MessageChannel
3133
*/
3234
public interface ChannelInterceptor {
3335

@@ -56,8 +58,8 @@ default void postSend(Message<?> message, MessageChannel channel, boolean sent)
5658
* completed and returned a Message, i.e. it did not return {@code null}.
5759
* @since 4.1
5860
*/
59-
default void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent,
60-
@Nullable Exception ex) {
61+
default void afterSendCompletion(
62+
Message<?> message, MessageChannel channel, boolean sent, @Nullable Exception ex) {
6163
}
6264

6365
/**

spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorChannelInterceptor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,10 +26,13 @@
2626
* asynchronous sending of a {@link org.springframework.messaging.Message} to
2727
* a specific subscriber through an {@link java.util.concurrent.Executor}.
2828
* Supported on {@link org.springframework.messaging.MessageChannel}
29-
* implementations that can be configured with an Executor.
29+
* implementations that can be configured with an {@code Executor}.
3030
*
3131
* @author Rossen Stoyanchev
3232
* @since 4.1
33+
* @see Message
34+
* @see MessageChannel
35+
* @see MessageHandler
3336
*/
3437
public interface ExecutorChannelInterceptor extends ChannelInterceptor {
3538

spring-messaging/src/test/java/org/springframework/messaging/simp/broker/OrderedMessageSenderTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.messaging.simp.broker;
1718

1819
import java.util.concurrent.CountDownLatch;

spring-messaging/src/test/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandlerTests.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ public void setup() {
7777

7878

7979
@Test
80-
public void subcribePublish() {
81-
80+
public void subscribePublish() {
8281
startSession("sess1");
8382
startSession("sess2");
8483

@@ -103,8 +102,7 @@ public void subcribePublish() {
103102
}
104103

105104
@Test
106-
public void subcribeDisconnectPublish() {
107-
105+
public void subscribeDisconnectPublish() {
108106
String sess1 = "sess1";
109107
String sess2 = "sess2";
110108

@@ -308,9 +306,9 @@ private Message<String> startSession(String id) {
308306
return connectMessage;
309307
}
310308

311-
private Message<String> createSubscriptionMessage(String sessionId, String subcriptionId, String destination) {
309+
private Message<String> createSubscriptionMessage(String sessionId, String subscriptionId, String destination) {
312310
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
313-
headers.setSubscriptionId(subcriptionId);
311+
headers.setSubscriptionId(subscriptionId);
314312
headers.setDestination(destination);
315313
headers.setSessionId(sessionId);
316314
return MessageBuilder.createMessage("", headers.getMessageHeaders());
@@ -330,11 +328,11 @@ private Message<String> createMessage(String destination, String payload) {
330328
return MessageBuilder.createMessage(payload, headers.getMessageHeaders());
331329
}
332330

333-
private boolean messageCaptured(String sessionId, String subcriptionId, String destination) {
331+
private boolean messageCaptured(String sessionId, String subscriptionId, String destination) {
334332
for (Message<?> message : this.messageCaptor.getAllValues()) {
335333
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
336334
if (sessionId.equals(headers.getSessionId())) {
337-
if (subcriptionId.equals(headers.getSubscriptionId())) {
335+
if (subscriptionId.equals(headers.getSubscriptionId())) {
338336
if (destination.equals(headers.getDestination())) {
339337
return true;
340338
}

spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,10 @@ public void clientInboundChannelCustomized() {
117117

118118
AbstractSubscribableChannel channel = context.getBean(
119119
"clientInboundChannel", AbstractSubscribableChannel.class);
120-
121120
assertEquals(3, channel.getInterceptors().size());
122121

123122
CustomThreadPoolTaskExecutor taskExecutor = context.getBean(
124123
"clientInboundChannelExecutor", CustomThreadPoolTaskExecutor.class);
125-
126124
assertEquals(11, taskExecutor.getCorePoolSize());
127125
assertEquals(12, taskExecutor.getMaxPoolSize());
128126
assertEquals(13, taskExecutor.getKeepAliveSeconds());
@@ -512,7 +510,6 @@ private void testDotSeparator(ApplicationContext context, boolean expectLeadingS
512510
assertEquals("123", new String((byte[]) outputMessage.getPayload()));
513511
outChannel.messages.clear();
514512

515-
516513
// 3. Send message via broker channel
517514

518515
SimpMessagingTemplate template = new SimpMessagingTemplate(brokerChannel);

spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerIntegrationTests.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@
4949
import org.springframework.util.Assert;
5050
import org.springframework.util.SocketUtils;
5151

52-
import static org.junit.Assert.assertEquals;
53-
import static org.junit.Assert.assertNotNull;
54-
import static org.junit.Assert.assertTrue;
52+
import static org.junit.Assert.*;
5553

5654
/**
5755
* Integration tests for {@link StompBrokerRelayMessageHandler} running against ActiveMQ.
@@ -79,7 +77,7 @@ public class StompBrokerRelayMessageHandlerIntegrationTests {
7977

8078

8179
@Before
82-
public void setUp() throws Exception {
80+
public void setup() throws Exception {
8381
logger.debug("Setting up before '" + this.testName.getMethodName() + "'");
8482
this.port = SocketUtils.findAvailableTcpPort(61613);
8583
this.responseChannel = new ExecutorSubscribableChannel();
@@ -116,7 +114,7 @@ private void createAndStartRelay() throws InterruptedException {
116114
}
117115

118116
@After
119-
public void tearDown() throws Exception {
117+
public void stop() throws Exception {
120118
try {
121119
logger.debug("STOMP broker relay stats: " + this.relay.getStatsInfo());
122120
this.relay.stop();
@@ -170,7 +168,6 @@ public void publishSubscribe() throws Exception {
170168

171169
@Test(expected = MessageDeliveryException.class)
172170
public void messageDeliveryExceptionIfSystemSessionForwardFails() throws Exception {
173-
174171
logger.debug("Starting test messageDeliveryExceptionIfSystemSessionForwardFails()");
175172

176173
stopActiveMqBrokerAndAwait();
@@ -181,8 +178,8 @@ public void messageDeliveryExceptionIfSystemSessionForwardFails() throws Excepti
181178
}
182179

183180
@Test
184-
public void brokerBecomingUnvailableTriggersErrorFrame() throws Exception {
185-
logger.debug("Starting test brokerBecomingUnvailableTriggersErrorFrame()");
181+
public void brokerBecomingUnavailableTriggersErrorFrame() throws Exception {
182+
logger.debug("Starting test brokerBecomingUnavailableTriggersErrorFrame()");
186183

187184
String sess1 = "sess1";
188185
MessageExchange connect = MessageExchangeBuilder.connect(sess1).build();

spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ public void simpleBroker() throws Exception {
210210
assertArrayEquals(new long[] {15000, 15000}, brokerMessageHandler.getHeartbeatValue());
211211
assertTrue(brokerMessageHandler.isPreservePublishOrder());
212212

213-
List<Class<? extends MessageHandler>> subscriberTypes =
214-
Arrays.asList(SimpAnnotationMethodMessageHandler.class,
213+
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class,
215214
UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class);
216215
testChannel("clientInboundChannel", subscriberTypes, 2);
217216
testExecutor("clientInboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
@@ -220,8 +219,7 @@ public void simpleBroker() throws Exception {
220219
testChannel("clientOutboundChannel", subscriberTypes, 2);
221220
testExecutor("clientOutboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
222221

223-
subscriberTypes = Arrays.asList(
224-
SimpleBrokerMessageHandler.class, UserDestinationMessageHandler.class);
222+
subscriberTypes = Arrays.asList(SimpleBrokerMessageHandler.class, UserDestinationMessageHandler.class);
225223
testChannel("brokerChannel", subscriberTypes, 1);
226224
try {
227225
this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class);
@@ -281,9 +279,8 @@ public void stompBrokerRelay() {
281279
assertThat(messageBroker.getDestinationPrefixes(), Matchers.containsInAnyOrder("/topic","/queue"));
282280
assertTrue(messageBroker.isPreservePublishOrder());
283281

284-
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(
285-
SimpAnnotationMethodMessageHandler.class, UserDestinationMessageHandler.class,
286-
StompBrokerRelayMessageHandler.class);
282+
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class,
283+
UserDestinationMessageHandler.class, StompBrokerRelayMessageHandler.class);
287284
testChannel("clientInboundChannel", subscriberTypes, 2);
288285
testExecutor("clientInboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
289286

@@ -382,9 +379,8 @@ public void customChannels() {
382379
assertSame(this.appContext.getBean("myValidator"), validator);
383380
assertThat(validator, Matchers.instanceOf(TestValidator.class));
384381

385-
List<Class<? extends MessageHandler>> subscriberTypes =
386-
Arrays.<Class<? extends MessageHandler>>asList(SimpAnnotationMethodMessageHandler.class,
387-
UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class);
382+
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class,
383+
UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class);
388384

389385
testChannel("clientInboundChannel", subscriberTypes, 3);
390386
testExecutor("clientInboundChannel", 100, 200, 600);
@@ -394,16 +390,13 @@ public void customChannels() {
394390
testChannel("clientOutboundChannel", subscriberTypes, 3);
395391
testExecutor("clientOutboundChannel", 101, 201, 601);
396392

397-
subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(SimpleBrokerMessageHandler.class,
398-
UserDestinationMessageHandler.class);
393+
subscriberTypes = Arrays.asList(SimpleBrokerMessageHandler.class, UserDestinationMessageHandler.class);
399394

400395
testChannel("brokerChannel", subscriberTypes, 1);
401396
testExecutor("brokerChannel", 102, 202, 602);
402397
}
403398

404-
// SPR-11623
405-
406-
@Test
399+
@Test // SPR-11623
407400
public void customChannelsWithDefaultExecutor() {
408401
loadBeanDefinitions("websocket-config-broker-customchannels-default-executor.xml");
409402

spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,8 +57,8 @@
5757
import org.springframework.web.socket.handler.TextWebSocketHandler;
5858
import org.springframework.web.socket.server.HandshakeHandler;
5959

60-
import static org.junit.Assert.assertTrue;
61-
import static org.springframework.web.socket.messaging.StompTextMessageBuilder.create;
60+
import static org.junit.Assert.*;
61+
import static org.springframework.web.socket.messaging.StompTextMessageBuilder.*;
6262

6363
/**
6464
* Integration tests with annotated message-handling methods.
@@ -70,6 +70,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
7070

7171
private static final long TIMEOUT = 10;
7272

73+
7374
@Parameters(name = "server [{0}], client [{1}]")
7475
public static Object[][] arguments() {
7576
return new Object[][] {
@@ -266,7 +267,7 @@ public String getValue() {
266267
}
267268

268269

269-
static interface ScopedBean {
270+
interface ScopedBean {
270271

271272
String getValue();
272273
}
@@ -320,9 +321,9 @@ protected void handleTextMessage(WebSocketSession session, TextMessage message)
320321

321322
@Configuration
322323
@ComponentScan(
323-
basePackageClasses=StompWebSocketIntegrationTests.class,
324-
useDefaultFilters=false,
325-
includeFilters=@ComponentScan.Filter(IntegrationTestController.class))
324+
basePackageClasses = StompWebSocketIntegrationTests.class,
325+
useDefaultFilters = false,
326+
includeFilters = @ComponentScan.Filter(IntegrationTestController.class))
326327
static class TestMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer {
327328

328329
@Autowired

0 commit comments

Comments
 (0)