mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 15:10:44 +01:00
Use PersistenceManager
This commit is contained in:
parent
308c970b68
commit
878f64555c
1 changed files with 14 additions and 25 deletions
|
@ -24,10 +24,9 @@ import bisq.core.dao.state.model.DaoState;
|
||||||
import bisq.network.p2p.storage.persistence.ResourceDataStoreService;
|
import bisq.network.p2p.storage.persistence.ResourceDataStoreService;
|
||||||
import bisq.network.p2p.storage.persistence.StoreService;
|
import bisq.network.p2p.storage.persistence.StoreService;
|
||||||
|
|
||||||
import bisq.common.UserThread;
|
|
||||||
import bisq.common.config.Config;
|
import bisq.common.config.Config;
|
||||||
import bisq.common.file.FileUtil;
|
import bisq.common.file.FileUtil;
|
||||||
import bisq.common.storage.Storage;
|
import bisq.common.persistence.PersistenceManager;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
@ -36,7 +35,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@ -45,13 +43,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DaoStateStorageService extends StoreService<DaoStateStore> {
|
public class DaoStateStorageService extends StoreService<DaoStateStore> {
|
||||||
// We needed to rename the db file as we have a new file structure with the hashChain feature and need to enforce the
|
|
||||||
// new file to be used.
|
|
||||||
// We can rename to DaoStateStore before mainnet launch again.
|
|
||||||
// Another update due to some data field changes which would cause diff. hashes, so to enforce users to get the new
|
|
||||||
// data we rename it to DaoStateStore
|
|
||||||
private static final String FILE_NAME = "DaoStateStore";
|
|
||||||
|
|
||||||
private final DaoState daoState;
|
private final DaoState daoState;
|
||||||
private final DaoStateMonitoringService daoStateMonitoringService;
|
private final DaoStateMonitoringService daoStateMonitoringService;
|
||||||
|
|
||||||
|
@ -65,8 +56,8 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
|
||||||
DaoState daoState,
|
DaoState daoState,
|
||||||
DaoStateMonitoringService daoStateMonitoringService,
|
DaoStateMonitoringService daoStateMonitoringService,
|
||||||
@Named(Config.STORAGE_DIR) File storageDir,
|
@Named(Config.STORAGE_DIR) File storageDir,
|
||||||
Storage<DaoStateStore> daoSnapshotStorage) {
|
PersistenceManager<DaoStateStore> persistenceManager) {
|
||||||
super(storageDir, daoSnapshotStorage);
|
super(storageDir, persistenceManager);
|
||||||
this.daoState = daoState;
|
this.daoState = daoState;
|
||||||
this.daoStateMonitoringService = daoStateMonitoringService;
|
this.daoStateMonitoringService = daoStateMonitoringService;
|
||||||
|
|
||||||
|
@ -80,19 +71,13 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return FILE_NAME;
|
return "DaoStateStore";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void persist(DaoState daoState, LinkedList<DaoStateHash> daoStateHashChain) {
|
public void persistNow(DaoState daoState, LinkedList<DaoStateHash> daoStateHashChain, Runnable completeHandler) {
|
||||||
persist(daoState, daoStateHashChain, 200);
|
store.setDaoState(daoState);
|
||||||
}
|
store.setDaoStateHashChain(daoStateHashChain);
|
||||||
|
persistenceManager.persistNow(completeHandler);
|
||||||
private void persist(DaoState daoState, LinkedList<DaoStateHash> daoStateHashChain, long delayInMilli) {
|
|
||||||
store.modifySynchronized(() -> {
|
|
||||||
store.setDaoState(daoState);
|
|
||||||
store.setDaoStateHashChain(daoStateHashChain);
|
|
||||||
});
|
|
||||||
storage.queueUpForSave(store, delayInMilli);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DaoState getPersistedBsqState() {
|
public DaoState getPersistedBsqState() {
|
||||||
|
@ -104,8 +89,7 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resyncDaoStateFromGenesis(Runnable resultHandler) {
|
public void resyncDaoStateFromGenesis(Runnable resultHandler) {
|
||||||
persist(new DaoState(), new LinkedList<>(), 1);
|
persistNow(new DaoState(), new LinkedList<>(), resultHandler);
|
||||||
UserThread.runAfter(resultHandler, 300, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resyncDaoStateFromResources(File storageDir) throws IOException {
|
public void resyncDaoStateFromResources(File storageDir) throws IOException {
|
||||||
|
@ -139,4 +123,9 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
|
||||||
protected DaoStateStore createStore() {
|
protected DaoStateStore createStore() {
|
||||||
return new DaoStateStore(DaoState.getClone(daoState), new LinkedList<>(daoStateMonitoringService.getDaoStateHashChain()));
|
return new DaoStateStore(DaoState.getClone(daoState), new LinkedList<>(daoStateMonitoringService.getDaoStateHashChain()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initializePersistenceManager() {
|
||||||
|
persistenceManager.initialize(store, PersistenceManager.Priority.LOW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue