Skip to content

Commit

Permalink
Fixed unsubscribe messages reducing counters when not subscribed
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Aug 8, 2024
1 parent 9de92c9 commit 06a2629
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fixed #1948: Sanitise user input in error output.
* Fixed MultiDatastream not picking up ID type of Thing and Sensor.
* Fixed Tomcat Docker images already having UID/GID 1000, FROST now uses 1001.
* Fixed unsubscribe messages reducing counters when not subscribed.


## Release version 2.3.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public void setTopic(String topic) {
this.topic = topic;
}

@Override
public String toString() {
return getTopic();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void onSubscribe(InterceptSubscribeMessage msg) {
final String topicFilter = msg.getTopicFilter();
LOGGER.trace(" Client {} subscribed to {}", clientId, topicFilter);
clientSubscriptions
.getOrDefault(clientId, new ArrayList<>())
.computeIfAbsent(clientId, t -> new ArrayList<>())
.add(topicFilter);
fireSubscribe(new SubscriptionEvent(topicFilter));
}
Expand All @@ -301,9 +301,11 @@ public void onUnsubscribe(InterceptUnsubscribeMessage msg) {
}
final String topicFilter = msg.getTopicFilter();
LOGGER.trace(" Client {} unsubscribed from {}", clientId, topicFilter);
clientSubscriptions.getOrDefault(clientId, new ArrayList<>())
boolean removed = clientSubscriptions.getOrDefault(clientId, new ArrayList<>())
.remove(topicFilter);
fireUnsubscribe(new SubscriptionEvent(topicFilter));
if (removed) {
fireUnsubscribe(new SubscriptionEvent(topicFilter));
}
}

@Override
Expand Down

0 comments on commit 06a2629

Please sign in to comment.