Use PersistenceManager

This commit is contained in:
chimp1984 2020-10-01 19:51:11 -05:00
parent 27c2cb894c
commit e0ea742a47
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3
6 changed files with 47 additions and 81 deletions

View file

@ -23,7 +23,6 @@ import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.DisputeList;
import bisq.common.proto.ProtoUtil;
import bisq.common.storage.Storage;
import com.google.protobuf.Message;
@ -44,19 +43,10 @@ import static com.google.common.base.Preconditions.checkArgument;
* Calls to the List are delegated because this class intercepts the add/remove calls so changes
* can be saved to disc.
*/
public final class ArbitrationDisputeList extends DisputeList<ArbitrationDisputeList> {
public final class ArbitrationDisputeList extends DisputeList<Dispute> {
ArbitrationDisputeList(Storage<ArbitrationDisputeList> storage) {
super(storage);
}
@Override
public void readPersisted() {
// We need to use DisputeList as file name to not lose existing disputes which are stored in the DisputeList file
ArbitrationDisputeList persisted = storage.initAndGetPersisted(this, "DisputeList", 50);
if (persisted != null) {
list.addAll(persisted.getList());
}
ArbitrationDisputeList() {
super();
}
@ -64,30 +54,26 @@ public final class ArbitrationDisputeList extends DisputeList<ArbitrationDispute
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private ArbitrationDisputeList(Storage<ArbitrationDisputeList> storage, List<Dispute> list) {
super(storage, list);
private ArbitrationDisputeList(List<Dispute> list) {
super(list);
}
@Override
public Message toProtoMessage() {
list.forEach(dispute -> checkArgument(dispute.getSupportType().equals(SupportType.ARBITRATION), "Support type has to be ARBITRATION"));
forEach(dispute -> checkArgument(dispute.getSupportType().equals(SupportType.ARBITRATION), "Support type has to be ARBITRATION"));
return protobuf.PersistableEnvelope.newBuilder().setArbitrationDisputeList(protobuf.ArbitrationDisputeList.newBuilder()
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list), protobuf.Dispute.class))).build();
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(getList()), protobuf.Dispute.class))).build();
}
public static ArbitrationDisputeList fromProto(protobuf.ArbitrationDisputeList proto,
CoreProtoResolver coreProtoResolver,
Storage<ArbitrationDisputeList> storage) {
CoreProtoResolver coreProtoResolver) {
List<Dispute> list = proto.getDisputeList().stream()
.map(disputeProto -> Dispute.fromProto(disputeProto, coreProtoResolver))
.filter(e -> e.getSupportType().equals(SupportType.ARBITRATION))
.collect(Collectors.toList());
list.forEach(e -> {
checkArgument(e.getSupportType().equals(SupportType.ARBITRATION), "Support type has to be ARBITRATION");
e.setStorage(storage);
});
return new ArbitrationDisputeList(storage, list);
return new ArbitrationDisputeList(list);
}
}

View file

@ -19,7 +19,7 @@ package bisq.core.support.dispute.arbitration;
import bisq.core.support.dispute.DisputeListService;
import bisq.common.storage.Storage;
import bisq.common.persistence.PersistenceManager;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -32,8 +32,8 @@ public final class ArbitrationDisputeListService extends DisputeListService<Arbi
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public ArbitrationDisputeListService(Storage<ArbitrationDisputeList> storage) {
super(storage);
public ArbitrationDisputeListService(PersistenceManager<ArbitrationDisputeList> persistenceManager) {
super(persistenceManager);
}
@ -43,6 +43,11 @@ public final class ArbitrationDisputeListService extends DisputeListService<Arbi
@Override
protected ArbitrationDisputeList getConcreteDisputeList() {
return new ArbitrationDisputeList(storage);
return new ArbitrationDisputeList();
}
@Override
protected String getFileName() {
return "DisputeList";
}
}

View file

@ -18,11 +18,11 @@
package bisq.core.support.dispute.mediation;
import bisq.core.proto.CoreProtoResolver;
import bisq.core.support.SupportType;
import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.DisputeList;
import bisq.common.proto.ProtoUtil;
import bisq.common.storage.Storage;
import com.google.protobuf.Message;
@ -41,18 +41,10 @@ import lombok.extern.slf4j.Slf4j;
* Calls to the List are delegated because this class intercepts the add/remove calls so changes
* can be saved to disc.
*/
public final class MediationDisputeList extends DisputeList<MediationDisputeList> {
public final class MediationDisputeList extends DisputeList<Dispute> {
MediationDisputeList(Storage<MediationDisputeList> storage) {
super(storage);
}
@Override
public void readPersisted() {
MediationDisputeList persisted = storage.initAndGetPersisted(this, "MediationDisputeList", 0);
if (persisted != null) {
list.addAll(persisted.getList());
}
MediationDisputeList() {
super();
}
@ -60,23 +52,22 @@ public final class MediationDisputeList extends DisputeList<MediationDisputeList
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private MediationDisputeList(Storage<MediationDisputeList> storage, List<Dispute> list) {
super(storage, list);
private MediationDisputeList(List<Dispute> list) {
super(list);
}
@Override
public Message toProtoMessage() {
return protobuf.PersistableEnvelope.newBuilder().setMediationDisputeList(protobuf.MediationDisputeList.newBuilder()
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list), protobuf.Dispute.class))).build();
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(getList()), protobuf.Dispute.class))).build();
}
public static MediationDisputeList fromProto(protobuf.MediationDisputeList proto,
CoreProtoResolver coreProtoResolver,
Storage<MediationDisputeList> storage) {
CoreProtoResolver coreProtoResolver) {
List<Dispute> list = proto.getDisputeList().stream()
.map(disputeProto -> Dispute.fromProto(disputeProto, coreProtoResolver))
.filter(e -> e.getSupportType().equals(SupportType.MEDIATION))
.collect(Collectors.toList());
list.forEach(e -> e.setStorage(storage));
return new MediationDisputeList(storage, list);
return new MediationDisputeList(list);
}
}

