Browse Source

add public server retry period with backoff

terminal
Craig Raw 4 years ago
parent
commit
759de8e047
  1. 2
      src/main/java/com/sparrowwallet/sparrow/AppController.java
  2. 4
      src/main/java/com/sparrowwallet/sparrow/AppServices.java

2
src/main/java/com/sparrowwallet/sparrow/AppController.java

@ -1315,7 +1315,7 @@ public class AppController implements Initializable {
@Subscribe
public void connectionFailed(ConnectionFailedEvent event) {
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));
}

4
src/main/java/com/sparrowwallet/sparrow/AppServices.java

@ -50,6 +50,7 @@ public class AppServices {
private static final Logger log = LoggerFactory.getLogger(AppServices.class);
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 RATES_PERIOD_SECS = 5 * 60;
private static final int VERSION_CHECK_PERIOD_HOURS = 24;
@ -187,6 +188,7 @@ public class AppServices {
}
});
connectionService.setOnSucceeded(successEvent -> {
connectionService.setPeriod(Duration.seconds(SERVER_PING_PERIOD_SECS));
connectionService.setRestartOnFailure(true);
onlineProperty.removeListener(onlineServicesListener);
@ -212,7 +214,7 @@ public class AppServices {
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());
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());

Loading…
Cancel
Save