Removed a queue per client of inFlightIds (never cleaned) in favor of single atomic generator, fixes issue #130

This commit is contained in:
andsel
2016-01-02 16:43:12 +01:00
parent 9c8e96df16
commit 5f83465529
4 changed files with 16 additions and 15 deletions
+1
View File
@@ -18,6 +18,7 @@ Version 0.8:
Added internal publish once the broker is embedded (issue #113)
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)
Removed a queue per client of inFlightIds (never cleaned) in favor of single atomic generator
Version 0.7:
Fix issue #38, added aligned to MQTT 3.1.1
@@ -141,7 +141,5 @@ public interface IMessagesStore {
* */
int nextPacketID(String clientID);
// void close();
void cleanRetained(String topic);
}
@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
/**
* IMessagesStore implementation backed by MapDB.
@@ -36,7 +37,7 @@ class MapDBMessagesStore implements IMessagesStore {
private DB m_db;
//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
private ConcurrentMap<String, String> m_retainedStore;
//maps guid to message, it's message store
@@ -115,18 +116,19 @@ class MapDBMessagesStore implements IMessagesStore {
* */
@Override
public int nextPacketID(String clientID) {
Set<Integer> inFlightForClient = this.m_inFlightIds.get(clientID);
if (inFlightForClient == null) {
int nextPacketId = 1;
inFlightForClient = new HashSet<>();
inFlightForClient.add(nextPacketId);
this.m_inFlightIds.put(clientID, inFlightForClient);
return nextPacketId;
AtomicLong atomicLong = this.m_inFlightIds.get(clientID);
if (atomicLong == null) {
AtomicLong messageId = new AtomicLong(1);
this.m_inFlightIds.put(clientID, messageId);
return 1;
}
int maxId = inFlightForClient.isEmpty() ? 0 : Collections.max(inFlightForClient);
int nextPacketId = (maxId + 1) % 0xFFFF;
inFlightForClient.add(nextPacketId);
return nextPacketId;
int incrementAndGet = (int) atomicLong.incrementAndGet();
if (incrementAndGet == 0XFFFF) {
atomicLong.set(1);
return 1;
}
return incrementAndGet;
}
@Override
+1 -1
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<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>
<target.version>1.7</target.version>
<bintray.repo>andsel/maven</bintray.repo>