Skip to content

Commit

Permalink
Improve adminClient handling in Controller
Browse files Browse the repository at this point in the history
* Closing previous adminClient if present and clear TopicList, before creating a new one
* Display Exceptions thrown during AdminClient creation
* Clear cluster selection if AdminClient creation failed
  • Loading branch information
patschuh committed Jun 7, 2024
1 parent fc3771c commit 88bb4e8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/at/esque/kafka/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,17 @@ public void setup(Stage controlledStage) {
});

clusterComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
adminClient = new KafkaesqueAdminClient(newValue.getBootStrapServers(), configHandler.getSslProperties(selectedCluster()), configHandler.getSaslProperties(selectedCluster()));
refreshTopicList();
try {
closeAdminClientIfPresentAndClearTopicList();
if (newValue == null) {
return;
}
adminClient = new KafkaesqueAdminClient(newValue.getBootStrapServers(), configHandler.getSslProperties(selectedCluster()), configHandler.getSaslProperties(selectedCluster()));
refreshTopicList();
} catch (Exception e) {
ErrorAlert.show(e, controlledStage);
clusterComboBox.getSelectionModel().clearSelection();
}
});

partitionCombobox.getItems().add(-1);
Expand Down Expand Up @@ -345,6 +354,14 @@ public void setup(Stage controlledStage) {
});
}

private void closeAdminClientIfPresentAndClearTopicList() {
if (adminClient != null) {
adminClient.close();
adminClient = null;
topicListView.getBaseList().clear();
}
}

private void showTextInStageTitle(String text) {
if (Strings.isNullOrEmpty(text)) {
controlledStage.setTitle("Kafkaesque");
Expand Down

0 comments on commit 88bb4e8

Please sign in to comment.