Skip to content

Commit 70db1cf

Browse files
authored
Merge pull request #3521 from ControlSystemStudio/olog_websockets
Olog websockets
2 parents e2ec6f9 + 13ac314 commit 70db1cf

File tree

18 files changed

+764
-196
lines changed

18 files changed

+764
-196
lines changed

app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/OlogHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ public Collection<LogEntryLevel> listLevels() {
580580
response.body(), new TypeReference<Set<LogEntryLevel>>() {
581581
});
582582
} catch (Exception e) {
583-
LOGGER.log(Level.WARNING, "Unable to get templates from service", e);
583+
LOGGER.log(Level.WARNING, "Unable to get levels from service", e);
584584
return Collections.emptySet();
585585
}
586586
}

app/logbook/olog/ui/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<artifactId>core-framework</artifactId>
1515
<version>5.0.3-SNAPSHOT</version>
1616
</dependency>
17+
<dependency>
18+
<groupId>org.phoebus</groupId>
19+
<artifactId>core-websocket</artifactId>
20+
<version>5.0.3-SNAPSHOT</version>
21+
</dependency>
1722
<dependency>
1823
<groupId>org.phoebus</groupId>
1924
<artifactId>core-ui</artifactId>

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

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import javafx.scene.layout.GridPane;
4545
import javafx.scene.layout.HBox;
4646
import javafx.scene.layout.VBox;
47+
import org.phoebus.framework.jobs.JobManager;
4748
import org.phoebus.logbook.LogClient;
4849
import org.phoebus.logbook.LogEntryLevel;
4950
import org.phoebus.logbook.Logbook;
@@ -317,18 +318,21 @@ public void initialize() {
317318
}
318319
});
319320

320-
levelsList.addAll(logClient.listLevels().stream().map(LogEntryLevel::name).sorted().toList());
321-
levelsList.forEach(level -> {
322-
LevelSelection levelSelection = new LevelSelection(level, false);
323-
levelSelections.add(levelSelection);
324-
CheckBox checkBox = new CheckBox(level);
325-
LevelSelectionMenuItem levelSelectionMenuItem = new LevelSelectionMenuItem(checkBox);
326-
levelSelectionMenuItem.setHideOnClick(false);
327-
checkBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
328-
levelSelection.selected = newValue;
329-
setSelectedLevelsString();
321+
// Fetch levels from service on separate thread
322+
JobManager.schedule("Get logbook levels", monitor -> {
323+
levelsList.addAll(logClient.listLevels().stream().map(LogEntryLevel::name).sorted().toList());
324+
levelsList.forEach(level -> {
325+
LevelSelection levelSelection = new LevelSelection(level, false);
326+
levelSelections.add(levelSelection);
327+
CheckBox checkBox = new CheckBox(level);
328+
LevelSelectionMenuItem levelSelectionMenuItem = new LevelSelectionMenuItem(checkBox);
329+
levelSelectionMenuItem.setHideOnClick(false);
330+
checkBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
331+
levelSelection.selected = newValue;
332+
setSelectedLevelsString();
333+
});
334+
levelsContextMenu.getItems().add(levelSelectionMenuItem);
330335
});
331-
levelsContextMenu.getItems().add(levelSelectionMenuItem);
332336
});
333337

