MOved the method nextClientID from IMessagesStore to the ISessionsStore because it's session related

This commit is contained in:
andsel
2016-01-17 13:00:36 +01:00
parent 5daf1362cc
commit 4c1f36cf67
9 changed files with 73 additions and 53 deletions
@@ -110,26 +110,26 @@ class MapDBMessagesStore implements IMessagesStore {
return m_persistentMessageStore.get(guid);
}
/**
* Return the next valid packetIdentifier for the given client session.
* */
@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;
}
int maxId = inFlightForClient.isEmpty() ? 0 : Collections.max(inFlightForClient);
int nextPacketId = (maxId + 1) % 0xFFFF;
inFlightForClient.add(nextPacketId);
return nextPacketId;
}
// /**
// * Return the next valid packetIdentifier for the given client session.
// * */
// @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;
//
// }
//
// int maxId = inFlightForClient.isEmpty() ? 0 : Collections.max(inFlightForClient);
// int nextPacketId = (maxId + 1) % 0xFFFF;
// inFlightForClient.add(nextPacketId);
// return nextPacketId;
// }
@Override
public void cleanRetained(String topic) {
@@ -143,6 +143,27 @@ class MapDBSessionsStore implements ISessionsStore {
return new ClientSession(clientID, m_messagesStore, this, storedSession.cleanSession);
}
/**
* Return the next valid packetIdentifier for the given client session.
* */
@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;
}
int maxId = inFlightForClient.isEmpty() ? 0 : Collections.max(inFlightForClient);
int nextPacketId = (maxId + 1) % 0xFFFF;
inFlightForClient.add(nextPacketId);
return nextPacketId;
}
@Override
public void inFlightAck(String clientID, int messageID) {
Map<Integer, String> m = this.m_inflightStore.get(clientID);