broker/MapDBPersistentStore: code formatter used
This commit is contained in:
@@ -23,14 +23,12 @@ import org.mapdb.DB;
|
|||||||
import org.mapdb.DBMaker;
|
import org.mapdb.DBMaker;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static io.moquette.BrokerConstants.AUTOSAVE_INTERVAL_PROPERTY_NAME;
|
import static io.moquette.BrokerConstants.AUTOSAVE_INTERVAL_PROPERTY_NAME;
|
||||||
import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME;
|
import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME;
|
||||||
|
|
||||||
@@ -40,10 +38,11 @@ import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME;
|
|||||||
public class MapDBPersistentStore {
|
public class MapDBPersistentStore {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a DTO used to persist minimal status (clean session and activation status) of
|
* This is a DTO used to persist minimal status (clean session and activation status) of a
|
||||||
* a session.
|
* session.
|
||||||
* */
|
*/
|
||||||
public static class PersistentSession implements Serializable {
|
public static class PersistentSession implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 5052054783220481854L;
|
private static final long serialVersionUID = 5052054783220481854L;
|
||||||
public final boolean cleanSession;
|
public final boolean cleanSession;
|
||||||
|
|
||||||
@@ -69,8 +68,9 @@ public class MapDBPersistentStore {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method to create message store backed by MapDB
|
* Factory method to create message store backed by MapDB
|
||||||
|
*
|
||||||
* @return the message store instance.
|
* @return the message store instance.
|
||||||
* */
|
*/
|
||||||
public IMessagesStore messagesStore() {
|
public IMessagesStore messagesStore() {
|
||||||
return m_messageStore;
|
return m_messageStore;
|
||||||
}
|
}
|
||||||
@@ -92,13 +92,20 @@ public class MapDBPersistentStore {
|
|||||||
boolean fileNewlyCreated = tmpFile.createNewFile();
|
boolean fileNewlyCreated = tmpFile.createNewFile();
|
||||||
LOG.warn("Using {} MapDB store file. Path = {}.", fileNewlyCreated ? "fresh" : "existing", m_storePath);
|
LOG.warn("Using {} MapDB store file. Path = {}.", fileNewlyCreated ? "fresh" : "existing", m_storePath);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOG.error("Unable to open MapDB store file. Path = {}, cause = {}, errorMessage = {}.", m_storePath, ex.getCause(), ex.getMessage());
|
LOG.error(
|
||||||
throw new RuntimeException("Can't create temp file for subscriptions storage [" + m_storePath + "]", ex);
|
"Unable to open MapDB store file. Path = {}, cause = {}, errorMessage = {}.",
|
||||||
|
m_storePath,
|
||||||
|
ex.getCause(),
|
||||||
|
ex.getMessage());
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Can't create temp file for subscriptions storage [" + m_storePath + "]",
|
||||||
|
ex);
|
||||||
}
|
}
|
||||||
m_db = DBMaker.newFileDB(tmpFile).make();
|
m_db = DBMaker.newFileDB(tmpFile).make();
|
||||||
}
|
}
|
||||||
LOG.info("Scheduling MapDB commit task...");
|
LOG.info("Scheduling MapDB commit task...");
|
||||||
m_scheduler.scheduleWithFixedDelay(new Runnable() {
|
m_scheduler.scheduleWithFixedDelay(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
LOG.debug("Committing to MapDB...");
|
LOG.debug("Committing to MapDB...");
|
||||||
@@ -106,7 +113,7 @@ public class MapDBPersistentStore {
|
|||||||
}
|
}
|
||||||
}, this.m_autosaveInterval, this.m_autosaveInterval, TimeUnit.SECONDS);
|
}, this.m_autosaveInterval, this.m_autosaveInterval, TimeUnit.SECONDS);
|
||||||
|
|
||||||
//TODO check m_db is valid and
|
// TODO check m_db is valid and
|
||||||
m_messageStore = new MapDBMessagesStore(m_db);
|
m_messageStore = new MapDBMessagesStore(m_db);
|
||||||
m_messageStore.initStore();
|
m_messageStore.initStore();
|
||||||
|
|
||||||
@@ -127,7 +134,8 @@ public class MapDBPersistentStore {
|
|||||||
this.m_scheduler.shutdown();
|
this.m_scheduler.shutdown();
|
||||||
try {
|
try {
|
||||||
m_scheduler.awaitTermination(10L, TimeUnit.SECONDS);
|
m_scheduler.awaitTermination(10L, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
if (!m_scheduler.isTerminated()) {
|
if (!m_scheduler.isTerminated()) {
|
||||||
LOG.warn("Forcing shutdown of MapDB commit tasks...");
|
LOG.warn("Forcing shutdown of MapDB commit tasks...");
|
||||||
m_scheduler.shutdown();
|
m_scheduler.shutdown();
|
||||||
|
|||||||
Reference in New Issue
Block a user