Refactor blitzortung reconnect logic
This commit is contained in:
parent
6bfc57f114
commit
f54da5f702
2 changed files with 6 additions and 7 deletions
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue