Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -50,7 +50,7 @@ import org.springframework.util.PathMatcher;
|
||||
* in memory and uses a {@link org.springframework.util.PathMatcher PathMatcher}
|
||||
* for matching destinations.
|
||||
*
|
||||
* <p>As of 4.2 this class supports a {@link #setSelectorHeaderName selector}
|
||||
* <p>As of 4.2, this class supports a {@link #setSelectorHeaderName selector}
|
||||
* header on subscription messages with Spring EL expressions evaluated against
|
||||
* the headers to filter out messages in addition to destination matching.
|
||||
*
|
||||
@@ -65,11 +65,10 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
|
||||
public static final int DEFAULT_CACHE_LIMIT = 1024;
|
||||
|
||||
|
||||
/** The maximum number of entries in the cache */
|
||||
private volatile int cacheLimit = DEFAULT_CACHE_LIMIT;
|
||||
|
||||
private PathMatcher pathMatcher = new AntPathMatcher();
|
||||
|
||||
private volatile int cacheLimit = DEFAULT_CACHE_LIMIT;
|
||||
|
||||
private String selectorHeaderName = "selector";
|
||||
|
||||
private volatile boolean selectorHeaderInUse = false;
|
||||
@@ -81,6 +80,20 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
|
||||
private final SessionSubscriptionRegistry subscriptionRegistry = new SessionSubscriptionRegistry();
|
||||
|
||||
|
||||
/**
|
||||
* Specify the {@link PathMatcher} to use.
|
||||
*/
|
||||
public void setPathMatcher(PathMatcher pathMatcher) {
|
||||
this.pathMatcher = pathMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured {@link PathMatcher}.
|
||||
*/
|
||||
public PathMatcher getPathMatcher() {
|
||||
return this.pathMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the maximum number of entries for the resolved destination cache.
|
||||
* Default is 1024.
|
||||
@@ -96,20 +109,6 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
|
||||
return this.cacheLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the {@link PathMatcher} to use.
|
||||
*/
|
||||
public void setPathMatcher(PathMatcher pathMatcher) {
|
||||
this.pathMatcher = pathMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured {@link PathMatcher}.
|
||||
*/
|
||||
public PathMatcher getPathMatcher() {
|
||||
return this.pathMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the name of a selector header that a subscription message can
|
||||
* have in order to filter messages based on their headers. The value of the
|
||||
@@ -123,12 +122,13 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
|
||||
* @since 4.2
|
||||
*/
|
||||
public void setSelectorHeaderName(String selectorHeaderName) {
|
||||
Assert.notNull(selectorHeaderName);
|
||||
Assert.notNull(selectorHeaderName, "'selectorHeaderName' must not be null");
|
||||
this.selectorHeaderName = selectorHeaderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name for the selector header.
|
||||
* @since 4.2
|
||||
*/
|
||||
public String getSelectorHeaderName() {
|
||||
return this.selectorHeaderName;
|
||||
|
||||
@@ -92,27 +92,30 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
|
||||
initPathMatcherToUse();
|
||||
}
|
||||
|
||||
private void initPathMatcherToUse() {
|
||||
if (this.pathMatcher != null) {
|
||||
if (this.subscriptionRegistry instanceof DefaultSubscriptionRegistry) {
|
||||
((DefaultSubscriptionRegistry) this.subscriptionRegistry).setPathMatcher(this.pathMatcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SubscriptionRegistry getSubscriptionRegistry() {
|
||||
return this.subscriptionRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* When configured, the given PathMatcher is passed down to the
|
||||
* When configured, the given PathMatcher is passed down to the underlying
|
||||
* SubscriptionRegistry to use for matching destination to subscriptions.
|
||||
* <p>Default is a standard {@link org.springframework.util.AntPathMatcher}.
|
||||
* @since 4.1
|
||||
* @see #setSubscriptionRegistry
|
||||
* @see DefaultSubscriptionRegistry#setPathMatcher
|
||||
* @see org.springframework.util.AntPathMatcher
|
||||
*/
|
||||
public void setPathMatcher(PathMatcher pathMatcher) {
|
||||
this.pathMatcher = pathMatcher;
|
||||
initPathMatcherToUse();
|
||||
}
|
||||
|
||||
private void initPathMatcherToUse() {
|
||||
if (this.pathMatcher != null && this.subscriptionRegistry instanceof DefaultSubscriptionRegistry) {
|
||||
((DefaultSubscriptionRegistry) this.subscriptionRegistry).setPathMatcher(this.pathMatcher);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the {@link org.springframework.scheduling.TaskScheduler} to
|
||||
* use for providing heartbeat support. Setting this property also sets the
|
||||
@@ -130,6 +133,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
|
||||
|
||||
/**
|
||||
* Return the configured TaskScheduler.
|
||||
* @since 4.2
|
||||
*/
|
||||
public TaskScheduler getTaskScheduler() {
|
||||
return this.taskScheduler;
|
||||
@@ -151,6 +155,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
|
||||
|
||||
/**
|
||||
* The configured value for the heart-beat settings.
|
||||
* @since 4.2
|
||||
*/
|
||||
public long[] getHeartbeatValue() {
|
||||
return this.heartbeatValue;
|
||||
@@ -160,6 +165,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
|
||||
* Configure a {@link MessageHeaderInitializer} to apply to the headers
|
||||
* of all messages sent to the client outbound channel.
|
||||
* <p>By default this property is not set.
|
||||
* @since 4.1
|
||||
*/
|
||||
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
|
||||
this.headerInitializer = headerInitializer;
|
||||
@@ -167,6 +173,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
|
||||
|
||||
/**
|
||||
* Return the configured header initializer.
|
||||
* @since 4.1
|
||||
*/
|
||||
public MessageHeaderInitializer getHeaderInitializer() {
|
||||
return this.headerInitializer;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -142,7 +142,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook for sub-classes to customize the message channel for inbound messages
|
||||
* A hook for subclasses to customize the message channel for inbound messages
|
||||
* from WebSocket clients.
|
||||
*/
|
||||
protected void configureClientInboundChannel(ChannelRegistration registration) {
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook for sub-classes to customize the message channel for messages from
|
||||
* A hook for subclasses to customize the message channel for messages from
|
||||
* the application or message broker to WebSocket clients.
|
||||
*/
|
||||
protected void configureClientOutboundChannel(ChannelRegistration registration) {
|
||||
@@ -223,7 +223,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook for sub-classes to customize message broker configuration through the
|
||||
* A hook for subclasses to customize message broker configuration through the
|
||||
* provided {@link MessageBrokerRegistry} instance.
|
||||
*/
|
||||
protected void configureMessageBroker(MessageBrokerRegistry registry) {
|
||||
@@ -252,7 +252,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
addReturnValueHandlers(returnValueHandlers);
|
||||
handler.setCustomReturnValueHandlers(returnValueHandlers);
|
||||
|
||||
PathMatcher pathMatcher = this.getBrokerRegistry().getPathMatcher();
|
||||
PathMatcher pathMatcher = getBrokerRegistry().getPathMatcher();
|
||||
if (pathMatcher != null) {
|
||||
handler.setPathMatcher(pathMatcher);
|
||||
}
|
||||
@@ -260,7 +260,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected method for plugging in a custom sub-class of
|
||||
* Protected method for plugging in a custom subclass of
|
||||
* {@link org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler
|
||||
* SimpAnnotationMethodMessageHandler}.
|
||||
* @since 4.2
|
||||
@@ -320,7 +320,6 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
}
|
||||
|
||||
// Expose alias for 4.1 compatibility
|
||||
|
||||
@Bean(name={"messageBrokerTaskScheduler", "messageBrokerSockJsTaskScheduler"})
|
||||
public ThreadPoolTaskScheduler messageBrokerTaskScheduler() {
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
@@ -395,9 +394,9 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
protected abstract SimpUserRegistry createLocalUserRegistry();
|
||||
|
||||
/**
|
||||
* As of 4.2, UserSessionRegistry is deprecated in favor of SimpUserRegistry
|
||||
* exposing information about all connected users. The MultiServerUserRegistry
|
||||
* implementation in combination with UserRegistryMessageHandler can be used
|
||||
* As of 4.2, {@code UserSessionRegistry} is deprecated in favor of {@link SimpUserRegistry}
|
||||
* exposing information about all connected users. The {@link MultiServerUserRegistry}
|
||||
* implementation in combination with {@link UserRegistryMessageHandler} can be used
|
||||
* to share user registries across multiple servers.
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -465,9 +464,9 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class NoOpBrokerMessageHandler extends AbstractBrokerMessageHandler {
|
||||
|
||||
public NoOpBrokerMessageHandler() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -96,6 +96,16 @@ public class MessageBrokerRegistry {
|
||||
return this.brokerChannelRegistration;
|
||||
}
|
||||
|
||||
protected String getUserDestinationBroadcast() {
|
||||
return (this.brokerRelayRegistration != null ?
|
||||
this.brokerRelayRegistration.getUserDestinationBroadcast() : null);
|
||||
}
|
||||
|
||||
protected String getUserRegistryBroadcast() {
|
||||
return (this.brokerRelayRegistration != null ?
|
||||
this.brokerRelayRegistration.getUserRegistryBroadcast() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure one or more prefixes to filter destinations targeting application
|
||||
* annotated methods. For example destinations prefixed with "/app" may be
|
||||
@@ -137,16 +147,6 @@ public class MessageBrokerRegistry {
|
||||
return this.userDestinationPrefix;
|
||||
}
|
||||
|
||||
protected String getUserDestinationBroadcast() {
|
||||
return (this.brokerRelayRegistration != null ?
|
||||
this.brokerRelayRegistration.getUserDestinationBroadcast() : null);
|
||||
}
|
||||
|
||||
protected String getUserRegistryBroadcast() {
|
||||
return (this.brokerRelayRegistration != null ?
|
||||
this.brokerRelayRegistration.getUserRegistryBroadcast() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the PathMatcher to use to match the destinations of incoming
|
||||
* messages to {@code @MessageMapping} and {@code @SubscribeMapping} methods.
|
||||
@@ -162,6 +162,7 @@ public class MessageBrokerRegistry {
|
||||
* <p>When the simple broker is enabled, the PathMatcher configured here is
|
||||
* also used to match message destinations when brokering messages.
|
||||
* @since 4.1
|
||||
* @see org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry#setPathMatcher
|
||||
*/
|
||||
public MessageBrokerRegistry setPathMatcher(PathMatcher pathMatcher) {
|
||||
this.pathMatcher = pathMatcher;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.messaging.simp.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -71,6 +68,9 @@ import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link AbstractMessageBrokerConfiguration}.
|
||||
*
|
||||
@@ -435,6 +435,7 @@ public class MessageBrokerConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class BaseTestMessageBrokerConfig extends AbstractMessageBrokerConfiguration {
|
||||
|
||||
@Override
|
||||
@@ -443,6 +444,7 @@ public class MessageBrokerConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Configuration
|
||||
static class SimpleBrokerConfig extends BaseTestMessageBrokerConfig {
|
||||
@@ -471,6 +473,7 @@ public class MessageBrokerConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class BrokerRelayConfig extends SimpleBrokerConfig {
|
||||
|
||||
@@ -482,10 +485,12 @@ public class MessageBrokerConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class DefaultConfig extends BaseTestMessageBrokerConfig {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class CustomConfig extends BaseTestMessageBrokerConfig {
|
||||
|
||||
@@ -534,6 +539,7 @@ public class MessageBrokerConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class TestValidator implements Validator {
|
||||
|
||||
@Override
|
||||
@@ -546,6 +552,7 @@ public class MessageBrokerConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class CustomThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user