Set delay for persistence in each client

This commit is contained in:
Manfred Karrer 2017-11-10 21:17:40 -05:00
parent 097ce7fdb9
commit 01d4c6fb8c
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
15 changed files with 23 additions and 25 deletions

View File

@ -77,26 +77,24 @@ public class Storage<T extends PersistableEnvelope> {
}
@Nullable
public T initAndGetPersistedWithFileName(String fileName) {
public T initAndGetPersistedWithFileName(String fileName, long delay) {
this.fileName = fileName;
storageFile = new File(dir, fileName);
fileManager = new FileManager<>(dir, storageFile, 300, persistenceProtoResolver);
fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver);
return getPersisted();
}
@Nullable
public T initAndGetPersisted(T persistable) {
return initAndGetPersisted(persistable, persistable.getClass().getSimpleName());
public T initAndGetPersisted(T persistable, long delay) {
return initAndGetPersisted(persistable, persistable.getClass().getSimpleName(), delay);
}
@Nullable
public T initAndGetPersisted(T persistable, String fileName) {
public T initAndGetPersisted(T persistable, String fileName, long delay) {
this.persistable = persistable;
this.fileName = fileName;
storageFile = new File(dir, fileName);
fileManager = new FileManager<>(dir, storageFile, 600, persistenceProtoResolver);
fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver);
return getPersisted();
}

View File

@ -54,7 +54,7 @@ public final class DisputeList implements PersistableEnvelope, PersistedDataHost
@Override
public void readPersisted() {
DisputeList persisted = storage.initAndGetPersisted(this);
DisputeList persisted = storage.initAndGetPersisted(this, 50);
if (persisted != null)
list.addAll(persisted.getList());
}

View File

@ -52,7 +52,7 @@ public final class AddressEntryList implements PersistableEnvelope, PersistedDat
@Override
public void readPersisted() {
AddressEntryList persisted = storage.initAndGetPersisted(this);
AddressEntryList persisted = storage.initAndGetPersisted(this, 10);
if (persisted != null)
list = new ArrayList<>(persisted.getList());
}

View File

@ -224,7 +224,7 @@ public class BsqChainState implements PersistableEnvelope {
public void applySnapshot() {
lock.write(() -> {
checkNotNull(storage, "storage must not be null");
BsqChainState snapshot = storage.initAndGetPersistedWithFileName("BsqChainState");
BsqChainState snapshot = storage.initAndGetPersistedWithFileName("BsqChainState", 50);
bsqBlocks.clear();
txMap.clear();
unspentTxOutputsMap.clear();

View File

@ -109,7 +109,7 @@ public class CompensationRequestManager implements PersistedDataHost {
@Override
public void readPersisted() {
if (BisqEnvironment.isDAOActivatedAndBaseCurrencySupportingBsq()) {
PersistableList<CompensationRequest> persisted = compensationRequestsStorage.initAndGetPersistedWithFileName("CompensationRequests");
PersistableList<CompensationRequest> persisted = compensationRequestsStorage.initAndGetPersistedWithFileName("CompensationRequests", 50);
if (persisted != null)
model.setPersistedCompensationRequest(persisted.getList());
}

View File

@ -94,7 +94,7 @@ public class VotingManager implements PersistedDataHost {
@Override
public void readPersisted() {
if (BisqEnvironment.isDAOActivatedAndBaseCurrencySupportingBsq()) {
PersistableList<VoteItemsList> persisted = voteItemCollectionsStorage.initAndGetPersistedWithFileName("VoteItemCollections");
PersistableList<VoteItemsList> persisted = voteItemCollectionsStorage.initAndGetPersistedWithFileName("VoteItemCollections", 50);
if (persisted != null)
voteItemsLists.addAll(persisted.getList());
}

View File

@ -52,7 +52,7 @@ public final class TradableList<T extends Tradable> implements PersistableEnvelo
public TradableList(Storage<TradableList<T>> storage, String fileName) {
this.storage = storage;
TradableList<T> persisted = storage.initAndGetPersisted(this, fileName);
TradableList<T> persisted = storage.initAndGetPersisted(this, fileName, 50);
if (persisted != null)
list.addAll(persisted.getList());
}

View File

@ -73,7 +73,7 @@ public class TradeStatisticsManager implements PersistedDataHost {
@Override
public void readPersisted() {
TradeStatisticsList persisted = statisticsStorage.initAndGetPersistedWithFileName("TradeStatistics");
TradeStatisticsList persisted = statisticsStorage.initAndGetPersistedWithFileName("TradeStatistics", 500);
if (persisted != null)
persistedTradeStatisticsList = persisted.getList();
}

View File

@ -73,7 +73,7 @@ public class TradeStatisticsMigrationTool {
null);
persistedTradeStatisticsList.add(tradeStatistics);
}
statisticsStorage.initAndGetPersistedWithFileName("TradeStatistics");
statisticsStorage.initAndGetPersistedWithFileName("TradeStatistics", 500);
statisticsStorage.queueUpForSave(new TradeStatisticsList(new ArrayList<>(persistedTradeStatisticsList)), 200);
} else {
log.warn("Unknown JOSN object " + fromDisc);

View File

@ -165,7 +165,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
@Override
public void readPersisted() {
PreferencesPayload persisted = storage.initAndGetPersistedWithFileName("PreferencesPayload");
PreferencesPayload persisted = storage.initAndGetPersistedWithFileName("PreferencesPayload", 100);
final BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
TradeCurrency preferredTradeCurrency;
if (persisted != null) {

View File

@ -74,7 +74,7 @@ public final class User implements PersistedDataHost {
@Override
public void readPersisted() {
UserPayload persisted = storage.initAndGetPersistedWithFileName("UserPayload");
UserPayload persisted = storage.initAndGetPersistedWithFileName("UserPayload", 100);
userPayload = persisted != null ? persisted : new UserPayload();
checkNotNull(userPayload.getPaymentAccounts(), "userPayload.getPaymentAccounts() must not be null");

View File

@ -67,7 +67,7 @@ public final class Navigation implements PersistedDataHost {
@Override
public void readPersisted() {
NavigationPath persisted = storage.initAndGetPersisted(navigationPath, "NavigationPath");
NavigationPath persisted = storage.initAndGetPersisted(navigationPath, "NavigationPath", 300);
if (persisted != null) {
List<Class<? extends View>> viewClasses = persisted.getPath().stream()
.map(className -> {

View File

@ -113,7 +113,7 @@ public class GUIUtil {
String directory = getDirectoryFromChooser(preferences, stage);
if (directory != null && !directory.isEmpty()) {
Storage<PersistableList<PaymentAccount>> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver);
paymentAccountsStorage.initAndGetPersisted(new PaymentAccountList(accounts), fileName);
paymentAccountsStorage.initAndGetPersisted(new PaymentAccountList(accounts), fileName, 50);
paymentAccountsStorage.queueUpForSave();
new Popup<>().feedback(Res.get("guiUtil.accountExport.savedToPath", Paths.get(directory, fileName).toAbsolutePath())).show();
}
@ -134,7 +134,7 @@ public class GUIUtil {
String directory = Paths.get(path).getParent().toString();
preferences.setDirectoryChooserPath(directory);
Storage<PaymentAccountList> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver);
PaymentAccountList persisted = paymentAccountsStorage.initAndGetPersistedWithFileName(fileName);
PaymentAccountList persisted = paymentAccountsStorage.initAndGetPersistedWithFileName(fileName, 50);
if (persisted != null) {
final StringBuilder msg = new StringBuilder();
persisted.getList().stream().forEach(paymentAccount -> {

View File

@ -136,7 +136,7 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
@Override
public void readPersisted() {
PeerList persistedPeerList = storage.initAndGetPersistedWithFileName("PeerList");
PeerList persistedPeerList = storage.initAndGetPersistedWithFileName("PeerList", 1000);
if (persistedPeerList != null)
this.persistedPeers.addAll(persistedPeerList.getList());
}

View File

@ -104,7 +104,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
@Override
public void readPersisted() {
SequenceNumberMap persistedSequenceNumberMap = sequenceNumberMapStorage.initAndGetPersisted(sequenceNumberMap);
SequenceNumberMap persistedSequenceNumberMap = sequenceNumberMapStorage.initAndGetPersisted(sequenceNumberMap, 300);
if (persistedSequenceNumberMap != null)
sequenceNumberMap.setMap(getPurgedSequenceNumberMap(persistedSequenceNumberMap.getMap()));
@ -136,7 +136,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
log.debug(storageFileName + " file exists already.");
}
// takes about 4 seconds with PB! :-(
persistableEntryMap = persistedEntryMapStorage.<HashMap<ByteArray, MapValue>>initAndGetPersistedWithFileName(storageFileName);
persistableEntryMap = persistedEntryMapStorage.<HashMap<ByteArray, MapValue>>initAndGetPersistedWithFileName(storageFileName, 100);
if (persistableEntryMap != null) {
map.putAll(persistableEntryMap.getMap());
@ -174,7 +174,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
} else {
log.debug(storageFileName + " file exists already.");
}
persistableNetworkPayloadCollection = persistableNetworkPayloadMapStorage.initAndGetPersistedWithFileName(storageFileName);
persistableNetworkPayloadCollection = persistableNetworkPayloadMapStorage.initAndGetPersistedWithFileName(storageFileName, 100);
if (persistableNetworkPayloadCollection != null) {
log.info("persistableNetworkPayloadMap size=" + persistableNetworkPayloadCollection.getMap().size());