334338
sortOrderProperty.addListener(searchOnSortChange);
@@ -358,45 +362,47 @@ public AnchorPane getPane() {
358362
* @param queryString Query string containing search terms and values
359363
*/
360364
private void updateControls(String queryString) {
361-
Map<String, String> queryStringParameters = LogbookQueryUtil.parseHumanReadableQueryString(queryString);
362-
queryStringParameters.entrySet().forEach(entry -> {
363-
Keys keys = Keys.findKey(entry.getKey());
364-
if (keys != null) {
365-
if (keys.equals(Keys.LEVEL)) {
366-
List<String> validatedLevels = getValidatedLevelsSelection(entry.getValue());
367-
if (validatedLevels.isEmpty()) {
368-
searchParameters.levelsProperty().setValue(null);
369-
} else {
370-
String selectedLevels =
371-
String.join(",", validatedLevels);
372-
searchParameters.levelsProperty().setValue(selectedLevels);
373-
}
374-
levelsContextMenu.getItems().forEach(mi -> {
375-
LevelSelectionMenuItem levelSelectionMenuItem =
376-
(LevelSelectionMenuItem) mi;
377-
levelSelectionMenuItem.setSelected(validatedLevels.contains(levelSelectionMenuItem.getCheckBox().getText()));
378-
});
379-
} else if (keys.equals(Keys.LOGBOOKS)) {
380-
List<String> validatedLogbookNames = getValidatedLogbooksSelection(entry.getValue());
381-
if (validatedLogbookNames.isEmpty()) {
382-
searchParameters.logbooksProperty().setValue(null);
383-
} else {
384-
String selectedLogbooks =
385-
String.join(",", validatedLogbookNames);
386-
searchParameters.logbooksProperty().setValue(selectedLogbooks);
387-
}
388-
logbookSearchPopover.setSelected(validatedLogbookNames);
389-
} else if (keys.equals(Keys.TAGS)) {
390-
List<String> validatedTagsNames = getValidatedTagsSelection(entry.getValue());
391-
if (validatedTagsNames.isEmpty()) {
392-
searchParameters.tagsProperty().setValue(null);
393-
} else {
394-
String selectedTags = String.join(",", validatedTagsNames);
395-
searchParameters.tagsProperty().setValue(selectedTags);
365+
JobManager.schedule("Update controls from server data", monitor -> {
366+
Map<String, String> queryStringParameters = LogbookQueryUtil.parseHumanReadableQueryString(queryString);
367+
queryStringParameters.entrySet().forEach(entry -> {
368+
Keys keys = Keys.findKey(entry.getKey());
369+
if (keys != null) {
370+
if (keys.equals(Keys.LEVEL)) {
371+
List<String> validatedLevels = getValidatedLevelsSelection(entry.getValue());
372+
if (validatedLevels.isEmpty()) {
373+
searchParameters.levelsProperty().setValue(null);
374+
} else {
375+
String selectedLevels =
376+
String.join(",", validatedLevels);
377+
searchParameters.levelsProperty().setValue(selectedLevels);
378+
}
379+
levelsContextMenu.getItems().forEach(mi -> {
380+
LevelSelectionMenuItem levelSelectionMenuItem =
381+
(LevelSelectionMenuItem) mi;
382+
levelSelectionMenuItem.setSelected(validatedLevels.contains(levelSelectionMenuItem.getCheckBox().getText()));
383+
});
384+
} else if (keys.equals(Keys.LOGBOOKS)) {
385+
List<String> validatedLogbookNames = getValidatedLogbooksSelection(entry.getValue());
386+
if (validatedLogbookNames.isEmpty()) {
387+
searchParameters.logbooksProperty().setValue(null);
388+
} else {
389+
String selectedLogbooks =
390+
String.join(",", validatedLogbookNames);
391+
searchParameters.logbooksProperty().setValue(selectedLogbooks);
392+
}
393+
logbookSearchPopover.setSelected(validatedLogbookNames);
394+
} else if (keys.equals(Keys.TAGS)) {
395+
List<String> validatedTagsNames = getValidatedTagsSelection(entry.getValue());
396+
if (validatedTagsNames.isEmpty()) {
397+
searchParameters.tagsProperty().setValue(null);
398+
} else {
399+
String selectedTags = String.join(",", validatedTagsNames);
400+
searchParameters.tagsProperty().setValue(selectedTags);
401+
}
402+
tagSearchPopover.setSelected(validatedTagsNames);
396403
}
397-
tagSearchPopover.setSelected(validatedTagsNames);
398404
}
399-
}
405+
});
400406
});
401407
}
402408

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class LogEntryCalenderApp implements AppResourceDescriptor {
1717

1818
public static final Logger logger = Logger.getLogger(LogEntryCalenderApp.class.getName());
1919
static final Image icon = ImageCache.getImage(LogEntryCalenderApp.class, "/icons/logbook-16.png");
20-
public static final String NAME = "logEntryCalender";
21-
public static String DISPLAYNAME = "Log Entry Calender";
20+
public static final String NAME = "logEntryCalendar";
21+
public static String DISPLAYNAME = "Log Entry Calendar";
2222

2323
private static final String SUPPORTED_SCHEMA = "logCalender";
2424
private LogFactory logFactory;

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.phoebus.logbook.SearchResult;
3535
import org.phoebus.logbook.olog.ui.query.OlogQuery;
3636
import org.phoebus.logbook.olog.ui.query.OlogQueryManager;
37-
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
3837

3938
import java.net.URL;
4039
import java.time.LocalDateTime;
@@ -73,21 +72,23 @@ public class LogEntryCalenderViewController extends LogbookSearchController {
7372
// Model
7473
List<LogEntry> logEntries;
7574

75+
@SuppressWarnings("unused")
7676
@FXML
7777
private AnchorPane agendaPane;
7878
@FXML
7979
private Agenda agenda;
8080

8181
// Model
8282
private Map<Appointment, LogEntry> map;
83-
private Map<String, Agenda.AppointmentGroup> appointmentGroupMap = new TreeMap<String, Agenda.AppointmentGroup>();
83+
private Map<String, Agenda.AppointmentGroup> appointmentGroupMap = new TreeMap<>();
8484

85+
@SuppressWarnings("unused")
8586
@FXML
8687
private AdvancedSearchViewController advancedSearchViewController;
8788

8889
private final OlogQueryManager ologQueryManager;
8990
private final ObservableList<OlogQuery> ologQueries = FXCollections.observableArrayList();
90-
private SearchParameters searchParameters;
91+
private final SearchParameters searchParameters;
9192

9293
public LogEntryCalenderViewController(LogClient logClient, OlogQueryManager ologQueryManager, SearchParameters searchParameters) {
9394
setClient(logClient);
@@ -103,9 +104,7 @@ public void initialize() {
103104
// Set the search parameters in the advanced search controller so that it operates on the same object.
104105
ologQueries.setAll(ologQueryManager.getQueries());
105106

106-
searchParameters.addListener((observable, oldValue, newValue) -> {
107-
query.getEditor().setText(newValue);
108-
});
107+
searchParameters.addListener((observable, oldValue, newValue) -> query.getEditor().setText(newValue));
109108

110109
agenda = new Agenda();
111110
agenda.setEditAppointmentCallback(new Callback<Agenda.Appointment, Void>() {
@@ -195,13 +194,21 @@ public Void call(Appointment appointment) {
195194

196195
search.disableProperty().bind(searchInProgress);
197196

198-
search();
197+
determineConnectivity(connectivityMode -> {
198+
connectivityModeObjectProperty.set(connectivityMode);
199+
connectivityCheckerCountDownLatch.countDown();
200+
switch (connectivityModeObjectProperty.get()){
201+
case HTTP_ONLY -> search();
202+
case WEB_SOCKETS_SUPPORTED -> connectWebSocket();
203+
}
204+
});
199205
}
200206

201207
// Keeps track of when the animation is active. Multiple clicks will be ignored
202208
// until a give resize action is completed
203-
private AtomicBoolean moving = new AtomicBoolean(false);
209+
private final AtomicBoolean moving = new AtomicBoolean(false);
204210

211+
@SuppressWarnings("unused")
205212
@FXML
206213
public void resize() {
207214
if (!moving.compareAndExchangeAcquire(false, true)) {
@@ -236,6 +243,7 @@ public void resize() {
236243
}
237244

238245
@FXML
246+
@Override
239247
public void search() {
240248
String queryString = query.getEditor().getText();
241249
Map<String, String> params =
@@ -246,8 +254,6 @@ public void search() {
246254
searchResult1 -> {
247255
searchInProgress.set(false);
248256
setSearchResult(searchResult1);
249-
logger.log(Level.INFO, "Starting periodic search: " + queryString);
250-
periodicSearch(params, searchResult -> setSearchResult(searchResult));
251257
List<OlogQuery> queries = ologQueryManager.getQueries();
252258
Platform.runLater(() -> {
253259
ologQueries.setAll(queries);
@@ -256,7 +262,6 @@ public void search() {
256262
},
257263
(msg, ex) -> {
258264
searchInProgress.set(false);
259-
ExceptionDetailsErrorDialog.openError("Logbook Search Error", ex);
260265
});
261266
}
262267

@@ -285,11 +290,15 @@ public Appointment apply(LogEntry logentry) {
285290
LocalDateTime.ofInstant(logentry.getCreatedDate().plusSeconds(2400), ZoneId.systemDefault()));
286291
List<String> logbookNames = getLogbookNames();
287292
if (logbookNames != null && !logbookNames.isEmpty()) {
288-
int index = logbookNames.indexOf(logentry.getLogbooks().iterator().next().getName());
289-
if (index >= 0 && index <= 22) {
290-
appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", (index + 1))));
291-
} else {
292-
appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", 23)));
293+
try {
294+
int index = logbookNames.indexOf(logentry.getLogbooks().iterator().next().getName());
295+
if (index >= 0 && index <= 22) {
296+
appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", (index + 1))));
297+
} else {
298+
appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", 23)));
299+
}
300+
} catch (Exception e) {
301+
throw new RuntimeException(e);
293302
}
294303
}
295304
return appointment;
@@ -318,7 +327,8 @@ private List<String> getLogbookNames() {
318327
}
319328

320329
private void setSearchResult(SearchResult searchResult) {
321-
setLogs(searchResult.getLogs());List<OlogQuery> queries = ologQueryManager.getQueries();
330+
setLogs(searchResult.getLogs());
331+
List<OlogQuery> queries = ologQueryManager.getQueries();
322332
Platform.runLater(() -> {
323333
ologQueries.setAll(queries);
324334
// Top-most query is the one used in the search.

0 commit comments

Comments
 (0)