Skip to content

Commit ce20abd

Browse files
sdeleuzerstoyanchev
authored andcommitted
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
1 parent 083d415 commit ce20abd

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

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

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected void removeSubscriptionInternal(String sessionId, String subsId, Messa
9797
if (info != null) {
9898
String destination = info.removeSubscription(subsId);
9999
if (destination != null) {
100-
this.destinationCache.updateAfterRemovedSubscription(destination, sessionId, subsId);
100+
this.destinationCache.updateAfterRemovedSubscription(sessionId, subsId);
101101
}
102102
}
103103
}
@@ -183,14 +183,14 @@ public void updateAfterNewSubscription(String destination, String sessionId, Str
183183
}
184184
}
185185

186-
public void updateAfterRemovedSubscription(String destination, String sessionId, String subsId) {
186+
public void updateAfterRemovedSubscription(String sessionId, String subsId) {
187187
synchronized (this.updateCache) {
188188
Set<String> destinationsToRemove = new HashSet<String>();
189189
for (Map.Entry<String, MultiValueMap<String, String>> entry : this.updateCache.entrySet()) {
190190
String cachedDestination = entry.getKey();
191-
if (getPathMatcher().match(destination, cachedDestination)) {
192-
MultiValueMap<String, String> subs = entry.getValue();
193-
List<String> subsIds = subs.get(sessionId);
191+
MultiValueMap<String, String> subs = entry.getValue();
192+
List<String> subsIds = subs.get(sessionId);
193+
if(subsIds != null) {
194194
subsIds.remove(subsId);
195195
if (subsIds.isEmpty()) {
196196
subs.remove(sessionId);
@@ -212,25 +212,22 @@ public void updateAfterRemovedSubscription(String destination, String sessionId,
212212

213213
public void updateAfterRemovedSession(SessionSubscriptionInfo info) {
214214
synchronized (this.updateCache) {
215-
for (String destination : info.getDestinations()) {
216-
Set<String> destinationsToRemove = new HashSet<String>();
217-
for (Map.Entry<String, MultiValueMap<String, String>> entry : this.updateCache.entrySet()) {
218-
String cachedDestination = entry.getKey();
219-
if (getPathMatcher().match(destination, cachedDestination)) {
220-
MultiValueMap<String, String> subs = entry.getValue();
221-
subs.remove(info.getSessionId());
222-
if (subs.isEmpty()) {
223-
destinationsToRemove.add(cachedDestination);
224-
}
225-
else {
226-
this.accessCache.put(cachedDestination,new LinkedMultiValueMap<String, String>(subs));
227-
}
215+
Set<String> destinationsToRemove = new HashSet<String>();
216+
for (Map.Entry<String, MultiValueMap<String, String>> entry : this.updateCache.entrySet()) {
217+
String cachedDestination = entry.getKey();
218+
MultiValueMap<String, String> subs = entry.getValue();
219+
if(subs.remove(info.getSessionId()) != null) {
220+
if (subs.isEmpty()) {
221+
destinationsToRemove.add(cachedDestination);
222+
}
223+
else {
224+
this.accessCache.put(cachedDestination,new LinkedMultiValueMap<String, String>(subs));
228225
}
229226
}
230-
for (String d : destinationsToRemove) {
231-
this.updateCache.remove(d);
232-
this.accessCache.remove(d);
233-
}
227+
}
228+
for (String d : destinationsToRemove) {
229+
this.updateCache.remove(d);
230+
this.accessCache.remove(d);
234231
}
235232
}
236233
}

0 commit comments

Comments
 (0)