Refactor blitzortung reconnect logic

This commit is contained in:
Minecon724 2025-05-24 10:05:46 +02:00
commit f54da5f702
Signed by untrusted user who does not match committer: m724
GPG key ID: A02E6E67AB961189
2 changed files with 6 additions and 7 deletions

View file

@ -39,15 +39,17 @@ public class BlitzortungProvider extends ThunderProvider {
scheduledExecutorService.schedule(() -> {
try {
Thread.sleep(5000);
websocketClient.closeBlocking();
Thread.sleep(3000);
submitEvent("Reconnecting");
websocketClient.reconnectBlocking();
websocketClient.connectBlocking();
} catch (InterruptedException e) {
submitEvent("Failed to reconnect", e);
}
}, 5, TimeUnit.SECONDS);
submitEvent("Reconnecting in 5 seconds");
submitEvent("Reconnecting in 3 seconds");
}
void submitStrike(Coordinates coordinates, long timestamp) {

View file

@ -77,9 +77,7 @@ class BlitzortungWebsocketClient extends WebSocketClient {
blitzortungProvider.submitStrike(coordinates, time);
} catch (JsonParseException e) {
blitzortungProvider.wsSubmitEvent("Websocket received invalid JSON", e);
// ignore invalid json
}
}
@Override
@ -94,8 +92,7 @@ class BlitzortungWebsocketClient extends WebSocketClient {
public void onError(Exception ex) {
blitzortungProvider.wsSubmitEvent("Websocket error", ex);
this.uri = uris[++currentUri % uris.length];
blitzortungProvider.reconnect();
closeConnection(0, "Closed because of an error");
}
}