From ce20abde51ac52dde2f318e28004af80cca886fe Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Tue, 1 Jul 2014 15:15:09 +0200 Subject: [PATCH] Improve subscription removal in SubscriptionRegistry Avoid using destination pattern based search when removing sessions or subscriptions from DefaultSubscriptionRegistry and use only session and subscription ids. Issue: SPR-11930 --- .../broker/DefaultSubscriptionRegistry.java | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java index 9646ff5e4d5..a52b881b933 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java @@ -97,7 +97,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { if (info != null) { String destination = info.removeSubscription(subsId); if (destination != null) { - this.destinationCache.updateAfterRemovedSubscription(destination, sessionId, subsId); + this.destinationCache.updateAfterRemovedSubscription(sessionId, subsId); } } } @@ -183,14 +183,14 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { } } - public void updateAfterRemovedSubscription(String destination, String sessionId, String subsId) { + public void updateAfterRemovedSubscription(String sessionId, String subsId) { synchronized (this.updateCache) { Set destinationsToRemove = new HashSet(); for (Map.Entry> entry : this.updateCache.entrySet()) { String cachedDestination = entry.getKey(); - if (getPathMatcher().match(destination, cachedDestination)) { - MultiValueMap subs = entry.getValue(); - List subsIds = subs.get(sessionId); + MultiValueMap subs = entry.getValue(); + List subsIds = subs.get(sessionId); + if(subsIds != null) { subsIds.remove(subsId); if (subsIds.isEmpty()) { subs.remove(sessionId); @@ -212,25 +212,22 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { public void updateAfterRemovedSession(SessionSubscriptionInfo info) { synchronized (this.updateCache) { - for (String destination : info.getDestinations()) { - Set destinationsToRemove = new HashSet(); - for (Map.Entry> entry : this.updateCache.entrySet()) { - String cachedDestination = entry.getKey(); - if (getPathMatcher().match(destination, cachedDestination)) { - MultiValueMap subs = entry.getValue(); - subs.remove(info.getSessionId()); - if (subs.isEmpty()) { - destinationsToRemove.add(cachedDestination); - } - else { - this.accessCache.put(cachedDestination,new LinkedMultiValueMap(subs)); - } + Set destinationsToRemove = new HashSet(); + for (Map.Entry> entry : this.updateCache.entrySet()) { + String cachedDestination = entry.getKey(); + MultiValueMap subs = entry.getValue(); + if(subs.remove(info.getSessionId()) != null) { + if (subs.isEmpty()) { + destinationsToRemove.add(cachedDestination); + } + else { + this.accessCache.put(cachedDestination,new LinkedMultiValueMap(subs)); } } - for (String d : destinationsToRemove) { - this.updateCache.remove(d); - this.accessCache.remove(d); - } + } + for (String d : destinationsToRemove) { + this.updateCache.remove(d); + this.accessCache.remove(d); } } }