Skip to content

Commit 20ebf73

Browse files
committed
Shutdown Olog UI checks connectivity in synchronized manner
1 parent 67eff8c commit 20ebf73

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryCalenderViewController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public Void call(Appointment appointment) {
196196

197197
determineConnectivity(connectivityMode -> {
198198
connectivityModeObjectProperty.set(connectivityMode);
199+
connectivityCheckerCountDownLatch.countDown();
199200
switch (connectivityModeObjectProperty.get()){
200201
case HTTP_ONLY -> search();
201202
case WEB_SOCKETS_SUPPORTED -> connectWebSocket();

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ public void updateItem(TableViewListItem logEntry, boolean empty) {
334334

335335
determineConnectivity(connectivityMode -> {
336336
connectivityModeObjectProperty.set(connectivityMode);
337+
connectivityCheckerCountDownLatch.countDown();
337338
switch (connectivityMode){
338339
case HTTP_ONLY -> search();
339340
case WEB_SOCKETS_SUPPORTED -> connectWebSocket();

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogbookSearchController.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)