View file

@ -19,7 +19,7 @@ package bisq.core.support.dispute.mediation;
import bisq.core.support.dispute.DisputeListService;
import bisq.common.storage.Storage;
import bisq.common.persistence.PersistenceManager;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -32,8 +32,8 @@ public final class MediationDisputeListService extends DisputeListService<Mediat
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public MediationDisputeListService(Storage<MediationDisputeList> storage) {
super(storage);
public MediationDisputeListService(PersistenceManager<MediationDisputeList> persistenceManager) {
super(persistenceManager);
}
@ -43,6 +43,6 @@ public final class MediationDisputeListService extends DisputeListService<Mediat
@Override
protected MediationDisputeList getConcreteDisputeList() {
return new MediationDisputeList(storage);
return new MediationDisputeList();
}
}

View file

@ -23,7 +23,6 @@ import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.DisputeList;
import bisq.common.proto.ProtoUtil;
import bisq.common.storage.Storage;
import com.google.protobuf.Message;
@ -44,19 +43,10 @@ import static com.google.common.base.Preconditions.checkArgument;
* Calls to the List are delegated because this class intercepts the add/remove calls so changes
* can be saved to disc.
*/
public final class RefundDisputeList extends DisputeList<RefundDisputeList> {
public final class RefundDisputeList extends DisputeList<Dispute> {
RefundDisputeList(Storage<RefundDisputeList> storage) {
super(storage);
}
@Override
public void readPersisted() {
// We need to use DisputeList as file name to not lose existing disputes which are stored in the DisputeList file
RefundDisputeList persisted = storage.initAndGetPersisted(this, "RefundDisputeList", 50);
if (persisted != null) {
list.addAll(persisted.getList());
}
RefundDisputeList() {
super();
}
@ -64,30 +54,24 @@ public final class RefundDisputeList extends DisputeList<RefundDisputeList> {
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private RefundDisputeList(Storage<RefundDisputeList> storage, List<Dispute> list) {
super(storage, list);
private RefundDisputeList(List<Dispute> list) {
super(list);
}
@Override
public Message toProtoMessage() {
list.forEach(dispute -> checkArgument(dispute.getSupportType().equals(SupportType.REFUND), "Support type has to be REFUND"));
forEach(dispute -> checkArgument(dispute.getSupportType().equals(SupportType.REFUND), "Support type has to be REFUND"));
return protobuf.PersistableEnvelope.newBuilder().setRefundDisputeList(protobuf.RefundDisputeList.newBuilder()
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list), protobuf.Dispute.class))).build();
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(getList()), protobuf.Dispute.class))).build();
}
public static RefundDisputeList fromProto(protobuf.RefundDisputeList proto,
CoreProtoResolver coreProtoResolver,
Storage<RefundDisputeList> storage) {
CoreProtoResolver coreProtoResolver) {
List<Dispute> list = proto.getDisputeList().stream()
.map(disputeProto -> Dispute.fromProto(disputeProto, coreProtoResolver))
.filter(e -> e.getSupportType().equals(SupportType.REFUND))
.collect(Collectors.toList());
list.forEach(e -> {
checkArgument(e.getSupportType().equals(SupportType.REFUND), "Support type has to be REFUND");
e.setStorage(storage);
});
return new RefundDisputeList(storage, list);
return new RefundDisputeList(list);
}
}

View file

@ -19,7 +19,7 @@ package bisq.core.support.dispute.refund;
import bisq.core.support.dispute.DisputeListService;
import bisq.common.storage.Storage;
import bisq.common.persistence.PersistenceManager;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -32,8 +32,8 @@ public final class RefundDisputeListService extends DisputeListService<RefundDis
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public RefundDisputeListService(Storage<RefundDisputeList> storage) {
super(storage);
public RefundDisputeListService(PersistenceManager<RefundDisputeList> persistenceManager) {
super(persistenceManager);
}
@ -43,6 +43,6 @@ public final class RefundDisputeListService extends DisputeListService<RefundDis
@Override
protected RefundDisputeList getConcreteDisputeList() {
return new RefundDisputeList(storage);
return new RefundDisputeList();
}
}