Update to allow for persistent store to be specified in the config
Update to allow for persistent store to be specified in the config
This commit is contained in:
@@ -46,6 +46,7 @@ class ConfigurationParser {
|
|||||||
m_properties.put("host", Constants.HOST);
|
m_properties.put("host", Constants.HOST);
|
||||||
m_properties.put("websocket_port", Integer.toString(Constants.WEBSOCKET_PORT));
|
m_properties.put("websocket_port", Integer.toString(Constants.WEBSOCKET_PORT));
|
||||||
m_properties.put("password_file", "");
|
m_properties.put("password_file", "");
|
||||||
|
m_properties.put("persistent_store", System.getProperty("user.home") + File.separator + "moquette_store.mapdb");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ public class Server {
|
|||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Server.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Server.class);
|
||||||
|
|
||||||
public static final String STORAGE_FILE_PATH = System.getProperty("user.home") +
|
|
||||||
File.separator + "moquette_store.mapdb";
|
|
||||||
|
|
||||||
private ServerAcceptor m_acceptor;
|
private ServerAcceptor m_acceptor;
|
||||||
SimpleMessaging messaging;
|
SimpleMessaging messaging;
|
||||||
|
|
||||||
@@ -64,7 +61,6 @@ public class Server {
|
|||||||
*/
|
*/
|
||||||
public void startServer(File configFile) throws IOException {
|
public void startServer(File configFile) throws IOException {
|
||||||
LOG.info("Using config file: " + configFile.getAbsolutePath());
|
LOG.info("Using config file: " + configFile.getAbsolutePath());
|
||||||
LOG.info("Persistent store file: " + STORAGE_FILE_PATH);
|
|
||||||
|
|
||||||
ConfigurationParser confParser = new ConfigurationParser();
|
ConfigurationParser confParser = new ConfigurationParser();
|
||||||
try {
|
try {
|
||||||
@@ -86,6 +82,7 @@ public class Server {
|
|||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public void startServer(Properties configProps) throws IOException {
|
public void startServer(Properties configProps) throws IOException {
|
||||||
|
LOG.info("Persistent store file: " + configProps.get("persistent_store"));
|
||||||
messaging = SimpleMessaging.getInstance();
|
messaging = SimpleMessaging.getInstance();
|
||||||
messaging.init(configProps);
|
messaging.init(configProps);
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
|
|||||||
benchmarkEnabled = Boolean.parseBoolean(System.getProperty("moquette.processor.benchmark", "false"));
|
benchmarkEnabled = Boolean.parseBoolean(System.getProperty("moquette.processor.benchmark", "false"));
|
||||||
|
|
||||||
//TODO use a property to select the storage path
|
//TODO use a property to select the storage path
|
||||||
MapDBPersistentStore mapStorage = new MapDBPersistentStore();
|
MapDBPersistentStore mapStorage = new MapDBPersistentStore(props.getProperty("persistent_store", ""));
|
||||||
m_storageService = mapStorage;
|
m_storageService = mapStorage;
|
||||||
m_sessionsStore = mapStorage;
|
m_sessionsStore = mapStorage;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import org.eclipse.moquette.spi.impl.events.PublishEvent;
|
|||||||
import org.eclipse.moquette.spi.impl.storage.StoredPublishEvent;
|
import org.eclipse.moquette.spi.impl.storage.StoredPublishEvent;
|
||||||
import org.eclipse.moquette.spi.impl.subscriptions.Subscription;
|
import org.eclipse.moquette.spi.impl.subscriptions.Subscription;
|
||||||
import org.eclipse.moquette.proto.messages.AbstractMessage;
|
import org.eclipse.moquette.proto.messages.AbstractMessage;
|
||||||
import static org.eclipse.moquette.server.Server.STORAGE_FILE_PATH;
|
|
||||||
import static org.eclipse.moquette.spi.impl.Utils.defaultGet;
|
import static org.eclipse.moquette.spi.impl.Utils.defaultGet;
|
||||||
|
|
||||||
import org.mapdb.DB;
|
import org.mapdb.DB;
|
||||||
@@ -57,16 +56,21 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
|
|||||||
//persistent Map of clientID, set of Subscriptions
|
//persistent Map of clientID, set of Subscriptions
|
||||||
private ConcurrentMap<String, Set<Subscription>> m_persistentSubscriptions;
|
private ConcurrentMap<String, Set<Subscription>> m_persistentSubscriptions;
|
||||||
private DB m_db;
|
private DB m_db;
|
||||||
|
private String m_storePath;
|
||||||
|
|
||||||
|
public MapDBPersistentStore(String storePath) {
|
||||||
|
this.m_storePath = storePath;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initStore() {
|
public void initStore() {
|
||||||
File tmpFile;
|
File tmpFile;
|
||||||
try {
|
try {
|
||||||
tmpFile = new File(STORAGE_FILE_PATH);
|
tmpFile = new File(m_storePath);
|
||||||
tmpFile.createNewFile();
|
tmpFile.createNewFile();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOG.error(null, ex);
|
LOG.error(null, ex);
|
||||||
throw new MQTTException("Can't create temp file for subscriptions storage [" + STORAGE_FILE_PATH + "]", ex);
|
throw new MQTTException("Can't create temp file for subscriptions storage [" + m_storePath + "]", ex);
|
||||||
}
|
}
|
||||||
m_db = DBMaker.newFileDB(tmpFile).make();
|
m_db = DBMaker.newFileDB(tmpFile).make();
|
||||||
m_retainedStore = m_db.getHashMap("retained");
|
m_retainedStore = m_db.getHashMap("retained");
|
||||||
|
|||||||
Reference in New Issue
Block a user