Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inject CorruptedDataFilesHandler instead of making it static #3107

Merged
merged 7 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions common/src/main/java/bisq/common/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public class Storage<T extends PersistableEnvelope> {
private static final Logger log = LoggerFactory.getLogger(Storage.class);
public static final String STORAGE_DIR = "storageDir";

private static CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;

public static void setCorruptedDatabaseFilesHandler(CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
Storage.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
}
private final CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;

private final File dir;
private FileManager<T> fileManager;
Expand All @@ -72,9 +68,12 @@ public static void setCorruptedDatabaseFilesHandler(CorruptedDatabaseFilesHandle
///////////////////////////////////////////////////////////////////////////////////////////

@Inject
public Storage(@Named(STORAGE_DIR) File dir, PersistenceProtoResolver persistenceProtoResolver) {
public Storage(@Named(STORAGE_DIR) File dir,
PersistenceProtoResolver persistenceProtoResolver,
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
this.dir = dir;
this.persistenceProtoResolver = persistenceProtoResolver;
this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
}

@Nullable
Expand Down
9 changes: 0 additions & 9 deletions core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import bisq.common.handlers.ResultHandler;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.setup.GracefulShutDownHandler;
import bisq.common.storage.CorruptedDatabaseFilesHandler;
import bisq.common.storage.Storage;

import org.springframework.core.env.JOptCommandLinePropertySource;

Expand Down Expand Up @@ -232,8 +230,6 @@ protected Injector getInjector() {
protected void applyInjector() {
setupDevEnv();

setCorruptedDataBaseFilesHandler();

setupPersistedDataHosts(injector);
}

Expand All @@ -242,11 +238,6 @@ protected void setupDevEnv() {
DevEnv.setDaoActivated(BisqEnvironment.isDaoActivated(bisqEnvironment));
}

private void setCorruptedDataBaseFilesHandler() {
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler = injector.getInstance(CorruptedDatabaseFilesHandler.class);
Storage.setCorruptedDatabaseFilesHandler(corruptedDatabaseFilesHandler);
}

protected void setupPersistedDataHosts(Injector injector) {
try {
PersistedDataHost.apply(CorePersistedDataHost.getPersistedDataHosts(injector));
Expand Down
29 changes: 16 additions & 13 deletions core/src/main/java/bisq/core/arbitration/DisputeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import bisq.common.handlers.ResultHandler;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.Storage;
import bisq.common.util.Tuple2;

Expand All @@ -66,8 +65,6 @@

import com.google.inject.Inject;

import javax.inject.Named;

import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;

Expand All @@ -77,8 +74,6 @@
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;

import java.io.File;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -136,8 +131,7 @@ public DisputeManager(P2PService p2PService,
ClosedTradableManager closedTradableManager,
OpenOfferManager openOfferManager,
KeyRing keyRing,
PersistenceProtoResolver persistenceProtoResolver,
@Named(Storage.STORAGE_DIR) File storageDir) {
Storage<DisputeList> storage) {
this.p2PService = p2PService;
this.tradeWalletService = tradeWalletService;
this.walletService = walletService;
Expand All @@ -147,7 +141,7 @@ public DisputeManager(P2PService p2PService,
this.openOfferManager = openOfferManager;
this.keyRing = keyRing;

disputeStorage = new Storage<>(storageDir, persistenceProtoResolver);
disputeStorage = storage;

openDisputes = new HashMap<>();
closedDisputes = new HashMap<>();
Expand Down Expand Up @@ -207,7 +201,8 @@ public void onUpdatedDataReceived() {
onDisputesChangeListener(disputes.getList(), null);
}

private void onDisputesChangeListener(List<? extends Dispute> addedList, @Nullable List<? extends Dispute> removedList) {
private void onDisputesChangeListener(List<? extends Dispute> addedList,
@Nullable List<? extends Dispute> removedList) {
if (removedList != null) {
removedList.forEach(dispute -> {
String id = dispute.getId();
Expand Down Expand Up @@ -295,7 +290,8 @@ private void applyMessages() {
decryptedMailboxMessageWithPubKeys.clear();
}

private void processAckMessage(AckMessage ackMessage, @Nullable DecryptedMessageWithPubKey decryptedMessageWithPubKey) {
private void processAckMessage(AckMessage ackMessage,
@Nullable DecryptedMessageWithPubKey decryptedMessageWithPubKey) {
if (ackMessage.getSourceType() == AckMessageSourceType.DISPUTE_MESSAGE) {
if (ackMessage.isSuccess()) {
log.info("Received AckMessage for {} with tradeId {} and uid {}",
Expand Down Expand Up @@ -339,7 +335,10 @@ else if (message instanceof PeerPublishedDisputePayoutTxMessage)
log.warn("Unsupported message at dispatchMessage.\nmessage=" + message);
}

public void sendOpenNewDisputeMessage(Dispute dispute, boolean reOpen, ResultHandler resultHandler, FaultHandler faultHandler) {
public void sendOpenNewDisputeMessage(Dispute dispute,
boolean reOpen,
ResultHandler resultHandler,
FaultHandler faultHandler) {
if (!disputes.contains(dispute)) {
final Optional<Dispute> storedDisputeOptional = findDispute(dispute.getTradeId(), dispute.getTraderId());
if (!storedDisputeOptional.isPresent() || reOpen) {
Expand Down Expand Up @@ -433,7 +432,9 @@ public void onFault(String errorMessage) {
}

// arbitrator sends that to trading peer when he received openDispute request
private String sendPeerOpenedDisputeMessage(Dispute disputeFromOpener, Contract contractFromOpener, PubKeyRing pubKeyRing) {
private String sendPeerOpenedDisputeMessage(Dispute disputeFromOpener,
Contract contractFromOpener,
PubKeyRing pubKeyRing) {
Dispute dispute = new Dispute(
disputeStorage,
disputeFromOpener.getTradeId(),
Expand Down Expand Up @@ -539,7 +540,9 @@ public void onFault(String errorMessage) {
}

// traders send msg to the arbitrator or arbitrator to 1 trader (trader to trader is not allowed)
public DisputeCommunicationMessage sendDisputeDirectMessage(Dispute dispute, String text, ArrayList<Attachment> attachments) {
public DisputeCommunicationMessage sendDisputeDirectMessage(Dispute dispute,
String text,
ArrayList<Attachment> attachments) {
DisputeCommunicationMessage message = new DisputeCommunicationMessage(
dispute.getTradeId(),
dispute.getTraderPubKeyRing().hashCode(),
Expand Down
9 changes: 2 additions & 7 deletions core/src/main/java/bisq/core/offer/OpenOfferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,14 @@
import bisq.common.handlers.ResultHandler;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.Storage;

import org.bitcoinj.core.Coin;

import javax.inject.Inject;
import javax.inject.Named;

import javafx.collections.ObservableList;

import java.io.File;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -127,10 +123,9 @@ public OpenOfferManager(KeyRing keyRing,
ClosedTradableManager closedTradableManager,
PriceFeedService priceFeedService,
Preferences preferences,
PersistenceProtoResolver persistenceProtoResolver,
TradeStatisticsManager tradeStatisticsManager,
ArbitratorManager arbitratorManager,
@Named(Storage.STORAGE_DIR) File storageDir) {
Storage<TradableList<OpenOffer>> storage) {
this.keyRing = keyRing;
this.user = user;
this.p2PService = p2PService;
Expand All @@ -144,7 +139,7 @@ public OpenOfferManager(KeyRing keyRing,
this.tradeStatisticsManager = tradeStatisticsManager;
this.arbitratorManager = arbitratorManager;

openOfferTradableListStorage = new Storage<>(storageDir, persistenceProtoResolver);
openOfferTradableListStorage = storage;

// In case the app did get killed the shutDown from the modules is not called, so we use a shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import bisq.common.proto.persistable.NavigationPath;
import bisq.common.proto.persistable.PersistableEnvelope;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.CorruptedDatabaseFilesHandler;
import bisq.common.storage.Storage;

import com.google.inject.Provider;
Expand All @@ -69,15 +70,18 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
private final Provider<BtcWalletService> btcWalletService;
private final NetworkProtoResolver networkProtoResolver;
private final File storageDir;
private final CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;

@Inject
public CorePersistenceProtoResolver(Provider<BtcWalletService> btcWalletService,
NetworkProtoResolver networkProtoResolver,
@Named(Storage.STORAGE_DIR) File storageDir) {
@Named(Storage.STORAGE_DIR) File storageDir,
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
this.btcWalletService = btcWalletService;
this.networkProtoResolver = networkProtoResolver;
this.storageDir = storageDir;

this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
}

@Override
Expand All @@ -93,14 +97,14 @@ public PersistableEnvelope fromProto(protobuf.PersistableEnvelope proto) {
case TRADABLE_LIST:
return TradableList.fromProto(proto.getTradableList(),
this,
new Storage<>(storageDir, this),
new Storage<>(storageDir, this, corruptedDatabaseFilesHandler),
btcWalletService.get());
case TRADE_STATISTICS_LIST:
throw new ProtobufferRuntimeException("TRADE_STATISTICS_LIST is not used anymore");
case DISPUTE_LIST:
return DisputeList.fromProto(proto.getDisputeList(),
this,
new Storage<>(storageDir, this));
new Storage<>(storageDir, this, corruptedDatabaseFilesHandler));
case PREFERENCES_PAYLOAD:
return PreferencesPayload.fromProto(proto.getPreferencesPayload(), this);
case USER_PAYLOAD:
Expand Down
9 changes: 2 additions & 7 deletions core/src/main/java/bisq/core/trade/TradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import bisq.common.handlers.ResultHandler;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.Storage;

import org.bitcoinj.core.AddressFormatException;
Expand All @@ -64,7 +63,6 @@
import org.bitcoinj.core.Transaction;

import javax.inject.Inject;
import javax.inject.Named;

import com.google.common.util.concurrent.FutureCallback;

Expand All @@ -78,8 +76,6 @@

import org.spongycastle.crypto.params.KeyParameter;

import java.io.File;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -148,11 +144,10 @@ public TradeManager(User user,
FilterManager filterManager,
TradeStatisticsManager tradeStatisticsManager,
ReferralIdService referralIdService,
PersistenceProtoResolver persistenceProtoResolver,
AccountAgeWitnessService accountAgeWitnessService,
ArbitratorManager arbitratorManager,
ClockWatcher clockWatcher,
@Named(Storage.STORAGE_DIR) File storageDir) {
Storage<TradableList<Trade>> storage) {
this.user = user;
this.keyRing = keyRing;
this.btcWalletService = btcWalletService;
Expand All @@ -170,7 +165,7 @@ public TradeManager(User user,
this.arbitratorManager = arbitratorManager;
this.clockWatcher = clockWatcher;

tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver);
tradableListStorage = storage;

p2PService.addDecryptedDirectMessageListener((decryptedMessageWithPubKey, peerNodeAddress) -> {
NetworkEnvelope networkEnvelope = decryptedMessageWithPubKey.getNetworkEnvelope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@

import bisq.common.crypto.KeyRing;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.Storage;

import com.google.inject.Inject;

import javax.inject.Named;

import com.google.common.collect.ImmutableList;

import javafx.collections.ObservableList;

import java.io.File;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand All @@ -52,14 +47,14 @@ public class ClosedTradableManager implements PersistedDataHost {
private final BtcWalletService btcWalletService;

@Inject
public ClosedTradableManager(KeyRing keyRing, PriceFeedService priceFeedService,
PersistenceProtoResolver persistenceProtoResolver,
public ClosedTradableManager(KeyRing keyRing,
PriceFeedService priceFeedService,
BtcWalletService btcWalletService,
@Named(Storage.STORAGE_DIR) File storageDir) {
Storage<TradableList<Tradable>> storage) {
this.keyRing = keyRing;
this.priceFeedService = priceFeedService;
this.btcWalletService = btcWalletService;
tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver);
tradableListStorage = storage;
// The ClosedTrades object can become a few MB so we don't keep so many backups
tradableListStorage.setNumMaxBackupFiles(3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@

import bisq.common.crypto.KeyRing;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.Storage;

import com.google.inject.Inject;

import javax.inject.Named;

import javafx.collections.ObservableList;

import java.io.File;

import java.util.Optional;
import java.util.stream.Stream;

Expand All @@ -51,14 +46,14 @@ public class FailedTradesManager implements PersistedDataHost {
private final Storage<TradableList<Trade>> tradableListStorage;

@Inject
public FailedTradesManager(KeyRing keyRing, PriceFeedService priceFeedService,
PersistenceProtoResolver persistenceProtoResolver,
public FailedTradesManager(KeyRing keyRing,
PriceFeedService priceFeedService,
BtcWalletService btcWalletService,
@Named(Storage.STORAGE_DIR) File storageDir) {
Storage<TradableList<Trade>> storage) {
this.keyRing = keyRing;
this.priceFeedService = priceFeedService;
this.btcWalletService = btcWalletService;
tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver);
tradableListStorage = storage;

}

Expand Down
Loading