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:
+21
-9
@@ -59,21 +59,33 @@ 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() {
|
||||||
File tmpFile;
|
if (m_storePath == null || m_storePath.length() <= 0) {
|
||||||
try {
|
m_db = DBMaker.newMemoryDB().make();
|
||||||
tmpFile = new File(m_storePath);
|
} else {
|
||||||
tmpFile.createNewFile();
|
File tmpFile;
|
||||||
} catch (IOException ex) {
|
try {
|
||||||
LOG.error(null, ex);
|
tmpFile = new File(m_storePath);
|
||||||
throw new MQTTException("Can't create temp file for subscriptions storage [" + m_storePath + "]", ex);
|
tmpFile.createNewFile();
|
||||||
}
|
} catch (IOException ex) {
|
||||||
m_db = DBMaker.newFileDB(tmpFile).make();
|
LOG.error(null, ex);
|
||||||
|
throw new MQTTException("Can't create temp file for subscriptions storage [" + m_storePath + "]", ex);
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
|||||||
Reference in New Issue
Block a user