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(() -> { scheduledExecutorService.schedule(() -> {
try { try {
Thread.sleep(5000); websocketClient.closeBlocking();
Thread.sleep(3000);
submitEvent("Reconnecting"); submitEvent("Reconnecting");
websocketClient.reconnectBlocking(); websocketClient.connectBlocking();
} catch (InterruptedException e) { } catch (InterruptedException e) {
submitEvent("Failed to reconnect", e); submitEvent("Failed to reconnect", e);
} }
}, 5, TimeUnit.SECONDS); }, 5, TimeUnit.SECONDS);
submitEvent("Reconnecting in 5 seconds"); submitEvent("Reconnecting in 3 seconds");
} }
void submitStrike(Coordinates coordinates, long timestamp) { void submitStrike(Coordinates coordinates, long timestamp) {

View file

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