Introduced handling of sessionPresent flag in ConnAck msg, now on every conenction is created an empty subscription in ISessionStore

This commit is contained in:
selva.andre
2014-07-27 12:20:53 +02:00
parent bd3c4cb40c
commit 482ffe0c65
8 changed files with 70 additions and 5 deletions
@@ -36,4 +36,9 @@ public interface ISessionsStore {
void wipeSubscriptions(String sessionID);
List<Subscription> listAllSubscriptions();
/**
* @return true iff there are subscriptions persisted with clientID
*/
boolean contains(String clientID);
}
@@ -273,6 +273,11 @@ public class HawtDBPersistentStore implements IMessagesStore, ISessionsStore {
LOG.debug("retrieveAllSubscriptions returning subs {}", allSubscriptions);
return allSubscriptions;
}
@Override
public boolean contains(String clientID) {
return m_persistentSubscriptions.containsKey(clientID);
}
public void close() {
LOG.debug("closing disk storage");
@@ -134,6 +134,11 @@ public class MemoryStorageService implements IMessagesStore, ISessionsStore {
public void wipeSubscriptions(String clientID) {
m_persistentSubscriptions.remove(clientID);
}
@Override
public boolean contains(String clientID) {
return m_persistentSubscriptions.containsKey(clientID);
}
public List<Subscription> listAllSubscriptions() {
List<Subscription> allSubscriptions = new ArrayList<Subscription>();
@@ -220,10 +220,16 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
ConnAckMessage okResp = new ConnAckMessage();
okResp.setReturnCode(ConnAckMessage.CONNECTION_ACCEPTED);
if (!msg.isCleanSession() && m_sessionsStore.contains(msg.getClientID())) {
okResp.setSessionPresent(true);
}
LOG.debug("processConnect sent OK ConnAck");
session.write(okResp);
LOG.info("Connected client ID <{}> with clean session {}", msg.getClientID(), msg.isCleanSession());
LOG.info("Create persistent session for clientID {}", msg.getClientID());
m_sessionsStore.addNewSubscription(Subscription.createEmptySubscription(msg.getClientID(), true), msg.getClientID()); //null means EmptySubscription
if (!msg.isCleanSession()) {
//force the republish of stored QoS1 and QoS2
republishStored(msg.getClientID());
@@ -39,6 +39,13 @@ public class Subscription implements Serializable {
this.topicFilter = topicFilter;
this.cleanSession = cleanSession;
}
/**
* Factory method for empty subscriptions
*/
public static final Subscription createEmptySubscription(String clientId, boolean cleanSession) {
return new Subscription(clientId, "", QOSType.MOST_ONE, cleanSession);
}
public String getClientId() {
return clientId;