Move AppSetupWithP2PAndDAO.start call to ExecutableForAppWithP2p

Refactor StatisticsMain

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2024-06-28 21:21:17 +07:00
parent 259f869e69
commit ed5547ac97
No known key found for this signature in database
GPG Key ID: 02AA2BAE387C8307
5 changed files with 21 additions and 34 deletions

View File

@ -54,6 +54,7 @@ public abstract class ExecutableForAppWithP2p extends BisqExecutable {
private volatile boolean stopped;
private final long startTime = System.currentTimeMillis();
private TradeLimits tradeLimits;
private AppSetupWithP2PAndDAO appSetupWithP2PAndDAO;
public ExecutableForAppWithP2p(String fullName, String scriptName, String appName, String version) {
super(fullName, scriptName, appName, version);
@ -71,11 +72,19 @@ public abstract class ExecutableForAppWithP2p extends BisqExecutable {
}
@Override
protected void startApplication() {
protected void applyInjector() {
super.applyInjector();
appSetupWithP2PAndDAO = injector.getInstance(AppSetupWithP2PAndDAO.class);
// Pin that as it is used in PaymentMethods and verification in TradeStatistics
tradeLimits = injector.getInstance(TradeLimits.class);
}
@Override
protected void startApplication() {
appSetupWithP2PAndDAO.start();
}
@Override
protected void launchApplication() {
onApplicationLaunched();

View File

@ -20,7 +20,6 @@ package bisq.restapi;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.app.TorSetup;
import bisq.core.app.misc.AppSetupWithP2PAndDAO;
import bisq.core.app.misc.ExecutableForAppWithP2p;
import bisq.core.dao.SignVerifyService;
import bisq.core.dao.governance.bond.reputation.BondedReputationRepository;
@ -107,7 +106,6 @@ public class RestApi extends ExecutableForAppWithP2p {
});
injector.getInstance(Preferences.class).setUseFullModeDaoMonitor(false);
injector.getInstance(AppSetupWithP2PAndDAO.class).start();
daoStateService = injector.getInstance(DaoStateService.class);
accountAgeWitnessService = injector.getInstance(AccountAgeWitnessService.class);

View File

@ -19,8 +19,6 @@ package bisq.seednode;
import bisq.seednode.reporting.SeedNodeReportingService;
import bisq.core.app.misc.AppSetup;
import bisq.core.app.misc.AppSetupWithP2PAndDAO;
import bisq.core.network.p2p.inventory.GetInventoryRequestHandler;
import bisq.common.config.Config;
@ -33,13 +31,11 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SeedNode {
private final AppSetup appSetup;
private final GetInventoryRequestHandler getInventoryRequestHandler;
private final SeedNodeReportingService seedNodeReportingService;
private final boolean useSeedNodeReportingService;
public SeedNode(Injector injector) {
appSetup = injector.getInstance(AppSetupWithP2PAndDAO.class);
getInventoryRequestHandler = injector.getInstance(GetInventoryRequestHandler.class);
seedNodeReportingService = injector.getInstance(SeedNodeReportingService.class);
@ -48,7 +44,6 @@ public class SeedNode {
}
public void startApplication() {
appSetup.start();
if (useSeedNodeReportingService) {
seedNodeReportingService.initialize();
}

View File

@ -17,8 +17,6 @@
package bisq.statistics;
import bisq.core.app.misc.AppSetup;
import bisq.core.app.misc.AppSetupWithP2PAndDAO;
import bisq.core.offer.OfferBookService;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.trade.statistics.TradeStatisticsManager;
@ -28,29 +26,23 @@ import bisq.network.p2p.P2PService;
import com.google.inject.Injector;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Statistics {
@Setter
private Injector injector;
private final P2PService p2pService;
private final PriceFeedService priceFeedService;
private final TradeStatisticsManager tradeStatisticsManager;
private final OfferBookService offerBookService; // pin to not get GC'ed
private OfferBookService offerBookService; // pin to not get GC'ed
private PriceFeedService priceFeedService;
private TradeStatisticsManager tradeStatisticsManager;
private P2PService p2pService;
private AppSetup appSetup;
public Statistics() {
public Statistics(Injector injector) {
p2pService = injector.getInstance(P2PService.class);
priceFeedService = injector.getInstance(PriceFeedService.class);
tradeStatisticsManager = injector.getInstance(TradeStatisticsManager.class);
offerBookService = injector.getInstance(OfferBookService.class);
}
public void startApplication() {
p2pService = injector.getInstance(P2PService.class);
offerBookService = injector.getInstance(OfferBookService.class);
priceFeedService = injector.getInstance(PriceFeedService.class);
tradeStatisticsManager = injector.getInstance(TradeStatisticsManager.class);
// We need the price feed for market based offers
priceFeedService.setCurrencyCode("USD");
p2pService.addP2PServiceListener(new BootstrapListener() {
@ -64,8 +56,5 @@ public class Statistics {
tradeStatisticsManager.onAllServicesInitialized();
}
});
appSetup = injector.getInstance(AppSetupWithP2PAndDAO.class);
appSetup.start();
}
}

View File

@ -30,12 +30,10 @@ public class StatisticsMain extends ExecutableForAppWithP2p {
new StatisticsMain().execute(args);
}
private final Statistics statistics;
private Statistics statistics;
public StatisticsMain() {
super("Bisq Statsnode", "bisq-statistics", "bisq_statistics", Version.VERSION);
statistics = new Statistics();
}
@Override
@ -54,14 +52,12 @@ public class StatisticsMain extends ExecutableForAppWithP2p {
@Override
protected void applyInjector() {
super.applyInjector();
statistics.setInjector(injector);
statistics = new Statistics(injector);
}
@Override
protected void startApplication() {
super.startApplication();
statistics.startApplication();
}
}