@@ -59,7 +59,7 @@ public abstract class LogbookSearchController implements WebSocketMessageHandler
5959 protected WebSocketClientService webSocketClientService ;
6060 private final String webSocketConnectUrl ;
6161 private final String subscriptionEndpoint ;
62- private final CountDownLatch connectivityCheckerCountDownLatch = new CountDownLatch (1 );
62+ protected final CountDownLatch connectivityCheckerCountDownLatch = new CountDownLatch (1 );
6363
6464 @ SuppressWarnings ("unused" )
6565 @ FXML
@@ -104,7 +104,6 @@ protected void determineConnectivity(Consumer<ConnectivityMode> consumer){
104104 connectivityMode = ConnectivityMode .HTTP_ONLY ;
105105 }
106106 }
107- connectivityCheckerCountDownLatch .countDown ();
108107 consumer .accept (connectivityMode );
109108 if (connectivityMode .equals (ConnectivityMode .NOT_CONNECTED )) {
110109 Platform .runLater (() -> {
@@ -176,6 +175,11 @@ private void cancelPeriodSearch() {
176175 * Utility method to cancel any ongoing periodic search jobs or close web socket.
177176 */
178177 public void shutdown () {
178+ try {
179+ connectivityCheckerCountDownLatch .await (10000 , TimeUnit .MILLISECONDS );
180+ } catch (InterruptedException e ) {
181+ Logger .getLogger (LogbookSearchController .class .getName ()).log (Level .WARNING , "Got InterruptedException waiting for connectivity mode result" );
182+ }
179183 if (connectivityModeObjectProperty .get ().equals (ConnectivityMode .WEB_SOCKETS_SUPPORTED ) && webSocketClientService != null ) {
180184 Logger .getLogger (LogbookSearchController .class .getName ()).log (Level .INFO , "Shutting down web socket" );
181185 webSocketClientService .removeWebSocketMessageHandler (this );
@@ -189,29 +193,20 @@ else if(connectivityModeObjectProperty.get().equals(ConnectivityMode.HTTP_ONLY))
189193 protected abstract void search ();
190194
191195 protected void connectWebSocket () {
192- try {
193- if (connectivityCheckerCountDownLatch .await (3000 , TimeUnit .MILLISECONDS )){
194- if (connectivityModeObjectProperty .get ().equals (ConnectivityMode .WEB_SOCKETS_SUPPORTED )) {
195- webSocketClientService = new WebSocketClientService (() -> {
196- logger .log (Level .INFO , "Connected to web socket on " + webSocketConnectUrl );
197- webSocketConnected .setValue (true );
198- viewSearchPane .visibleProperty ().set (true );
199- errorPane .visibleProperty ().set (false );
200- search ();
201- }, () -> {
202- logger .log (Level .INFO , "Disconnected from web socket on " + webSocketConnectUrl );
203- webSocketConnected .set (false );
204- viewSearchPane .visibleProperty ().set (false );
205- errorPane .visibleProperty ().set (true );
206- }, webSocketConnectUrl , subscriptionEndpoint , null );
207- webSocketClientService .addWebSocketMessageHandler (this );
208- webSocketClientService .connect ();
209- }
210- }
211- } catch (InterruptedException e ) {
212- Logger .getLogger (LogbookSearchController .class .getName ()).log (Level .WARNING , "Timed out waiting for connectivity check" );
213- connectivityModeObjectProperty .set (ConnectivityMode .NOT_CONNECTED );
214- }
196+ webSocketClientService = new WebSocketClientService (() -> {
197+ logger .log (Level .INFO , "Connected to web socket on " + webSocketConnectUrl );
198+ webSocketConnected .setValue (true );
199+ viewSearchPane .visibleProperty ().set (true );
200+ errorPane .visibleProperty ().set (false );
201+ search ();
202+ }, () -> {
203+ logger .log (Level .INFO , "Disconnected from web socket on " + webSocketConnectUrl );
204+ webSocketConnected .set (false );
205+ viewSearchPane .visibleProperty ().set (false );
206+ errorPane .visibleProperty ().set (true );
207+ }, webSocketConnectUrl , subscriptionEndpoint , null );
208+ webSocketClientService .addWebSocketMessageHandler (this );
209+ webSocketClientService .connect ();
215210 }
216211
217212 @ Override
0 commit comments