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:
Andreas Mager
2017-03-20 13:04:14 +01:00
parent ec6ec09cee
commit 63d2f2dd69
20 changed files with 124 additions and 64 deletions
@@ -136,8 +136,11 @@ public class ProtocolProcessor {
private boolean allowAnonymous;
private boolean allowZeroByteClientId;
private IAuthorizator m_authorizator;
private IMessagesStore m_messagesStore;
private ISessionsStore m_sessionsStore;
private IAuthenticator m_authenticator;
private BrokerInterceptor m_interceptor;
private String m_server_port;
@@ -1063,4 +1066,12 @@ public class ProtocolProcessor {
public void removeInterceptHandler(InterceptHandler interceptHandler) {
this.m_interceptor.removeInterceptHandler(interceptHandler);
}
public IMessagesStore getMessagesStore() {
return m_messagesStore;
}
public ISessionsStore getSessionsStore() {
return m_sessionsStore;
}
}
@@ -24,6 +24,7 @@ import io.moquette.server.config.IConfig;
import io.moquette.server.config.IResourceLoader;
import io.moquette.spi.IMessagesStore;
import io.moquette.spi.ISessionsStore;
import io.moquette.spi.IStore;
import io.moquette.spi.impl.security.ACLFileParser;
import io.moquette.spi.impl.security.AcceptAllAuthenticator;
import io.moquette.spi.impl.security.DenyAllAuthorizator;
@@ -53,10 +54,10 @@ public class ProtocolProcessorBootstrapper {
private SubscriptionsStore subscriptions;
private MapDBPersistentStore m_mapStorage;
private ISessionsStore m_sessionsStore;
private Runnable storeShutdown = null;
private BrokerInterceptor m_interceptor;
private final ProtocolProcessor m_processor = new ProtocolProcessor();
@@ -89,11 +90,31 @@ public class ProtocolProcessorBootstrapper {
IAuthenticator authenticator, IAuthorizator authorizator, Server server) {
subscriptions = new SubscriptionsStore();
IMessagesStore messagesStore;
LOG.info("Initializing messages and sessions stores...");
m_mapStorage = new MapDBPersistentStore(props);
m_mapStorage.initStore();
IMessagesStore messagesStore = m_mapStorage.messagesStore();
m_sessionsStore = m_mapStorage.sessionsStore();
String storageClassName = props.getProperty(BrokerConstants.STORAGE_CLASS_NAME, "");
if (storageClassName != null && !storageClassName.isEmpty()) {
final IStore store = loadClass(storageClassName, IStore.class, Server.class, server);
messagesStore = store.messagesStore();
m_sessionsStore = store.sessionsStore();
storeShutdown = new Runnable() {
@Override
public void run() {
store.close();
}
};
} else {
final MapDBPersistentStore m_mapStorage = new MapDBPersistentStore(props);
m_mapStorage.initStore();
messagesStore = m_mapStorage.messagesStore();
m_sessionsStore = m_mapStorage.sessionsStore();
storeShutdown = new Runnable() {
@Override
public void run() {
m_mapStorage.close();
}
};
}
LOG.info("Configuring message interceptors...");
@@ -258,12 +279,17 @@ public class ProtocolProcessorBootstrapper {
return instance;
}
public ISessionsStore getSessionsStore() {
return m_sessionsStore;
}
public List<Subscription> getSubscriptions() {
return m_sessionsStore.getSubscriptions();
}
public void shutdown() {
this.m_mapStorage.close();
if (storeShutdown != null)
storeShutdown.run();
}
public ConnectionDescriptorStore getConnectionDescriptors() {