Create SeedNode when injector is available and pass injector to constructor.

Add initialize method to seedNodeReportingService

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

View File

@ -29,29 +29,28 @@ import com.google.inject.Injector;
import com.google.inject.Key; import com.google.inject.Key;
import com.google.inject.name.Names; import com.google.inject.name.Names;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class SeedNode { public class SeedNode {
@Setter private final AppSetup appSetup;
private Injector injector; private final GetInventoryRequestHandler getInventoryRequestHandler;
private AppSetup appSetup; private final SeedNodeReportingService seedNodeReportingService;
private GetInventoryRequestHandler getInventoryRequestHandler; private final boolean useSeedNodeReportingService;
private SeedNodeReportingService seedNodeReportingService;
public SeedNode() { public SeedNode(Injector injector) {
appSetup = injector.getInstance(AppSetupWithP2PAndDAO.class);
getInventoryRequestHandler = injector.getInstance(GetInventoryRequestHandler.class);
seedNodeReportingService = injector.getInstance(SeedNodeReportingService.class);
String seedNodeReportingServerUrl = injector.getInstance(Key.get(String.class, Names.named(Config.SEED_NODE_REPORTING_SERVER_URL)));
useSeedNodeReportingService = seedNodeReportingServerUrl != null && !seedNodeReportingServerUrl.trim().isEmpty();
} }
public void startApplication() { public void startApplication() {
appSetup = injector.getInstance(AppSetupWithP2PAndDAO.class);
appSetup.start(); appSetup.start();
if (useSeedNodeReportingService) {
getInventoryRequestHandler = injector.getInstance(GetInventoryRequestHandler.class); seedNodeReportingService.initialize();
String seedNodeReportingServerUrl = injector.getInstance(Key.get(String.class, Names.named(Config.SEED_NODE_REPORTING_SERVER_URL)));
if (seedNodeReportingServerUrl != null && !seedNodeReportingServerUrl.trim().isEmpty()) {
seedNodeReportingService = injector.getInstance(SeedNodeReportingService.class);
} }
} }

View File

@ -63,13 +63,11 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
new SeedNodeMain().execute(args); new SeedNodeMain().execute(args);
} }
private final SeedNode seedNode; private SeedNode seedNode;
private Timer checkConnectionLossTimer; private Timer checkConnectionLossTimer;
public SeedNodeMain() { public SeedNodeMain() {
super("Bisq Seednode", "bisq-seednode", "bisq_seednode", Version.VERSION); super("Bisq Seednode", "bisq-seednode", "bisq_seednode", Version.VERSION);
seedNode = new SeedNode();
} }
@Override @Override
@ -107,7 +105,7 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
protected void applyInjector() { protected void applyInjector() {
super.applyInjector(); super.applyInjector();
seedNode.setInjector(injector); seedNode = new SeedNode(injector);
} }
@Override @Override

View File

@ -87,6 +87,7 @@ public class SeedNodeReportingService {
private final static long HEART_BEAT_DELAY_SEC = TimeUnit.MINUTES.toSeconds(1); private final static long HEART_BEAT_DELAY_SEC = TimeUnit.MINUTES.toSeconds(1);
private final P2PService p2PService; private final P2PService p2PService;
private final DaoFacade daoFacade;
private final NetworkNode networkNode; private final NetworkNode networkNode;
private final PeerManager peerManager; private final PeerManager peerManager;
private final P2PDataStorage p2PDataStorage; private final P2PDataStorage p2PDataStorage;
@ -94,13 +95,14 @@ public class SeedNodeReportingService {
private final DaoStateMonitoringService daoStateMonitoringService; private final DaoStateMonitoringService daoStateMonitoringService;
private final ProposalStateMonitoringService proposalStateMonitoringService; private final ProposalStateMonitoringService proposalStateMonitoringService;
private final BlindVoteStateMonitoringService blindVoteStateMonitoringService; private final BlindVoteStateMonitoringService blindVoteStateMonitoringService;
private final RequestDataManager requestDataManager;
private final FullNodeNetworkService fullNodeNetworkService;
private final int maxConnections; private final int maxConnections;
private final String seedNodeReportingServerUrl; private final String seedNodeReportingServerUrl;
private final DaoStateListener daoStateListener; private final DaoStateListener daoStateListener;
private final HttpClient httpClient; private final HttpClient httpClient;
private final ExecutorService executor; private final ExecutorService executor;
private final Timer heartBeatTimer; private Timer heartBeatTimer, dataReportTimer;
private Timer dataReportTimer;
@Inject @Inject
public SeedNodeReportingService(P2PService p2PService, public SeedNodeReportingService(P2PService p2PService,
@ -117,6 +119,7 @@ public class SeedNodeReportingService {
@Named(Config.MAX_CONNECTIONS) int maxConnections, @Named(Config.MAX_CONNECTIONS) int maxConnections,
@Named(Config.SEED_NODE_REPORTING_SERVER_URL) String seedNodeReportingServerUrl) { @Named(Config.SEED_NODE_REPORTING_SERVER_URL) String seedNodeReportingServerUrl) {
this.p2PService = p2PService; this.p2PService = p2PService;
this.daoFacade = daoFacade;
this.networkNode = networkNode; this.networkNode = networkNode;
this.peerManager = peerManager; this.peerManager = peerManager;
this.p2PDataStorage = p2PDataStorage; this.p2PDataStorage = p2PDataStorage;
@ -124,6 +127,8 @@ public class SeedNodeReportingService {
this.daoStateMonitoringService = daoStateMonitoringService; this.daoStateMonitoringService = daoStateMonitoringService;
this.proposalStateMonitoringService = proposalStateMonitoringService; this.proposalStateMonitoringService = proposalStateMonitoringService;
this.blindVoteStateMonitoringService = blindVoteStateMonitoringService; this.blindVoteStateMonitoringService = blindVoteStateMonitoringService;
this.requestDataManager = requestDataManager;
this.fullNodeNetworkService = fullNodeNetworkService;
this.maxConnections = maxConnections; this.maxConnections = maxConnections;
this.seedNodeReportingServerUrl = seedNodeReportingServerUrl; this.seedNodeReportingServerUrl = seedNodeReportingServerUrl;
@ -132,8 +137,6 @@ public class SeedNodeReportingService {
executor = Utilities.getThreadPoolExecutor("SeedNodeReportingService", 20, 40, 100, 8 * 60); executor = Utilities.getThreadPoolExecutor("SeedNodeReportingService", 20, 40, 100, 8 * 60);
httpClient = HttpClient.newBuilder().executor(executor).build(); httpClient = HttpClient.newBuilder().executor(executor).build();
heartBeatTimer = UserThread.runPeriodically(this::sendHeartBeat, HEART_BEAT_DELAY_SEC);
daoStateListener = new DaoStateListener() { daoStateListener = new DaoStateListener() {
@Override @Override
public void onParseBlockChainComplete() { public void onParseBlockChainComplete() {
@ -152,6 +155,11 @@ public class SeedNodeReportingService {
}); });
} }
}; };
}
public void initialize() {
heartBeatTimer = UserThread.runPeriodically(this::sendHeartBeat, HEART_BEAT_DELAY_SEC);
daoFacade.addBsqStateListener(daoStateListener); daoFacade.addBsqStateListener(daoStateListener);
p2PService.getNetworkNode().addMessageListener((networkEnvelope, connection) -> { p2PService.getNetworkNode().addMessageListener((networkEnvelope, connection) -> {