broker/MapDBPersistentStore: Interfaces used for the Constructors
broker/IStore: Interface added for MapDBPersistentStore broker/ProtocolProcessorBootstrapper: class loader for store added broker/ISessionsStore#mapToGuid: moved to IMessagesStore broker/ProtocolProcessorBootstrapper: getter used for SessionStore broker/Server: getter for processor added broker/ProtocolProcessor: getter added for Stores
This commit is contained in:
@@ -20,6 +20,9 @@ import io.moquette.BrokerConstants;
|
||||
import io.moquette.server.config.IConfig;
|
||||
import io.moquette.server.config.MemoryConfig;
|
||||
import io.moquette.spi.impl.subscriptions.Topic;
|
||||
import io.moquette.spi.impl.MemoryMessagesStore;
|
||||
import io.moquette.spi.impl.MemoryStorageService;
|
||||
import io.moquette.spi.persistence.MemorySessionStore;
|
||||
import io.moquette.spi.security.IAuthenticator;
|
||||
import io.moquette.spi.security.IAuthorizator;
|
||||
import org.junit.After;
|
||||
@@ -64,6 +67,16 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadStorage() throws Exception {
|
||||
Properties props = new Properties(IntegrationUtils.prepareTestProperties());
|
||||
props.setProperty(BrokerConstants.STORAGE_CLASS_NAME, MemoryStorageService.class.getName());
|
||||
|
||||
startServer(props);
|
||||
assertTrue(m_server.getProcessor().getMessagesStore() instanceof MemoryMessagesStore);
|
||||
assertTrue(m_server.getProcessor().getSessionsStore() instanceof MemorySessionStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkValid(String clientID, String username, byte[] password) {
|
||||
return true;
|
||||
|
||||
@@ -22,7 +22,6 @@ public class ClientSessionTest {
|
||||
public void setUp() {
|
||||
store = new SubscriptionsStore();
|
||||
MemoryStorageService storageService = new MemoryStorageService();
|
||||
storageService.initStore();
|
||||
this.sessionsStore = storageService.sessionsStore();
|
||||
store.init(sessionsStore);
|
||||
|
||||
|
||||
@@ -34,10 +34,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
private Map<Topic, MessageGUID> m_retainedStore = new HashMap<>();
|
||||
private Map<MessageGUID, StoredMessage> m_persistentMessageStore = new HashMap<>();
|
||||
private Map<String, Map<Integer, MessageGUID>> m_messageToGuids;
|
||||
private Map<String, Map<Integer, MessageGUID>> m_messageToGuids = new HashMap<>();
|
||||
|
||||
MemoryMessagesStore(Map<String, Map<Integer, MessageGUID>> messageToGuids) {
|
||||
m_messageToGuids = messageToGuids;
|
||||
MemoryMessagesStore() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,4 +108,11 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
else
|
||||
return messageToGuids.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageGUID mapToGuid(String clientID, int messageID) {
|
||||
HashMap<Integer, MessageGUID> guids = (HashMap<Integer, MessageGUID>) Utils
|
||||
.defaultGet(m_messageToGuids, clientID, new HashMap<Integer, MessageGUID>());
|
||||
return guids.get(messageID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,28 +18,32 @@ package io.moquette.spi.impl;
|
||||
|
||||
import io.moquette.spi.IMessagesStore;
|
||||
import io.moquette.spi.ISessionsStore;
|
||||
import io.moquette.spi.MessageGUID;
|
||||
import io.moquette.spi.IStore;
|
||||
import io.moquette.spi.persistence.MemorySessionStore;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MemoryStorageService {
|
||||
public class MemoryStorageService implements IStore {
|
||||
|
||||
private MemorySessionStore m_sessionsStore;
|
||||
private MemoryMessagesStore m_messagesStore;
|
||||
|
||||
public void initStore() {
|
||||
Map<String, Map<Integer, MessageGUID>> messageToGuids = new HashMap<>();
|
||||
m_messagesStore = new MemoryMessagesStore(messageToGuids);
|
||||
m_sessionsStore = new MemorySessionStore(m_messagesStore, messageToGuids);
|
||||
public MemoryStorageService() {
|
||||
m_messagesStore = new MemoryMessagesStore();
|
||||
m_sessionsStore = new MemorySessionStore(m_messagesStore);
|
||||
m_messagesStore.initStore();
|
||||
m_sessionsStore.initStore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessagesStore messagesStore() {
|
||||
return m_messagesStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISessionsStore sessionsStore() {
|
||||
return m_sessionsStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,6 @@ public class ProtocolProcessorTest {
|
||||
// sleep to let the messaging batch processor to process the initEvent
|
||||
Thread.sleep(300);
|
||||
MemoryStorageService memStorage = new MemoryStorageService();
|
||||
memStorage.initStore();
|
||||
m_messagesStore = memStorage.messagesStore();
|
||||
m_sessionStore = memStorage.sessionsStore();
|
||||
// m_messagesStore.initStore();
|
||||
@@ -128,7 +127,6 @@ public class ProtocolProcessorTest {
|
||||
|
||||
// simulate a connect that register a clientID to an IoSession
|
||||
MemoryStorageService storageService = new MemoryStorageService();
|
||||
storageService.initStore();
|
||||
subs.init(storageService.sessionsStore());
|
||||
m_processor.init(
|
||||
subs,
|
||||
@@ -177,7 +175,6 @@ public class ProtocolProcessorTest {
|
||||
|
||||
// simulate a connect that register a clientID to an IoSession
|
||||
MemoryStorageService storageService = new MemoryStorageService();
|
||||
storageService.initStore();
|
||||
subs.init(storageService.sessionsStore());
|
||||
m_processor.init(
|
||||
subs,
|
||||
@@ -353,7 +350,6 @@ public class ProtocolProcessorTest {
|
||||
}
|
||||
};
|
||||
MemoryStorageService storageService = new MemoryStorageService();
|
||||
storageService.initStore();
|
||||
subs.init(storageService.sessionsStore());
|
||||
|
||||
// simulate a connect that register a clientID to an IoSession
|
||||
|
||||
@@ -66,7 +66,6 @@ public class ProtocolProcessor_CONNECT_Test {
|
||||
// sleep to let the messaging batch processor to process the initEvent
|
||||
Thread.sleep(300);
|
||||
MemoryStorageService memStorage = new MemoryStorageService();
|
||||
memStorage.initStore();
|
||||
m_messagesStore = memStorage.messagesStore();
|
||||
m_sessionStore = memStorage.sessionsStore();
|
||||
// m_messagesStore.initStore();
|
||||
|
||||
@@ -43,7 +43,6 @@ public class SubscriptionsStoreTest {
|
||||
public void setUp() throws IOException {
|
||||
store = new SubscriptionsStore();
|
||||
MemoryStorageService storageService = new MemoryStorageService();
|
||||
storageService.initStore();
|
||||
this.sessionsStore = storageService.sessionsStore();
|
||||
store.init(sessionsStore);
|
||||
}
|
||||
@@ -209,7 +208,6 @@ public class SubscriptionsStoreTest {
|
||||
Topic topic = new Topic(t);
|
||||
store = new SubscriptionsStore();
|
||||
MemoryStorageService memStore = new MemoryStorageService();
|
||||
memStore.initStore();
|
||||
ISessionsStore aSessionsStore = memStore.sessionsStore();
|
||||
store.init(aSessionsStore);
|
||||
Subscription sub = new Subscription("FAKE_CLI_ID_1", subscription, MqttQoS.AT_MOST_ONCE);
|
||||
@@ -223,7 +221,6 @@ public class SubscriptionsStoreTest {
|
||||
Topic topic = new Topic(t);
|
||||
store = new SubscriptionsStore();
|
||||
MemoryStorageService memStore = new MemoryStorageService();
|
||||
memStore.initStore();
|
||||
store.init(memStore.sessionsStore());
|
||||
Subscription sub = new Subscription("FAKE_CLI_ID_1", subscription, MqttQoS.AT_MOST_ONCE);
|
||||
sessionsStore.addNewSubscription(sub);
|
||||
@@ -276,7 +273,6 @@ public class SubscriptionsStoreTest {
|
||||
public void removeSubscription_withDifferentClients_subscribedSameTopic() {
|
||||
SubscriptionsStore aStore = new SubscriptionsStore();
|
||||
MemoryStorageService memStore = new MemoryStorageService();
|
||||
memStore.initStore();
|
||||
ISessionsStore sessionsStore = memStore.sessionsStore();
|
||||
aStore.init(sessionsStore);
|
||||
// subscribe a not active clientID1 to /topic
|
||||
|
||||
@@ -52,11 +52,9 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
// maps clientID->[MessageId -> guid]
|
||||
private Map<String, Map<Integer, MessageGUID>> m_secondPhaseStore = new HashMap<>();
|
||||
|
||||
private Map<String, Map<Integer, MessageGUID>> m_messageToGuids;
|
||||
private final IMessagesStore m_messagesStore;
|
||||
|
||||
public MemorySessionStore(IMessagesStore messagesStore, Map<String, Map<Integer, MessageGUID>> messageToGuids) {
|
||||
m_messageToGuids = messageToGuids;
|
||||
public MemorySessionStore(IMessagesStore messagesStore) {
|
||||
this.m_messagesStore = messagesStore;
|
||||
}
|
||||
|
||||
@@ -235,13 +233,6 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
return guid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageGUID mapToGuid(String clientID, int messageID) {
|
||||
HashMap<Integer, MessageGUID> guids = (HashMap<Integer, MessageGUID>) Utils
|
||||
.defaultGet(m_messageToGuids, clientID, new HashMap<Integer, MessageGUID>());
|
||||
return guids.get(messageID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoredMessage getInflightMessage(String clientID, int messageID) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user