Use PersistenceManager for MapStoreService (not yet supported for subclasses)

This commit is contained in:
chimp1984 2020-10-01 17:21:42 -05:00
parent 2e55251bcf
commit 92b0ea9f13
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3

View file

@ -19,9 +19,9 @@ package bisq.network.p2p.storage.persistence;
import bisq.network.p2p.storage.P2PDataStorage; import bisq.network.p2p.storage.P2PDataStorage;
import bisq.common.persistence.PersistenceManager;
import bisq.common.proto.persistable.PersistableEnvelope; import bisq.common.proto.persistable.PersistableEnvelope;
import bisq.common.proto.persistable.PersistablePayload; import bisq.common.proto.persistable.PersistablePayload;
import bisq.common.storage.Storage;
import java.io.File; import java.io.File;
@ -43,8 +43,8 @@ public abstract class MapStoreService<T extends PersistableEnvelope, R extends P
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public MapStoreService(File storageDir, Storage<T> storage) { public MapStoreService(File storageDir, PersistenceManager<T> persistenceManager) {
super(storageDir, storage); super(storageDir, persistenceManager);
} }
@ -58,18 +58,18 @@ public abstract class MapStoreService<T extends PersistableEnvelope, R extends P
void put(P2PDataStorage.ByteArray hash, R payload) { void put(P2PDataStorage.ByteArray hash, R payload) {
getMap().put(hash, payload); getMap().put(hash, payload);
persist(); requestPersistence();
} }
R putIfAbsent(P2PDataStorage.ByteArray hash, R payload) { R putIfAbsent(P2PDataStorage.ByteArray hash, R payload) {
R previous = getMap().putIfAbsent(hash, payload); R previous = getMap().putIfAbsent(hash, payload);
persist(); requestPersistence();
return previous; return previous;
} }
R remove(P2PDataStorage.ByteArray hash) { R remove(P2PDataStorage.ByteArray hash) {
final R result = getMap().remove(hash); R result = getMap().remove(hash);
persist(); requestPersistence();
return result; return result;
} }