Allow the mapdb store to remain in memory

If the store path supplied is null or empty we will create an in memory
mapdb store.
This commit is contained in:
swarwick
2015-03-14 16:38:30 +01:00
committed by andrea
parent d215ba8c8b
commit d388ae01bb
@@ -59,12 +59,23 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
private DB m_db; private DB m_db;
private String m_storePath; private String m_storePath;
/*
* The default constructor will create an in memory store as no file path was specified
*/
public MapDBPersistentStore() {
this.m_storePath = "";
}
public MapDBPersistentStore(String storePath) { public MapDBPersistentStore(String storePath) {
this.m_storePath = storePath; this.m_storePath = storePath;
} }
@Override @Override
public void initStore() { public void initStore() {
if (m_storePath == null || m_storePath.length() <= 0) {
m_db = DBMaker.newMemoryDB().make();
} else {
File tmpFile; File tmpFile;
try { try {
tmpFile = new File(m_storePath); tmpFile = new File(m_storePath);
@@ -74,6 +85,7 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
throw new MQTTException("Can't create temp file for subscriptions storage [" + m_storePath + "]", 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");
m_persistentMessageStore = m_db.getHashMap("persistedMessages"); m_persistentMessageStore = m_db.getHashMap("persistedMessages");
m_inflightStore = m_db.getHashMap("inflight"); m_inflightStore = m_db.getHashMap("inflight");