Extracted the persistence dependency from SubscriptionsStore

This commit is contained in:
selva.andre
2014-06-30 22:59:37 +02:00
parent 90cfe1ac23
commit 665e60a646
4 changed files with 14 additions and 8 deletions
@@ -25,9 +25,15 @@ import org.dna.mqtt.moquette.messaging.spi.impl.subscriptions.Subscription;
*/ */
public interface IPersistentSubscriptionStore { public interface IPersistentSubscriptionStore {
/**
* Add a new subscription to the session
*/
void addNewSubscription(Subscription newSubscription, String clientID); void addNewSubscription(Subscription newSubscription, String clientID);
void removeAllSubscriptions(String clientID); /**
* Remove all the subscriptions of the session
*/
void wipeSubscriptions(String sessionID);
List<Subscription> retrieveAllSubscriptions(); List<Subscription> retrieveAllSubscriptions();
} }
@@ -260,7 +260,7 @@ public class HawtDBStorageService implements IStorageService {
} }
} }
public void removeAllSubscriptions(String clientID) { public void wipeSubscriptions(String clientID) {
m_persistentSubscriptions.remove(clientID); m_persistentSubscriptions.remove(clientID);
} }
@@ -130,7 +130,7 @@ public class MemoryStorageService implements IStorageService {
} }
} }
public void removeAllSubscriptions(String clientID) { public void wipeSubscriptions(String clientID) {
m_persistentSubscriptions.remove(clientID); m_persistentSubscriptions.remove(clientID);
} }
@@ -160,7 +160,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
boolean cleanSession = (Boolean) oldSession.getAttribute(Constants.CLEAN_SESSION); boolean cleanSession = (Boolean) oldSession.getAttribute(Constants.CLEAN_SESSION);
if (cleanSession) { if (cleanSession) {
//cleanup topic subscriptions //cleanup topic subscriptions
processRemoveAllSubscriptions(msg.getClientID()); cleanSession(msg.getClientID());
} }
m_clientIDs.get(msg.getClientID()).getSession().close(false); m_clientIDs.get(msg.getClientID()).getSession().close(false);
@@ -208,7 +208,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
if (msg.isCleanSession()) { if (msg.isCleanSession()) {
//remove all prev subscriptions //remove all prev subscriptions
//cleanup topic subscriptions //cleanup topic subscriptions
processRemoveAllSubscriptions(msg.getClientID()); cleanSession(msg.getClientID());
} }
ConnAckMessage okResp = new ConnAckMessage(); ConnAckMessage okResp = new ConnAckMessage();
@@ -243,10 +243,10 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
m_storageService.cleanPersistedPublishMessage(clientID, messageID); m_storageService.cleanPersistedPublishMessage(clientID, messageID);
} }
private void processRemoveAllSubscriptions(String clientID) { private void cleanSession(String clientID) {
LOG.info("cleaning old saved subscriptions for client <{}>", clientID); LOG.info("cleaning old saved subscriptions for client <{}>", clientID);
//remove from log all subscriptions //remove from log all subscriptions
m_storageService.removeAllSubscriptions(clientID); m_storageService.wipeSubscriptions(clientID);
subscriptions.removeForClient(clientID); subscriptions.removeForClient(clientID);
//remove also the messages stored of type QoS1/2 //remove also the messages stored of type QoS1/2
@@ -458,7 +458,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
void processDisconnect(ServerChannel session, String clientID, boolean cleanSession) throws InterruptedException { void processDisconnect(ServerChannel session, String clientID, boolean cleanSession) throws InterruptedException {
if (cleanSession) { if (cleanSession) {
//cleanup topic subscriptions //cleanup topic subscriptions
processRemoveAllSubscriptions(clientID); cleanSession(clientID);
} }
// m_notifier.disconnect(evt.getSession()); // m_notifier.disconnect(evt.getSession());
m_clientIDs.remove(clientID); m_clientIDs.remove(clientID);