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:
swarwick
2015-03-14 16:37:09 +01:00
committed by andrea
parent 4195b0d62c
commit 8943445efa
4 changed files with 10 additions and 8 deletions
@@ -173,7 +173,7 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
benchmarkEnabled = Boolean.parseBoolean(System.getProperty("moquette.processor.benchmark", "false"));
//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_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.subscriptions.Subscription;
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 org.mapdb.DB;
@@ -57,16 +56,21 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
//persistent Map of clientID, set of Subscriptions
private ConcurrentMap<String, Set<Subscription>> m_persistentSubscriptions;
private DB m_db;
private String m_storePath;
public MapDBPersistentStore(String storePath) {
this.m_storePath = storePath;
}
@Override
public void initStore() {
File tmpFile;
try {
tmpFile = new File(STORAGE_FILE_PATH);
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 [" + 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_retainedStore = m_db.getHashMap("retained");