Enabled overriding of subscription from same client to same topic with different QoS, the latest wins
This commit is contained in:
+11
@@ -225,6 +225,17 @@ public class HawtDBStorageService implements IStorageService {
|
||||
Set<Subscription> subs = m_persistentSubscriptions.get(clientID);
|
||||
if (!subs.contains(newSubscription)) {
|
||||
LOG.debug("updating clientID {} subscriptions set with new subscription", clientID);
|
||||
//TODO check the subs doesn't contain another subscription to the same topic with different
|
||||
Subscription existingSubscription = null;
|
||||
for (Subscription scanSub : subs) {
|
||||
if (newSubscription.getTopic().equals(scanSub.getTopic())) {
|
||||
existingSubscription = scanSub;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (existingSubscription != null) {
|
||||
subs.remove(existingSubscription);
|
||||
}
|
||||
subs.add(newSubscription);
|
||||
m_persistentSubscriptions.put(clientID, subs);
|
||||
LOG.debug("clientID {} subscriptions set now is {}", clientID, subs);
|
||||
|
||||
+17
-1
@@ -1,11 +1,21 @@
|
||||
package org.dna.mqtt.moquette.messaging.spi.impl.subscriptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
class TreeNode {
|
||||
|
||||
private class ClientIDComparator implements Comparator<Subscription> {
|
||||
|
||||
public int compare(Subscription o1, Subscription o2) {
|
||||
return o1.getClientId().compareTo(o2.getClientId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TreeNode m_parent;
|
||||
Token m_token;
|
||||
@@ -25,10 +35,16 @@ class TreeNode {
|
||||
}
|
||||
|
||||
void addSubscription(Subscription s) {
|
||||
//avoid double registering
|
||||
//avoid double registering for same clientID, topic and QoS
|
||||
if (m_subscriptions.contains(s)) {
|
||||
return;
|
||||
}
|
||||
//remove existing subscription for same client and topic but different QoS
|
||||
int existingSubIdx = Collections.binarySearch(m_subscriptions, s, new ClientIDComparator());
|
||||
if (existingSubIdx >= 0) {
|
||||
m_subscriptions.remove(existingSubIdx);
|
||||
}
|
||||
|
||||
m_subscriptions.add(s);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user