Used the message store for QoS2 messages

This commit is contained in:
andsel
2015-11-16 23:45:47 +01:00
parent dbf86c9408
commit 9236def453
8 changed files with 65 additions and 22 deletions
@@ -24,12 +24,10 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import static org.eclipse.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME;
import static org.junit.Assert.*;
/**
@@ -208,8 +206,8 @@ public class ServerIntegrationFuseTest {
* subscriber connects again and receive "hello1" "hello2"
*/
@Test
public void checkQoS2SuscriberDisconnectReceivePersistedPublishes() throws Exception {
LOG.info("*** checkQoS2SuscriberDisconnectReceivePersistedPublishes ***");
public void checkQoS2SubscriberDisconnectReceivePersistedPublishes() throws Exception {
LOG.info("*** checkQoS2SubscriberDisconnectReceivePersistedPublishes ***");
m_mqtt.setHost("localhost", 1883);
m_mqtt.setCleanSession(false);
m_mqtt.setClientId("Subscriber");
@@ -47,6 +47,7 @@ public class MemoryStorageService implements IMessagesStore, ISessionsStore {
private Map<String, Set<Integer>> m_secondPhaseStore = new HashMap<>();
private Map<String, Set<Integer>> m_inflightIDs = new HashMap<>();
private Map<String, PublishEvent> m_qos2Store = new HashMap<>();
private Map<String, Map<Integer, String>> m_messageToGuids = new HashMap<>();
private MemorySessionStore m_sessionsStore;
private static final Logger LOG = LoggerFactory.getLogger(MemoryStorageService.class);
@@ -95,6 +96,9 @@ public class MemoryStorageService implements IMessagesStore, ISessionsStore {
String guid = UUID.randomUUID().toString();
evt.setGuid(guid);
m_persistentMessageStore.put(guid, evt);
HashMap<Integer, String> guids = (HashMap<Integer, String>) defaultGet(m_messageToGuids,
evt.getClientID(), new HashMap<Integer, String>());
guids.put(evt.getMessageID(), guid);
return guid;
}
@@ -112,6 +116,18 @@ public class MemoryStorageService implements IMessagesStore, ISessionsStore {
m_persistentMessageStore.remove(clientID);
}
@Override
public PublishEvent getMessageByGuid(String guid) {
return m_persistentMessageStore.get(guid);
}
@Override
public String mapToGuid(String clientID, int messageID) {
HashMap<Integer, String> guids = (HashMap<Integer, String>) defaultGet(m_messageToGuids,
clientID, new HashMap<Integer, String>());
return guids.get(messageID);
}
/**
* Return the next valid packetIdentifier for the given client session.
* */
@@ -18,6 +18,7 @@ package org.eclipse.moquette.spi.persistence;
import org.eclipse.moquette.spi.ClientSession;
import org.eclipse.moquette.spi.IMessagesStore;
import org.eclipse.moquette.spi.ISessionsStore;
import org.eclipse.moquette.spi.impl.MemoryStorageService;
import org.eclipse.moquette.spi.impl.subscriptions.Subscription;
import static org.eclipse.moquette.spi.impl.Utils.defaultGet;
@@ -29,7 +30,7 @@ import java.util.*;
/**
*
* @author andream_messagesStore
* @author andrea
*/
public class MemorySessionStore implements ISessionsStore {
private static final Logger LOG = LoggerFactory.getLogger(MemorySessionStore.class);
@@ -208,4 +209,9 @@ public class MemorySessionStore implements ISessionsStore {
messageIDs.add(messageID);
m_secondPhaseStore.put(clientID, messageIDs);
}
@Override
public String mapToGuid(String clientID, int messageID) {
return ((MemoryStorageService) m_messagesStore).mapToGuid(clientID, messageID);
}
}