MOved the method nextClientID from IMessagesStore to the ISessionsStore because it's session related
This commit is contained in:
@@ -159,7 +159,7 @@ public class ClientSession {
|
||||
}
|
||||
|
||||
public int nextPacketId() {
|
||||
return this.messagesStore.nextPacketID(this.clientID);
|
||||
return this.m_sessionsStore.nextPacketID(this.clientID);
|
||||
}
|
||||
|
||||
public void inFlightAcknowledged(int messageID) {
|
||||
|
||||
@@ -136,10 +136,5 @@ public interface IMessagesStore {
|
||||
|
||||
StoredMessage getMessageByGuid(String guid);
|
||||
|
||||
/**
|
||||
* Return the next valid packetIdentifier for the given client session.
|
||||
* */
|
||||
int nextPacketID(String clientID);
|
||||
|
||||
void cleanRetained(String topic);
|
||||
}
|
||||
|
||||
@@ -110,6 +110,11 @@ public interface ISessionsStore {
|
||||
* */
|
||||
void inFlight(String clientID, int messageID, String guid);
|
||||
|
||||
/**
|
||||
* Return the next valid packetIdentifier for the given client session.
|
||||
* */
|
||||
int nextPacketID(String clientID);
|
||||
|
||||
/**
|
||||
* Store the guid to be later published.
|
||||
* */
|
||||
|
||||
@@ -427,7 +427,7 @@ public class ProtocolProcessor {
|
||||
//NB it's a will publish, it needs a PacketIdentifier for this conn, default to 1
|
||||
Integer messageId = null;
|
||||
if (will.getQos() != AbstractMessage.QOSType.MOST_ONE) {
|
||||
messageId = m_messagesStore.nextPacketID(clientID);
|
||||
messageId = m_sessionsStore.nextPacketID(clientID);
|
||||
}
|
||||
|
||||
IMessagesStore.StoredMessage tobeStored = asStoredMessage(will);
|
||||
@@ -737,7 +737,7 @@ public class ProtocolProcessor {
|
||||
LOG.debug("send publish message for topic {}", newSubscription.getTopicFilter());
|
||||
//forwardPublishQoS0(newSubscription.getClientId(), storedMsg.getTopic(), storedMsg.getQos(), storedMsg.getPayload(), true);
|
||||
Integer packetID = storedMsg.getQos() == QOSType.MOST_ONE ? null :
|
||||
m_messagesStore.nextPacketID(newSubscription.getClientId());
|
||||
targetSession.nextPacketId();
|
||||
directSend(targetSession, storedMsg.getTopic(), storedMsg.getQos(), storedMsg.getPayload(), true, packetID);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user