Fixed ugly empty session storage, avoid fake NullObject empty subscription subscription
This commit is contained in:
@@ -53,4 +53,6 @@ public interface ISessionsStore {
|
||||
* @return true iff there are subscriptions persisted with clientID
|
||||
*/
|
||||
boolean contains(String clientID);
|
||||
|
||||
void createNewSession(String clientID);
|
||||
}
|
||||
|
||||
@@ -208,6 +208,15 @@ public class MemoryStorageService implements IMessagesStore, ISessionsStore {
|
||||
return m_persistentSubscriptions.containsKey(clientID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createNewSession(String clientID) {
|
||||
if (m_persistentSubscriptions.containsKey(clientID)) {
|
||||
LOG.error("already exists a session for client <{}>", clientID);
|
||||
return;
|
||||
}
|
||||
m_persistentSubscriptions.put(clientID, new HashSet<Subscription>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Subscription> listAllSubscriptions() {
|
||||
List<Subscription> allSubscriptions = new ArrayList<Subscription>();
|
||||
|
||||
@@ -243,14 +243,17 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
|
||||
|
||||
ConnAckMessage okResp = new ConnAckMessage();
|
||||
okResp.setReturnCode(ConnAckMessage.CONNECTION_ACCEPTED);
|
||||
if (!msg.isCleanSession() && m_sessionsStore.contains(msg.getClientID())) {
|
||||
boolean isSessionAlreadyStored = m_sessionsStore.contains(msg.getClientID());
|
||||
if (!msg.isCleanSession() && isSessionAlreadyStored) {
|
||||
okResp.setSessionPresent(true);
|
||||
}
|
||||
session.write(okResp);
|
||||
m_interceptor.notifyClientConnected(msg);
|
||||
|
||||
LOG.info("Create persistent session for clientID <{}>", msg.getClientID());
|
||||
m_sessionsStore.addNewSubscription(Subscription.createEmptySubscription(msg.getClientID(), true)); //null means EmptySubscription
|
||||
if (!isSessionAlreadyStored) {
|
||||
LOG.info("Create persistent session for clientID <{}>", msg.getClientID());
|
||||
m_sessionsStore.createNewSession(msg.getClientID());
|
||||
}
|
||||
LOG.info("Connected client ID <{}> with clean session {}", msg.getClientID(), msg.isCleanSession());
|
||||
if (!msg.isCleanSession()) {
|
||||
//force the republish of stored QoS1 and QoS2
|
||||
|
||||
+12
-1
@@ -285,7 +285,7 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
|
||||
}
|
||||
|
||||
public List<Subscription> listAllSubscriptions() {
|
||||
List<Subscription> allSubscriptions = new ArrayList<Subscription>();
|
||||
List<Subscription> allSubscriptions = new ArrayList<>();
|
||||
for (Map.Entry<String, Set<Subscription>> entry : m_persistentSubscriptions.entrySet()) {
|
||||
allSubscriptions.addAll(entry.getValue());
|
||||
}
|
||||
@@ -298,6 +298,17 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
|
||||
return m_persistentSubscriptions.containsKey(clientID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createNewSession(String clientID) {
|
||||
LOG.debug("createNewSession for client <{}>", clientID);
|
||||
if (m_persistentSubscriptions.containsKey(clientID)) {
|
||||
LOG.error("already exists a session for client <{}>", clientID);
|
||||
return;
|
||||
}
|
||||
LOG.debug("clientID {} is a newcome, creating it's empty subscriptions set", clientID);
|
||||
m_persistentSubscriptions.put(clientID, new HashSet<Subscription>());
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.m_db.commit();
|
||||
LOG.debug("persisted subscriptions {}", m_persistentSubscriptions);
|
||||
|
||||
Reference in New Issue
Block a user