Removed client active/not active state from persistence (issue #118)

This commit is contained in:
andsel
2015-12-19 18:01:54 +01:00
parent 4f65a59324
commit 8e891da49f
9 changed files with 67 additions and 62 deletions
@@ -46,11 +46,9 @@ public class MapDBPersistentStore {
* */
public static class PersistentSession implements Serializable {
public final boolean cleanSession;
public final boolean active;
public PersistentSession(boolean cleanSession, boolean active) {
public PersistentSession(boolean cleanSession) {
this.cleanSession = cleanSession;
this.active = active;
}
}
@@ -129,7 +129,7 @@ class MapDBSessionsStore implements ISessionsStore {
throw new IllegalArgumentException("Can't create a session with the ID of an already existing" + clientID);
}
LOG.debug("clientID {} is a newcome, creating it's empty subscriptions set", clientID);
m_persistentSessions.putIfAbsent(clientID, new PersistentSession(cleanSession, false));
m_persistentSessions.putIfAbsent(clientID, new PersistentSession(cleanSession));
return new ClientSession(clientID, m_messagesStore, this, cleanSession);
}
@@ -140,30 +140,7 @@ class MapDBSessionsStore implements ISessionsStore {
}
PersistentSession storedSession = m_persistentSessions.get(clientID);
ClientSession clientSession = new ClientSession(clientID, m_messagesStore, this, storedSession.cleanSession);
if (storedSession.active) {
clientSession.activate();
}
return clientSession;
}
@Override
public void activate(String clientID) {
activationHelper(clientID, true);
}
@Override
public void deactivate(String clientID) {
activationHelper(clientID, false);
}
private void activationHelper(String clientID, boolean activation) {
PersistentSession storedSession = m_persistentSessions.get(clientID);
if (storedSession == null) {
throw new IllegalStateException((activation ? "activating" : "deactivating") + " a session never stored/created, clientID <"+ clientID + ">", null);
}
PersistentSession newStoredSession = new PersistentSession(storedSession.cleanSession, activation);
m_persistentSessions.put(clientID, newStoredSession);
return new ClientSession(clientID, m_messagesStore, this, storedSession.cleanSession);
}
@Override