Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Jun 27, 2014
1 parent 7a5b3c1 commit cab0b97
Showing 1 changed file with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
import org.springframework.util.StringUtils;

/**
* An implementation of {@link org.springframework.messaging.simp.SimpMessageSendingOperations}.
* An implementation of
* {@link org.springframework.messaging.simp.SimpMessageSendingOperations}.
*
* <p>Also provides methods for sending messages to a user. See
* {@link org.springframework.messaging.simp.user.UserDestinationResolver UserDestinationResolver}
* {@link org.springframework.messaging.simp.user.UserDestinationResolver
* UserDestinationResolver}
* for more on user destinations.
*
* @author Rossen Stoyanchev
Expand All @@ -47,19 +49,19 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String

private final MessageChannel messageChannel;

private String userDestinationPrefix = "/user/";

private MessageHeaderInitializer headerInitializer;
private String destinationPrefix = "/user/";

private volatile long sendTimeout = -1;

private MessageHeaderInitializer headerInitializer;


/**
* Create a new {@link SimpMessagingTemplate} instance.
* @param messageChannel the message channel (must not be {@code null})
*/
public SimpMessagingTemplate(MessageChannel messageChannel) {
Assert.notNull(messageChannel, "MessageChannel must not be null");
Assert.notNull(messageChannel, "'messageChannel' must not be null");
this.messageChannel = messageChannel;
}

Expand All @@ -77,46 +79,46 @@ public MessageChannel getMessageChannel() {
* @see org.springframework.messaging.simp.user.UserDestinationMessageHandler
*/
public void setUserDestinationPrefix(String prefix) {
Assert.hasText(prefix, "'userDestinationPrefix' must not be empty");
this.userDestinationPrefix = prefix.endsWith("/") ? prefix : prefix + "/";
Assert.hasText(prefix, "'destinationPrefix' must not be empty");
this.destinationPrefix = prefix.endsWith("/") ? prefix : prefix + "/";

}

/**
* Return the configured user destination prefix.
*/
public String getUserDestinationPrefix() {
return this.userDestinationPrefix;
return this.destinationPrefix;
}

/**
* Configure a {@link MessageHeaderInitializer} to apply to the headers of all
* messages created through the {@code SimpMessagingTemplate}.
* <p>By default, this property is not set.
* Specify the timeout value to use for send operations (in milliseconds).
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
public void setSendTimeout(long sendTimeout) {
this.sendTimeout = sendTimeout;
}

/**
* Return the configured header initializer.
* Return the configured send timeout (in milliseconds).
*/
public MessageHeaderInitializer getHeaderInitializer() {
return this.headerInitializer;
public long getSendTimeout() {
return this.sendTimeout;
}

/**
* Specify the timeout value to use for send operations (in milliseconds).
* Configure a {@link MessageHeaderInitializer} to apply to the headers of all
* messages created through the {@code SimpMessagingTemplate}.
* <p>By default, this property is not set.
*/
public void setSendTimeout(long sendTimeout) {
this.sendTimeout = sendTimeout;
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
}

/**
* Return the configured send timeout (in milliseconds).
* Return the configured header initializer.
*/
public long getSendTimeout() {
return this.sendTimeout;
public MessageHeaderInitializer getHeaderInitializer() {
return this.headerInitializer;
}


Expand Down Expand Up @@ -220,7 +222,7 @@ public void convertAndSendToUser(String user, String destination, Object payload

Assert.notNull(user, "User must not be null");
user = StringUtils.replace(user, "/", "%2F");
super.convertAndSend(this.userDestinationPrefix + user + destination, payload, headers, postProcessor);
super.convertAndSend(this.destinationPrefix + user + destination, payload, headers, postProcessor);
}


Expand Down

0 comments on commit cab0b97

Please sign in to comment.