From d388ae01bb376e4ec4516f97a11b27adbab0593b Mon Sep 17 00:00:00 2001 From: swarwick Date: Wed, 11 Mar 2015 11:39:07 -0400 Subject: [PATCH] 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. --- .../spi/persistence/MapDBPersistentStore.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/broker/src/main/java/org/eclipse/moquette/spi/persistence/MapDBPersistentStore.java b/broker/src/main/java/org/eclipse/moquette/spi/persistence/MapDBPersistentStore.java index b8670f3b..c0d338fd 100644 --- a/broker/src/main/java/org/eclipse/moquette/spi/persistence/MapDBPersistentStore.java +++ b/broker/src/main/java/org/eclipse/moquette/spi/persistence/MapDBPersistentStore.java @@ -59,21 +59,33 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore { private DB m_db; 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) { this.m_storePath = storePath; } @Override public void initStore() { - File tmpFile; - try { - tmpFile = new File(m_storePath); - tmpFile.createNewFile(); - } catch (IOException ex) { - LOG.error(null, ex); - throw new MQTTException("Can't create temp file for subscriptions storage [" + m_storePath + "]", ex); - } - m_db = DBMaker.newFileDB(tmpFile).make(); + if (m_storePath == null || m_storePath.length() <= 0) { + m_db = DBMaker.newMemoryDB().make(); + } else { + File tmpFile; + try { + tmpFile = new File(m_storePath); + tmpFile.createNewFile(); + } catch (IOException ex) { + 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_persistentMessageStore = m_db.getHashMap("persistedMessages"); m_inflightStore = m_db.getHashMap("inflight");