add public server retry period with backoff

This commit is contained in:
Craig Raw 2021-02-18 09:27:01 +02:00
parent 1e3dd61b57
commit 759de8e047
2 changed files with 4 additions and 2 deletions

View file

@ -1315,7 +1315,7 @@ public class AppController implements Initializable {
@Subscribe @Subscribe
public void connectionFailed(ConnectionFailedEvent event) { public void connectionFailed(ConnectionFailedEvent event) {
String reason = event.getException().getCause() != null ? event.getException().getCause().getMessage() : event.getException().getMessage(); String reason = event.getException().getCause() != null ? event.getException().getCause().getMessage() : event.getException().getMessage();
String status = "Connection error: " + reason; String status = "Connection failed: " + reason;
statusUpdated(new StatusEvent(status)); statusUpdated(new StatusEvent(status));
} }

View file

@ -50,6 +50,7 @@ public class AppServices {
private static final Logger log = LoggerFactory.getLogger(AppServices.class); private static final Logger log = LoggerFactory.getLogger(AppServices.class);
private static final int SERVER_PING_PERIOD_SECS = 60; private static final int SERVER_PING_PERIOD_SECS = 60;
private static final int PUBLIC_SERVER_RETRY_PERIOD_SECS = 3;
private static final int ENUMERATE_HW_PERIOD_SECS = 30; private static final int ENUMERATE_HW_PERIOD_SECS = 30;
private static final int RATES_PERIOD_SECS = 5 * 60; private static final int RATES_PERIOD_SECS = 5 * 60;
private static final int VERSION_CHECK_PERIOD_HOURS = 24; private static final int VERSION_CHECK_PERIOD_HOURS = 24;
@ -187,6 +188,7 @@ public class AppServices {
} }
}); });
connectionService.setOnSucceeded(successEvent -> { connectionService.setOnSucceeded(successEvent -> {
connectionService.setPeriod(Duration.seconds(SERVER_PING_PERIOD_SECS));
connectionService.setRestartOnFailure(true); connectionService.setRestartOnFailure(true);
onlineProperty.removeListener(onlineServicesListener); onlineProperty.removeListener(onlineServicesListener);
@ -212,7 +214,7 @@ public class AppServices {
if(Config.get().getServerType() == ServerType.PUBLIC_ELECTRUM_SERVER) { if(Config.get().getServerType() == ServerType.PUBLIC_ELECTRUM_SERVER) {
List<String> otherServers = Arrays.stream(PublicElectrumServer.values()).map(PublicElectrumServer::getUrl).filter(url -> !url.equals(Config.get().getPublicElectrumServer())).collect(Collectors.toList()); List<String> otherServers = Arrays.stream(PublicElectrumServer.values()).map(PublicElectrumServer::getUrl).filter(url -> !url.equals(Config.get().getPublicElectrumServer())).collect(Collectors.toList());
Config.get().setPublicElectrumServer(otherServers.get(new Random().nextInt(otherServers.size()))); Config.get().setPublicElectrumServer(otherServers.get(new Random().nextInt(otherServers.size())));
restartService(connectionService); connectionService.setPeriod(Duration.seconds(PUBLIC_SERVER_RETRY_PERIOD_SECS));
} }
log.debug("Connection failed", failEvent.getSource().getException()); log.debug("Connection failed", failEvent.getSource().getException());