Browse Source

Avoid filtering if selector header is not in use

pull/890/head
Rossen Stoyanchev 9 years ago
parent
commit
922e6de788
  1. 8
      spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java
  2. 8
      spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java

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

@ -23,6 +23,8 @@ import org.springframework.messaging.Message; @@ -23,6 +23,8 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
/**
@ -35,6 +37,10 @@ import org.springframework.util.MultiValueMap; @@ -35,6 +37,10 @@ import org.springframework.util.MultiValueMap;
*/
public abstract class AbstractSubscriptionRegistry implements SubscriptionRegistry {
private static MultiValueMap<String, String> EMPTY_MAP =
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, String>(0));
protected final Log logger = LogFactory.getLog(getClass());
@ -104,7 +110,7 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist @@ -104,7 +110,7 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist
String destination = SimpMessageHeaderAccessor.getDestination(headers);
if (destination == null) {
logger.error("No destination in " + message);
return null;
return EMPTY_MAP;
}
return findSubscriptionsInternal(destination, message);

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

@ -72,7 +72,9 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { @@ -72,7 +72,9 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
private String selectorHeaderName = "selector";
private ExpressionParser expressionParser = new SpelExpressionParser();
private volatile boolean selectorHeaderInUse = false;
private final ExpressionParser expressionParser = new SpelExpressionParser();
private final DestinationCache destinationCache = new DestinationCache();
@ -143,6 +145,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { @@ -143,6 +145,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
if (selector != null) {
try {
expression = this.expressionParser.parseExpression(selector);
this.selectorHeaderInUse = true;
if (logger.isTraceEnabled()) {
logger.trace("Subscription selector: [" + selector + "]");
}
@ -185,6 +188,9 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { @@ -185,6 +188,9 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
private MultiValueMap<String, String> filterSubscriptions(
MultiValueMap<String, String> allMatches, Message<?> message) {
if (!this.selectorHeaderInUse) {
return allMatches;
}
EvaluationContext context = null;
MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(allMatches.size());
for (String sessionId : allMatches.keySet()) {

Loading…
Cancel
Save