From a4e8ec5ebf5cae75db9548080bffc1cc8fddfad8 Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Tue, 6 Aug 2019 18:32:00 +0200 Subject: [PATCH 1/5] convert some of the core config --- core/src/main/java/bisq/core/CoreModule.java | 12 ------------ core/src/main/java/bisq/core/app/BisqSetup.java | 2 ++ .../src/main/java/bisq/core/app/P2PNetworkSetup.java | 2 ++ core/src/main/java/bisq/core/app/TorSetup.java | 2 ++ core/src/main/java/bisq/core/app/WalletAppSetup.java | 2 ++ .../src/main/java/bisq/core/payment/TradeLimits.java | 2 ++ .../src/test/java/bisq/desktop/GuiceSetupTest.java | 12 ++++++++++++ 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/bisq/core/CoreModule.java b/core/src/main/java/bisq/core/CoreModule.java index fa4d8795155..0ebac0edf67 100644 --- a/core/src/main/java/bisq/core/CoreModule.java +++ b/core/src/main/java/bisq/core/CoreModule.java @@ -21,10 +21,6 @@ import bisq.core.app.AppOptionKeys; import bisq.core.app.AvoidStandbyModeService; import bisq.core.app.BisqEnvironment; -import bisq.core.app.BisqSetup; -import bisq.core.app.P2PNetworkSetup; -import bisq.core.app.TorSetup; -import bisq.core.app.WalletAppSetup; import bisq.core.arbitration.ArbitratorModule; import bisq.core.btc.BitcoinModule; import bisq.core.dao.DaoModule; @@ -40,7 +36,6 @@ import bisq.core.notifications.alerts.market.MarketAlerts; import bisq.core.notifications.alerts.price.PriceAlert; import bisq.core.offer.OfferModule; -import bisq.core.payment.TradeLimits; import bisq.core.presentation.CorePresentationModule; import bisq.core.proto.network.CoreNetworkProtoResolver; import bisq.core.proto.persistable.CorePersistenceProtoResolver; @@ -80,15 +75,8 @@ public CoreModule(Environment environment) { @Override protected void configure() { - bind(BisqSetup.class).in(Singleton.class); - bind(TorSetup.class).in(Singleton.class); - bind(P2PNetworkSetup.class).in(Singleton.class); - bind(WalletAppSetup.class).in(Singleton.class); - bind(BisqEnvironment.class).toInstance((BisqEnvironment) environment); - bind(TradeLimits.class).in(Singleton.class); - bind(KeyStorage.class).in(Singleton.class); bind(KeyRing.class).in(Singleton.class); bind(User.class).in(Singleton.class); diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index d59dbd89bd7..f4c2b66839c 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -72,6 +72,7 @@ import org.bitcoinj.core.Coin; import javax.inject.Inject; +import javax.inject.Singleton; import com.google.common.net.InetAddresses; @@ -109,6 +110,7 @@ import javax.annotation.Nullable; @Slf4j +@Singleton public class BisqSetup { public interface BisqSetupCompleteListener { void onSetupComplete(); diff --git a/core/src/main/java/bisq/core/app/P2PNetworkSetup.java b/core/src/main/java/bisq/core/app/P2PNetworkSetup.java index cbcda4bb3af..76527919dc4 100644 --- a/core/src/main/java/bisq/core/app/P2PNetworkSetup.java +++ b/core/src/main/java/bisq/core/app/P2PNetworkSetup.java @@ -28,6 +28,7 @@ import bisq.network.p2p.network.ConnectionListener; import javax.inject.Inject; +import javax.inject.Singleton; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.monadic.MonadicBinding; @@ -44,6 +45,7 @@ import javax.annotation.Nullable; +@Singleton @Slf4j public class P2PNetworkSetup { private final PriceFeedService priceFeedService; diff --git a/core/src/main/java/bisq/core/app/TorSetup.java b/core/src/main/java/bisq/core/app/TorSetup.java index 238e23e97a4..669f570ee1c 100644 --- a/core/src/main/java/bisq/core/app/TorSetup.java +++ b/core/src/main/java/bisq/core/app/TorSetup.java @@ -25,6 +25,7 @@ import com.google.inject.name.Named; import javax.inject.Inject; +import javax.inject.Singleton; import java.nio.file.Paths; @@ -36,6 +37,7 @@ import javax.annotation.Nullable; @Slf4j +@Singleton public class TorSetup { private File torDir; diff --git a/core/src/main/java/bisq/core/app/WalletAppSetup.java b/core/src/main/java/bisq/core/app/WalletAppSetup.java index e89df28ab85..f9ad67f2fd8 100644 --- a/core/src/main/java/bisq/core/app/WalletAppSetup.java +++ b/core/src/main/java/bisq/core/app/WalletAppSetup.java @@ -28,6 +28,7 @@ import org.bitcoinj.store.ChainFileLockedException; import javax.inject.Inject; +import javax.inject.Singleton; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.monadic.MonadicBinding; @@ -50,6 +51,7 @@ import javax.annotation.Nullable; @Slf4j +@Singleton public class WalletAppSetup { private final WalletsManager walletsManager; private final WalletsSetup walletsSetup; diff --git a/core/src/main/java/bisq/core/payment/TradeLimits.java b/core/src/main/java/bisq/core/payment/TradeLimits.java index 78edb3a944b..62e825e3eee 100644 --- a/core/src/main/java/bisq/core/payment/TradeLimits.java +++ b/core/src/main/java/bisq/core/payment/TradeLimits.java @@ -26,6 +26,7 @@ import org.bitcoinj.core.Coin; import javax.inject.Inject; +import javax.inject.Singleton; import com.google.common.annotations.VisibleForTesting; @@ -35,6 +36,7 @@ import javax.annotation.Nullable; @Slf4j +@Singleton public class TradeLimits { @Nullable @Getter diff --git a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java index 109df3e37be..85a94e82797 100644 --- a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java +++ b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java @@ -18,8 +18,12 @@ import bisq.core.app.AvoidStandbyModeService; import bisq.core.app.BisqEnvironment; +import bisq.core.app.P2PNetworkSetup; +import bisq.core.app.TorSetup; +import bisq.core.app.WalletAppSetup; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; +import bisq.core.payment.TradeLimits; import bisq.core.util.BSFormatter; import bisq.core.util.BsqFormatter; @@ -48,6 +52,7 @@ public void setUp() { @Test public void testGuiceSetup() { injector.getInstance(AvoidStandbyModeService.class); + // desktop module assertSingleton(OfferBook.class); assertSingleton(CachingViewLoader.class); assertSingleton(Navigation.class); @@ -65,6 +70,13 @@ public void testGuiceSetup() { assertSingleton(TransactionAwareTradableFactory.class); assertSingleton(DisplayedTransactionsFactory.class); assertSingleton(BondingViewUtils.class); + + // core module +// assertSingleton(BisqSetup.class); // this is a can of worms + assertSingleton(TorSetup.class); + assertSingleton(P2PNetworkSetup.class); + assertSingleton(WalletAppSetup.class); + assertSingleton(TradeLimits.class); } private void assertSingleton(Class type) { From 3f097ebf636cfb004f735b3fb0cbe2d681de3489 Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Tue, 6 Aug 2019 18:34:33 +0200 Subject: [PATCH 2/5] more singletoning --- common/src/main/java/bisq/common/crypto/KeyRing.java | 2 ++ common/src/main/java/bisq/common/crypto/KeyStorage.java | 2 ++ core/src/main/java/bisq/core/CoreModule.java | 5 ----- core/src/main/java/bisq/core/user/User.java | 2 ++ desktop/src/test/java/bisq/desktop/GuiceSetupTest.java | 7 +++++++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/bisq/common/crypto/KeyRing.java b/common/src/main/java/bisq/common/crypto/KeyRing.java index 4dab6ad3ac6..7f965d702ae 100644 --- a/common/src/main/java/bisq/common/crypto/KeyRing.java +++ b/common/src/main/java/bisq/common/crypto/KeyRing.java @@ -18,6 +18,7 @@ package bisq.common.crypto; import javax.inject.Inject; +import javax.inject.Singleton; import org.bouncycastle.openpgp.PGPKeyPair; import org.bouncycastle.openpgp.PGPPublicKey; @@ -34,6 +35,7 @@ @Getter @EqualsAndHashCode @Slf4j +@Singleton public class KeyRing { private final KeyPair signatureKeyPair; private final KeyPair encryptionKeyPair; diff --git a/common/src/main/java/bisq/common/crypto/KeyStorage.java b/common/src/main/java/bisq/common/crypto/KeyStorage.java index 5a8d271acfe..82274c34d20 100644 --- a/common/src/main/java/bisq/common/crypto/KeyStorage.java +++ b/common/src/main/java/bisq/common/crypto/KeyStorage.java @@ -22,6 +22,7 @@ import com.google.inject.Inject; import javax.inject.Named; +import javax.inject.Singleton; import org.bouncycastle.openpgp.PGPKeyPair; @@ -56,6 +57,7 @@ import javax.annotation.Nullable; // TODO: use a password protection for key storage +@Singleton public class KeyStorage { private static final Logger log = LoggerFactory.getLogger(KeyStorage.class); diff --git a/core/src/main/java/bisq/core/CoreModule.java b/core/src/main/java/bisq/core/CoreModule.java index 0ebac0edf67..e534937957c 100644 --- a/core/src/main/java/bisq/core/CoreModule.java +++ b/core/src/main/java/bisq/core/CoreModule.java @@ -41,7 +41,6 @@ import bisq.core.proto.persistable.CorePersistenceProtoResolver; import bisq.core.trade.TradeModule; import bisq.core.user.Preferences; -import bisq.core.user.User; import bisq.network.crypto.EncryptionServiceModule; import bisq.network.p2p.P2PModule; @@ -51,7 +50,6 @@ import bisq.common.ClockWatcher; import bisq.common.CommonOptionKeys; import bisq.common.app.AppModule; -import bisq.common.crypto.KeyRing; import bisq.common.crypto.KeyStorage; import bisq.common.proto.network.NetworkProtoResolver; import bisq.common.proto.persistable.PersistenceProtoResolver; @@ -77,9 +75,6 @@ public CoreModule(Environment environment) { protected void configure() { bind(BisqEnvironment.class).toInstance((BisqEnvironment) environment); - bind(KeyStorage.class).in(Singleton.class); - bind(KeyRing.class).in(Singleton.class); - bind(User.class).in(Singleton.class); bind(ClockWatcher.class).in(Singleton.class); bind(Preferences.class).in(Singleton.class); bind(BridgeAddressProvider.class).to(Preferences.class).in(Singleton.class); diff --git a/core/src/main/java/bisq/core/user/User.java b/core/src/main/java/bisq/core/user/User.java index 05b99b0fe21..af8637efaae 100644 --- a/core/src/main/java/bisq/core/user/User.java +++ b/core/src/main/java/bisq/core/user/User.java @@ -34,6 +34,7 @@ import bisq.common.storage.Storage; import javax.inject.Inject; +import javax.inject.Singleton; import javafx.beans.property.ObjectProperty; import javafx.beans.property.ReadOnlyObjectProperty; @@ -64,6 +65,7 @@ */ @Slf4j @AllArgsConstructor +@Singleton public class User implements PersistedDataHost { final private Storage storage; final private KeyRing keyRing; diff --git a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java index 85a94e82797..110a480f201 100644 --- a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java +++ b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java @@ -24,9 +24,13 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.TradeLimits; +import bisq.core.user.User; import bisq.core.util.BSFormatter; import bisq.core.util.BsqFormatter; +import bisq.common.crypto.KeyRing; +import bisq.common.crypto.KeyStorage; + import org.springframework.mock.env.MockPropertySource; import com.google.inject.Guice; @@ -77,6 +81,9 @@ public void testGuiceSetup() { assertSingleton(P2PNetworkSetup.class); assertSingleton(WalletAppSetup.class); assertSingleton(TradeLimits.class); + assertSingleton(KeyStorage.class); + assertSingleton(KeyRing.class); + assertSingleton(User.class); } private void assertSingleton(Class type) { From 75008874845cd149df46df81a245341a32d4f5bb Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Tue, 6 Aug 2019 18:41:23 +0200 Subject: [PATCH 3/5] even more singletoning --- .../src/main/java/bisq/common/ClockWatcher.java | 3 +++ .../storage/CorruptedDatabaseFilesHandler.java | 2 ++ core/src/main/java/bisq/core/CoreModule.java | 11 ++--------- .../bisq/core/app/AvoidStandbyModeService.java | 2 ++ .../p2p/seed/DefaultSeedNodeRepository.java | 2 ++ .../main/java/bisq/core/user/Preferences.java | 4 +++- .../test/java/bisq/desktop/GuiceSetupTest.java | 16 +++++++++++++++- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/bisq/common/ClockWatcher.java b/common/src/main/java/bisq/common/ClockWatcher.java index 0ca0a3423b6..1b673535fad 100644 --- a/common/src/main/java/bisq/common/ClockWatcher.java +++ b/common/src/main/java/bisq/common/ClockWatcher.java @@ -17,6 +17,8 @@ package bisq.common; +import javax.inject.Singleton; + import java.util.LinkedList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -26,6 +28,7 @@ // Helps configure listener objects that are run by the `UserThread` each second // and can do per second, per minute and delayed second actions. Also detects when we were in standby, and logs it. @Slf4j +@Singleton public class ClockWatcher { public static final int IDLE_TOLERANCE_MS = 20000; diff --git a/common/src/main/java/bisq/common/storage/CorruptedDatabaseFilesHandler.java b/common/src/main/java/bisq/common/storage/CorruptedDatabaseFilesHandler.java index f33d8ac4bca..ac967604519 100644 --- a/common/src/main/java/bisq/common/storage/CorruptedDatabaseFilesHandler.java +++ b/common/src/main/java/bisq/common/storage/CorruptedDatabaseFilesHandler.java @@ -18,6 +18,7 @@ package bisq.common.storage; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.ArrayList; import java.util.List; @@ -26,6 +27,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j +@Singleton public class CorruptedDatabaseFilesHandler { private List corruptedDatabaseFiles = new ArrayList<>(); diff --git a/core/src/main/java/bisq/core/CoreModule.java b/core/src/main/java/bisq/core/CoreModule.java index e534937957c..df5d6b856a7 100644 --- a/core/src/main/java/bisq/core/CoreModule.java +++ b/core/src/main/java/bisq/core/CoreModule.java @@ -19,7 +19,6 @@ import bisq.core.alert.AlertModule; import bisq.core.app.AppOptionKeys; -import bisq.core.app.AvoidStandbyModeService; import bisq.core.app.BisqEnvironment; import bisq.core.arbitration.ArbitratorModule; import bisq.core.btc.BitcoinModule; @@ -47,13 +46,11 @@ import bisq.network.p2p.network.BridgeAddressProvider; import bisq.network.p2p.seed.SeedNodeRepository; -import bisq.common.ClockWatcher; import bisq.common.CommonOptionKeys; import bisq.common.app.AppModule; import bisq.common.crypto.KeyStorage; import bisq.common.proto.network.NetworkProtoResolver; import bisq.common.proto.persistable.PersistenceProtoResolver; -import bisq.common.storage.CorruptedDatabaseFilesHandler; import bisq.common.storage.Storage; import org.springframework.core.env.Environment; @@ -75,13 +72,9 @@ public CoreModule(Environment environment) { protected void configure() { bind(BisqEnvironment.class).toInstance((BisqEnvironment) environment); - bind(ClockWatcher.class).in(Singleton.class); - bind(Preferences.class).in(Singleton.class); - bind(BridgeAddressProvider.class).to(Preferences.class).in(Singleton.class); - bind(CorruptedDatabaseFilesHandler.class).in(Singleton.class); - bind(AvoidStandbyModeService.class).in(Singleton.class); + bind(BridgeAddressProvider.class).to(Preferences.class); - bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class).in(Singleton.class); + bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class); File storageDir = new File(environment.getRequiredProperty(Storage.STORAGE_DIR)); bind(File.class).annotatedWith(named(Storage.STORAGE_DIR)).toInstance(storageDir); diff --git a/core/src/main/java/bisq/core/app/AvoidStandbyModeService.java b/core/src/main/java/bisq/core/app/AvoidStandbyModeService.java index 36badeaecd5..bf9a733718e 100644 --- a/core/src/main/java/bisq/core/app/AvoidStandbyModeService.java +++ b/core/src/main/java/bisq/core/app/AvoidStandbyModeService.java @@ -20,6 +20,7 @@ import bisq.core.user.Preferences; import javax.inject.Inject; +import javax.inject.Singleton; import org.apache.commons.io.IOUtils; @@ -40,6 +41,7 @@ import javax.sound.sampled.SourceDataLine; @Slf4j +@Singleton public class AvoidStandbyModeService { private final Preferences preferences; private volatile boolean isStopped; diff --git a/core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepository.java b/core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepository.java index 6b3a021789f..d8f4f039a14 100644 --- a/core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepository.java +++ b/core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepository.java @@ -25,6 +25,7 @@ import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Singleton; import java.io.BufferedReader; import java.io.InputStream; @@ -43,6 +44,7 @@ // If a new BaseCurrencyNetwork type gets added we need to add the resource file for it as well! @Slf4j +@Singleton public class DefaultSeedNodeRepository implements SeedNodeRepository { //TODO add support for localhost addresses private static final Pattern pattern = Pattern.compile("^([a-z0-9]+\\.onion:\\d+)"); diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index d8023c56098..52e96b90dad 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -32,8 +32,8 @@ import bisq.core.locale.GlobalSettings; import bisq.core.locale.TradeCurrency; import bisq.core.payment.PaymentAccount; -import bisq.core.setup.CoreNetworkCapabilities; import bisq.core.payment.PaymentAccountUtil; +import bisq.core.setup.CoreNetworkCapabilities; import bisq.network.p2p.network.BridgeAddressProvider; @@ -43,6 +43,7 @@ import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Singleton; import javafx.beans.property.BooleanProperty; import javafx.beans.property.LongProperty; @@ -74,6 +75,7 @@ import static com.google.common.base.Preconditions.checkNotNull; @Slf4j +@Singleton public final class Preferences implements PersistedDataHost, BridgeAddressProvider { private static final ArrayList BTC_MAIN_NET_EXPLORERS = new ArrayList<>(Arrays.asList( diff --git a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java index 110a480f201..c436271611d 100644 --- a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java +++ b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java @@ -23,13 +23,20 @@ import bisq.core.app.WalletAppSetup; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; +import bisq.core.network.p2p.seed.DefaultSeedNodeRepository; import bisq.core.payment.TradeLimits; +import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.BSFormatter; import bisq.core.util.BsqFormatter; +import bisq.network.p2p.network.BridgeAddressProvider; +import bisq.network.p2p.seed.SeedNodeRepository; + +import bisq.common.ClockWatcher; import bisq.common.crypto.KeyRing; import bisq.common.crypto.KeyStorage; +import bisq.common.storage.CorruptedDatabaseFilesHandler; import org.springframework.mock.env.MockPropertySource; @@ -84,9 +91,16 @@ public void testGuiceSetup() { assertSingleton(KeyStorage.class); assertSingleton(KeyRing.class); assertSingleton(User.class); + assertSingleton(ClockWatcher.class); + assertSingleton(Preferences.class); + assertSingleton(BridgeAddressProvider.class); + assertSingleton(CorruptedDatabaseFilesHandler.class); + assertSingleton(AvoidStandbyModeService.class); + assertSingleton(DefaultSeedNodeRepository.class); + assertSingleton(SeedNodeRepository.class); } - private void assertSingleton(Class type) { + private void assertSingleton(Class type) { assertSame(injector.getInstance(type), injector.getInstance(type)); } } From c6f07ed945c434507be54750188069f5d19c4f7a Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Tue, 6 Aug 2019 19:20:18 +0200 Subject: [PATCH 4/5] singletonify the rest of the core module --- core/src/main/java/bisq/core/CoreModule.java | 23 ++-------------- .../bisq/core/notifications/MobileModel.java | 2 ++ .../MobileNotificationService.java | 2 ++ .../MobileNotificationValidator.java | 2 ++ .../alerts/DisputeMsgEvents.java | 2 ++ .../alerts/MyOfferTakenEvents.java | 2 ++ .../notifications/alerts/TradeEvents.java | 2 ++ .../alerts/market/MarketAlerts.java | 2 ++ .../alerts/price/PriceAlert.java | 2 ++ .../network/CoreNetworkProtoResolver.java | 2 ++ .../CorePersistenceProtoResolver.java | 2 ++ .../java/bisq/desktop/GuiceSetupTest.java | 27 +++++++++++++++++++ 12 files changed, 49 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/bisq/core/CoreModule.java b/core/src/main/java/bisq/core/CoreModule.java index df5d6b856a7..adcbf3a163e 100644 --- a/core/src/main/java/bisq/core/CoreModule.java +++ b/core/src/main/java/bisq/core/CoreModule.java @@ -25,15 +25,6 @@ import bisq.core.dao.DaoModule; import bisq.core.filter.FilterModule; import bisq.core.network.p2p.seed.DefaultSeedNodeRepository; -import bisq.core.notifications.MobileMessageEncryption; -import bisq.core.notifications.MobileModel; -import bisq.core.notifications.MobileNotificationService; -import bisq.core.notifications.MobileNotificationValidator; -import bisq.core.notifications.alerts.DisputeMsgEvents; -import bisq.core.notifications.alerts.MyOfferTakenEvents; -import bisq.core.notifications.alerts.TradeEvents; -import bisq.core.notifications.alerts.market.MarketAlerts; -import bisq.core.notifications.alerts.price.PriceAlert; import bisq.core.offer.OfferModule; import bisq.core.presentation.CorePresentationModule; import bisq.core.proto.network.CoreNetworkProtoResolver; @@ -55,7 +46,6 @@ import org.springframework.core.env.Environment; -import com.google.inject.Singleton; import com.google.inject.name.Names; import java.io.File; @@ -82,8 +72,8 @@ protected void configure() { File keyStorageDir = new File(environment.getRequiredProperty(KeyStorage.KEY_STORAGE_DIR)); bind(File.class).annotatedWith(named(KeyStorage.KEY_STORAGE_DIR)).toInstance(keyStorageDir); - bind(NetworkProtoResolver.class).to(CoreNetworkProtoResolver.class).in(Singleton.class); - bind(PersistenceProtoResolver.class).to(CorePersistenceProtoResolver.class).in(Singleton.class); + bind(NetworkProtoResolver.class).to(CoreNetworkProtoResolver.class); + bind(PersistenceProtoResolver.class).to(CorePersistenceProtoResolver.class); Boolean useDevPrivilegeKeys = environment.getProperty(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS, Boolean.class, false); bind(boolean.class).annotatedWith(Names.named(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS)).toInstance(useDevPrivilegeKeys); @@ -94,15 +84,6 @@ protected void configure() { String referralId = environment.getProperty(AppOptionKeys.REFERRAL_ID, String.class, ""); bind(String.class).annotatedWith(Names.named(AppOptionKeys.REFERRAL_ID)).toInstance(referralId); - bind(MobileNotificationService.class).in(Singleton.class); - bind(MobileMessageEncryption.class).in(Singleton.class); - bind(MobileNotificationValidator.class).in(Singleton.class); - bind(MobileModel.class).in(Singleton.class); - bind(MyOfferTakenEvents.class).in(Singleton.class); - bind(TradeEvents.class).in(Singleton.class); - bind(DisputeMsgEvents.class).in(Singleton.class); - bind(PriceAlert.class).in(Singleton.class); - bind(MarketAlerts.class).in(Singleton.class); // ordering is used for shut down sequence install(tradeModule()); diff --git a/core/src/main/java/bisq/core/notifications/MobileModel.java b/core/src/main/java/bisq/core/notifications/MobileModel.java index ffd015afa0b..2c212e7e4e9 100644 --- a/core/src/main/java/bisq/core/notifications/MobileModel.java +++ b/core/src/main/java/bisq/core/notifications/MobileModel.java @@ -18,6 +18,7 @@ package bisq.core.notifications; import javax.inject.Inject; +import javax.inject.Singleton; import com.google.common.annotations.VisibleForTesting; @@ -29,6 +30,7 @@ @Data @Slf4j +@Singleton public class MobileModel { public static final String PHONE_SEPARATOR_ESCAPED = "\\|"; // see https://stackoverflow.com/questions/5675704/java-string-split-not-returning-the-right-values public static final String PHONE_SEPARATOR_WRITING = "|"; diff --git a/core/src/main/java/bisq/core/notifications/MobileNotificationService.java b/core/src/main/java/bisq/core/notifications/MobileNotificationService.java index 3b80e0f8940..e93845f0a44 100644 --- a/core/src/main/java/bisq/core/notifications/MobileNotificationService.java +++ b/core/src/main/java/bisq/core/notifications/MobileNotificationService.java @@ -29,6 +29,7 @@ import com.google.gson.Gson; import com.google.inject.Inject; +import com.google.inject.Singleton; import javax.inject.Named; @@ -54,6 +55,7 @@ import static com.google.common.base.Preconditions.checkNotNull; @Slf4j +@Singleton public class MobileNotificationService { // Used in Relay app to response of a success state. We won't want a code dependency just for that string so we keep it // duplicated in relay and here. Must not be changed. diff --git a/core/src/main/java/bisq/core/notifications/MobileNotificationValidator.java b/core/src/main/java/bisq/core/notifications/MobileNotificationValidator.java index 95eab45fff7..5cf6f2aeb51 100644 --- a/core/src/main/java/bisq/core/notifications/MobileNotificationValidator.java +++ b/core/src/main/java/bisq/core/notifications/MobileNotificationValidator.java @@ -18,10 +18,12 @@ package bisq.core.notifications; import javax.inject.Inject; +import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; @Slf4j +@Singleton public class MobileNotificationValidator { @Inject public MobileNotificationValidator() { diff --git a/core/src/main/java/bisq/core/notifications/alerts/DisputeMsgEvents.java b/core/src/main/java/bisq/core/notifications/alerts/DisputeMsgEvents.java index e989317f770..fc9f21e0aaf 100644 --- a/core/src/main/java/bisq/core/notifications/alerts/DisputeMsgEvents.java +++ b/core/src/main/java/bisq/core/notifications/alerts/DisputeMsgEvents.java @@ -28,6 +28,7 @@ import bisq.network.p2p.P2PService; import javax.inject.Inject; +import javax.inject.Singleton; import javafx.collections.ListChangeListener; @@ -36,6 +37,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j +@Singleton public class DisputeMsgEvents { private final P2PService p2PService; private final MobileNotificationService mobileNotificationService; diff --git a/core/src/main/java/bisq/core/notifications/alerts/MyOfferTakenEvents.java b/core/src/main/java/bisq/core/notifications/alerts/MyOfferTakenEvents.java index 2ed8a7ebb7f..842dbadacc4 100644 --- a/core/src/main/java/bisq/core/notifications/alerts/MyOfferTakenEvents.java +++ b/core/src/main/java/bisq/core/notifications/alerts/MyOfferTakenEvents.java @@ -25,6 +25,7 @@ import bisq.core.offer.OpenOfferManager; import javax.inject.Inject; +import javax.inject.Singleton; import javafx.collections.ListChangeListener; @@ -33,6 +34,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j +@Singleton public class MyOfferTakenEvents { private final OpenOfferManager openOfferManager; private final MobileNotificationService mobileNotificationService; diff --git a/core/src/main/java/bisq/core/notifications/alerts/TradeEvents.java b/core/src/main/java/bisq/core/notifications/alerts/TradeEvents.java index 43f51ec80e5..adef19d1b1c 100644 --- a/core/src/main/java/bisq/core/notifications/alerts/TradeEvents.java +++ b/core/src/main/java/bisq/core/notifications/alerts/TradeEvents.java @@ -28,6 +28,7 @@ import bisq.common.crypto.PubKeyRing; import javax.inject.Inject; +import javax.inject.Singleton; import javafx.collections.ListChangeListener; @@ -38,6 +39,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j +@Singleton public class TradeEvents { private final PubKeyRing pubKeyRing; private final TradeManager tradeManager; diff --git a/core/src/main/java/bisq/core/notifications/alerts/market/MarketAlerts.java b/core/src/main/java/bisq/core/notifications/alerts/market/MarketAlerts.java index ac2a70a4321..fad6fc2a2f1 100644 --- a/core/src/main/java/bisq/core/notifications/alerts/market/MarketAlerts.java +++ b/core/src/main/java/bisq/core/notifications/alerts/market/MarketAlerts.java @@ -38,6 +38,7 @@ import org.bitcoinj.utils.Fiat; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.List; import java.util.UUID; @@ -45,6 +46,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j +@Singleton public class MarketAlerts { private final OfferBookService offerBookService; private final MobileNotificationService mobileNotificationService; diff --git a/core/src/main/java/bisq/core/notifications/alerts/price/PriceAlert.java b/core/src/main/java/bisq/core/notifications/alerts/price/PriceAlert.java index c7b21aeabaf..f52a048f60e 100644 --- a/core/src/main/java/bisq/core/notifications/alerts/price/PriceAlert.java +++ b/core/src/main/java/bisq/core/notifications/alerts/price/PriceAlert.java @@ -33,10 +33,12 @@ import org.bitcoinj.utils.Fiat; import javax.inject.Inject; +import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; @Slf4j +@Singleton public class PriceAlert { private final PriceFeedService priceFeedService; private final MobileNotificationService mobileNotificationService; diff --git a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java index 99dbf83ca77..3d0c065fc42 100644 --- a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java @@ -79,11 +79,13 @@ import bisq.common.proto.network.NetworkProtoResolver; import javax.inject.Inject; +import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; // TODO Use ProtobufferException instead of ProtobufferRuntimeException @Slf4j +@Singleton public class CoreNetworkProtoResolver extends CoreProtoResolver implements NetworkProtoResolver { @Inject diff --git a/core/src/main/java/bisq/core/proto/persistable/CorePersistenceProtoResolver.java b/core/src/main/java/bisq/core/proto/persistable/CorePersistenceProtoResolver.java index 4e4e5114c90..96e7bc9775e 100644 --- a/core/src/main/java/bisq/core/proto/persistable/CorePersistenceProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/persistable/CorePersistenceProtoResolver.java @@ -56,6 +56,7 @@ import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Singleton; import java.io.File; @@ -63,6 +64,7 @@ // TODO Use ProtobufferException instead of ProtobufferRuntimeException @Slf4j +@Singleton public class CorePersistenceProtoResolver extends CoreProtoResolver implements PersistenceProtoResolver { private final Provider btcWalletService; private final NetworkProtoResolver networkProtoResolver; diff --git a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java index c436271611d..daa0fc76bc2 100644 --- a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java +++ b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java @@ -24,7 +24,16 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.network.p2p.seed.DefaultSeedNodeRepository; +import bisq.core.notifications.MobileModel; +import bisq.core.notifications.MobileNotificationService; +import bisq.core.notifications.MobileNotificationValidator; +import bisq.core.notifications.alerts.MyOfferTakenEvents; +import bisq.core.notifications.alerts.TradeEvents; +import bisq.core.notifications.alerts.market.MarketAlerts; +import bisq.core.notifications.alerts.price.PriceAlert; import bisq.core.payment.TradeLimits; +import bisq.core.proto.network.CoreNetworkProtoResolver; +import bisq.core.proto.persistable.CorePersistenceProtoResolver; import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.BSFormatter; @@ -36,6 +45,8 @@ import bisq.common.ClockWatcher; import bisq.common.crypto.KeyRing; import bisq.common.crypto.KeyStorage; +import bisq.common.proto.network.NetworkProtoResolver; +import bisq.common.proto.persistable.PersistenceProtoResolver; import bisq.common.storage.CorruptedDatabaseFilesHandler; import org.springframework.mock.env.MockPropertySource; @@ -47,6 +58,7 @@ import org.junit.Test; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; public class GuiceSetupTest { @@ -84,6 +96,7 @@ public void testGuiceSetup() { // core module // assertSingleton(BisqSetup.class); // this is a can of worms +// assertSingleton(DisputeMsgEvents.class); assertSingleton(TorSetup.class); assertSingleton(P2PNetworkSetup.class); assertSingleton(WalletAppSetup.class); @@ -98,6 +111,20 @@ public void testGuiceSetup() { assertSingleton(AvoidStandbyModeService.class); assertSingleton(DefaultSeedNodeRepository.class); assertSingleton(SeedNodeRepository.class); + assertTrue(injector.getInstance(SeedNodeRepository.class) instanceof DefaultSeedNodeRepository); + assertSingleton(CoreNetworkProtoResolver.class); + assertSingleton(NetworkProtoResolver.class); + assertTrue(injector.getInstance(NetworkProtoResolver.class) instanceof CoreNetworkProtoResolver); + assertSingleton(PersistenceProtoResolver.class); + assertSingleton(CorePersistenceProtoResolver.class); + assertTrue(injector.getInstance(PersistenceProtoResolver.class) instanceof CorePersistenceProtoResolver); + assertSingleton(MobileNotificationService.class); + assertSingleton(MobileNotificationValidator.class); + assertSingleton(MobileModel.class); + assertSingleton(MyOfferTakenEvents.class); + assertSingleton(TradeEvents.class); + assertSingleton(PriceAlert.class); + assertSingleton(MarketAlerts.class); } private void assertSingleton(Class type) { From a8494a993a85e3bdf838029827ef79732c37111e Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Tue, 13 Aug 2019 15:52:49 +0200 Subject: [PATCH 5/5] fix missing annotation --- .../java/bisq/core/notifications/MobileMessageEncryption.java | 2 ++ desktop/src/test/java/bisq/desktop/GuiceSetupTest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core/src/main/java/bisq/core/notifications/MobileMessageEncryption.java b/core/src/main/java/bisq/core/notifications/MobileMessageEncryption.java index 0b6195872b7..37ddfe88d41 100644 --- a/core/src/main/java/bisq/core/notifications/MobileMessageEncryption.java +++ b/core/src/main/java/bisq/core/notifications/MobileMessageEncryption.java @@ -18,6 +18,7 @@ package bisq.core.notifications; import javax.inject.Inject; +import javax.inject.Singleton; import com.google.common.base.Charsets; @@ -33,6 +34,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j +@Singleton public class MobileMessageEncryption { private SecretKeySpec keySpec; private Cipher cipher; diff --git a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java index daa0fc76bc2..68feb00202f 100644 --- a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java +++ b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java @@ -24,6 +24,7 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.network.p2p.seed.DefaultSeedNodeRepository; +import bisq.core.notifications.MobileMessageEncryption; import bisq.core.notifications.MobileModel; import bisq.core.notifications.MobileNotificationService; import bisq.core.notifications.MobileNotificationValidator; @@ -118,6 +119,7 @@ public void testGuiceSetup() { assertSingleton(PersistenceProtoResolver.class); assertSingleton(CorePersistenceProtoResolver.class); assertTrue(injector.getInstance(PersistenceProtoResolver.class) instanceof CorePersistenceProtoResolver); + assertSingleton(MobileMessageEncryption.class); assertSingleton(MobileNotificationService.class); assertSingleton(MobileNotificationValidator.class); assertSingleton(MobileModel.class);