mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
add public server retry period with backoff
This commit is contained in:
parent
1e3dd61b57
commit
759de8e047
2 changed files with 4 additions and 2 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
|
|
Loading…
Reference in a new issue