mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Set delay for persistence in each client
This commit is contained in:
parent
097ce7fdb9
commit
01d4c6fb8c
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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");
|
||||
|
@ -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 -> {
|
||||
|
@ -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 -> {
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user