Merge pull request #225 from mpaatz/master

fixed ConcurrentModification Exceptions in MapDBSessionsStore, fixes #215
This commit is contained in:
Andrea Selva
2016-10-26 13:52:31 +02:00
committed by GitHub
@@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
/** /**
@@ -39,7 +40,7 @@ class MapDBSessionsStore implements ISessionsStore {
private static final Logger LOG = LoggerFactory.getLogger(MapDBSessionsStore.class); private static final Logger LOG = LoggerFactory.getLogger(MapDBSessionsStore.class);
//maps clientID->[MessageId -> guid] //maps clientID->[MessageId -> guid]
private ConcurrentMap<String, Map<Integer, MessageGUID>> m_inflightStore; private ConcurrentMap<String, ConcurrentMap<Integer, MessageGUID>> m_inflightStore;
//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, Set<Integer>> m_inFlightIds;
private ConcurrentMap<String, PersistentSession> m_persistentSessions; private ConcurrentMap<String, PersistentSession> m_persistentSessions;
@@ -167,7 +168,7 @@ class MapDBSessionsStore implements ISessionsStore {
Set<Integer> inFlightForClient = this.m_inFlightIds.get(clientID); Set<Integer> inFlightForClient = this.m_inFlightIds.get(clientID);
if (inFlightForClient == null) { if (inFlightForClient == null) {
int nextPacketId = 1; int nextPacketId = 1;
inFlightForClient = new HashSet<>(); inFlightForClient = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
inFlightForClient.add(nextPacketId); inFlightForClient.add(nextPacketId);
this.m_inFlightIds.put(clientID, inFlightForClient); this.m_inFlightIds.put(clientID, inFlightForClient);
return nextPacketId; return nextPacketId;
@@ -199,9 +200,9 @@ class MapDBSessionsStore implements ISessionsStore {
@Override @Override
public void inFlight(String clientID, int messageID, MessageGUID guid) { public void inFlight(String clientID, int messageID, MessageGUID guid) {
Map<Integer, MessageGUID> m = this.m_inflightStore.get(clientID); ConcurrentMap<Integer, MessageGUID> m = this.m_inflightStore.get(clientID);
if (m == null) { if (m == null) {
m = new HashMap<>(); m = new ConcurrentHashMap<>();
} }
m.put(messageID, guid); m.put(messageID, guid);
LOG.info("storing inflight clientID <{}> messageID {} guid <{}>", clientID, messageID, guid); LOG.info("storing inflight clientID <{}> messageID {} guid <{}>", clientID, messageID, guid);