From eb3509a37c5e28e5b44534341ee2e16b761090ea Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 23 Aug 2014 02:02:38 +0200 Subject: [PATCH] Polishing --- .../simp/config/MessageBrokerRegistry.java | 51 ++++++++++--------- .../simp/config/SimpleBrokerRegistration.java | 10 ++-- .../config/StompBrokerRelayRegistration.java | 14 ++--- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java index 11400f9eef..2c9165820b 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java @@ -41,12 +41,12 @@ public class MessageBrokerRegistry { private StompBrokerRelayRegistration brokerRelayRegistration; + private final ChannelRegistration brokerChannelRegistration = new ChannelRegistration(); + private String[] applicationDestinationPrefixes; private String userDestinationPrefix; - private ChannelRegistration brokerChannelRegistration = new ChannelRegistration(); - public MessageBrokerRegistry(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) { Assert.notNull(clientInboundChannel); @@ -55,6 +55,7 @@ public class MessageBrokerRegistry { this.clientOutboundChannel = clientOutboundChannel; } + /** * Enable a simple message broker and configure one or more prefixes to filter * destinations targeting the broker (e.g. destinations prefixed with "/topic"). @@ -76,6 +77,21 @@ public class MessageBrokerRegistry { return this.brokerRelayRegistration; } + /** + * Customize the channel used to send messages from the application to the message + * broker. By default, messages from the application to the message broker are sent + * synchronously, which means application code sending a message will find out + * if the message cannot be sent through an exception. However, this can be changed + * if the broker channel is configured here with task executor properties. + */ + public ChannelRegistration configureBrokerChannel() { + return this.brokerChannelRegistration; + } + + protected ChannelRegistration getBrokerChannelRegistration() { + return this.brokerChannelRegistration; + } + /** * Configure one or more prefixes to filter destinations targeting application * annotated methods. For example destinations prefixed with "/app" may be @@ -91,6 +107,11 @@ public class MessageBrokerRegistry { return this; } + protected Collection getApplicationDestinationPrefixes() { + return (this.applicationDestinationPrefixes != null ? + Arrays.asList(this.applicationDestinationPrefixes) : null); + } + /** * Configure the prefix used to identify user destinations. User destinations * provide the ability for a user to subscribe to queue names unique to their @@ -108,19 +129,13 @@ public class MessageBrokerRegistry { return this; } - /** - * Customize the channel used to send messages from the application to the message - * broker. By default messages from the application to the message broker are sent - * synchronously, which means application code sending a message will find out - * if the message cannot be sent through an exception. However, this can be changed - * if the broker channel is configured here with task executor properties. - */ - public ChannelRegistration configureBrokerChannel() { - return this.brokerChannelRegistration; + protected String getUserDestinationPrefix() { + return this.userDestinationPrefix; } + protected SimpleBrokerMessageHandler getSimpleBroker(SubscribableChannel brokerChannel) { - if ((this.simpleBrokerRegistration == null) && (this.brokerRelayRegistration == null)) { + if (this.simpleBrokerRegistration == null && this.brokerRelayRegistration == null) { enableSimpleBroker(); } if (this.simpleBrokerRegistration != null) { @@ -136,16 +151,4 @@ public class MessageBrokerRegistry { return null; } - protected Collection getApplicationDestinationPrefixes() { - return (this.applicationDestinationPrefixes != null) - ? Arrays.asList(this.applicationDestinationPrefixes) : null; - } - - protected String getUserDestinationPrefix() { - return this.userDestinationPrefix; - } - - protected ChannelRegistration getBrokerChannelRegistration() { - return this.brokerChannelRegistration; - } } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/SimpleBrokerRegistration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/SimpleBrokerRegistration.java index 2c683ebe34..bd6073cb03 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/SimpleBrokerRegistration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/SimpleBrokerRegistration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,14 +28,10 @@ import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler; */ public class SimpleBrokerRegistration extends AbstractBrokerRegistration { - - public SimpleBrokerRegistration(SubscribableChannel clientInboundChannel, - MessageChannel clientOutboundChannel, String[] destinationPrefixes) { - - super(clientInboundChannel, clientOutboundChannel, destinationPrefixes); + public SimpleBrokerRegistration(SubscribableChannel inChannel, MessageChannel outChannel, String[] prefixes) { + super(inChannel, outChannel, prefixes); } - @Override protected SimpleBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel) { return new SimpleBrokerMessageHandler(getClientInboundChannel(), diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java index c0580f1816..9efc8e2119 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java @@ -74,12 +74,10 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration { return this; } - /** * Set the login to use when creating connections to the STOMP broker on * behalf of connected clients. - *

- * By default this is set to "guest". + *

By default this is set to "guest". */ public StompBrokerRelayRegistration setClientLogin(String login) { Assert.hasText(login, "clientLogin must not be empty"); @@ -90,8 +88,7 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration { /** * Set the passcode to use when creating connections to the STOMP broker on * behalf of connected clients. - *

- * By default this is set to "guest". + *

By default this is set to "guest". */ public StompBrokerRelayRegistration setClientPasscode(String passcode) { Assert.hasText(passcode, "clientPasscode must not be empty"); @@ -103,8 +100,7 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration { * Set the login for the shared "system" connection used to send messages to * the STOMP broker from within the application, i.e. messages not associated * with a specific client session (e.g. REST/HTTP request handling method). - *

- * By default this is set to "guest". + *

By default this is set to "guest". */ public StompBrokerRelayRegistration setSystemLogin(String login) { Assert.hasText(login, "systemLogin must not be empty"); @@ -116,8 +112,7 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration { * Set the passcode for the shared "system" connection used to send messages to * the STOMP broker from within the application, i.e. messages not associated * with a specific client session (e.g. REST/HTTP request handling method). - *

- * By default this is set to "guest". + *

By default this is set to "guest". */ public StompBrokerRelayRegistration setSystemPasscode(String passcode) { Assert.hasText(passcode, "systemPasscode must not be empty"); @@ -173,7 +168,6 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration { protected StompBrokerRelayMessageHandler getMessageHandler(SubscribableChannel brokerChannel) { - StompBrokerRelayMessageHandler handler = new StompBrokerRelayMessageHandler(getClientInboundChannel(), getClientOutboundChannel(), brokerChannel, getDestinationPrefixes());