Removed a queue per client of inFlightIds (never cleaned) in favor of single atomic generator, fixes issue #130
This commit is contained in:
@@ -18,6 +18,7 @@ Version 0.8:
|
|||||||
Added internal publish once the broker is embedded (issue #113)
|
Added internal publish once the broker is embedded (issue #113)
|
||||||
Removed client active/not active state from persistence (issue #118)
|
Removed client active/not active state from persistence (issue #118)
|
||||||
Avoid deletion of client descriptor in case of multiple clients with same clientID (issues #116 and #124)
|
Avoid deletion of client descriptor in case of multiple clients with same clientID (issues #116 and #124)
|
||||||
|
Removed a queue per client of inFlightIds (never cleaned) in favor of single atomic generator
|
||||||
|
|
||||||
Version 0.7:
|
Version 0.7:
|
||||||
Fix issue #38, added aligned to MQTT 3.1.1
|
Fix issue #38, added aligned to MQTT 3.1.1
|
||||||
|
|||||||
@@ -141,7 +141,5 @@ public interface IMessagesStore {
|
|||||||
* */
|
* */
|
||||||
int nextPacketID(String clientID);
|
int nextPacketID(String clientID);
|
||||||
|
|
||||||
// void close();
|
|
||||||
|
|
||||||
void cleanRetained(String topic);
|
void cleanRetained(String topic);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IMessagesStore implementation backed by MapDB.
|
* IMessagesStore implementation backed by MapDB.
|
||||||
@@ -36,7 +37,7 @@ class MapDBMessagesStore implements IMessagesStore {
|
|||||||
private DB m_db;
|
private DB m_db;
|
||||||
|
|
||||||
//map clientID <-> set of currently in flight packet identifiers
|
//map clientID <-> set of currently in flight packet identifiers
|
||||||
private Map<String, Set<Integer>> m_inFlightIds;
|
private Map<String, AtomicLong> m_inFlightIds;
|
||||||
//maps clientID -> guid
|
//maps clientID -> guid
|
||||||
private ConcurrentMap<String, String> m_retainedStore;
|
private ConcurrentMap<String, String> m_retainedStore;
|
||||||
//maps guid to message, it's message store
|
//maps guid to message, it's message store
|
||||||
@@ -115,18 +116,19 @@ class MapDBMessagesStore implements IMessagesStore {
|
|||||||
* */
|
* */
|
||||||
@Override
|
@Override
|
||||||
public int nextPacketID(String clientID) {
|
public int nextPacketID(String clientID) {
|
||||||
Set<Integer> inFlightForClient = this.m_inFlightIds.get(clientID);
|
AtomicLong atomicLong = this.m_inFlightIds.get(clientID);
|
||||||
if (inFlightForClient == null) {
|
if (atomicLong == null) {
|
||||||
int nextPacketId = 1;
|
AtomicLong messageId = new AtomicLong(1);
|
||||||
inFlightForClient = new HashSet<>();
|
this.m_inFlightIds.put(clientID, messageId);
|
||||||
inFlightForClient.add(nextPacketId);
|
return 1;
|
||||||
this.m_inFlightIds.put(clientID, inFlightForClient);
|
|
||||||
return nextPacketId;
|
|
||||||
}
|
}
|
||||||
int maxId = inFlightForClient.isEmpty() ? 0 : Collections.max(inFlightForClient);
|
int incrementAndGet = (int) atomicLong.incrementAndGet();
|
||||||
int nextPacketId = (maxId + 1) % 0xFFFF;
|
if (incrementAndGet == 0XFFFF) {
|
||||||
inFlightForClient.add(nextPacketId);
|
atomicLong.set(1);
|
||||||
return nextPacketId;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return incrementAndGet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<netty.version>4.0.30.Final</netty.version>
|
<netty.version>4.0.33.Final</netty.version>
|
||||||
<source.version>1.7</source.version>
|
<source.version>1.7</source.version>
|
||||||
<target.version>1.7</target.version>
|
<target.version>1.7</target.version>
|
||||||
<bintray.repo>andsel/maven</bintray.repo>
|
<bintray.repo>andsel/maven</bintray.repo>
|
||||||
|
|||||||
Reference in New Issue
Block a user