Global task: to make a cloud manager. I need help. javaFX + Netty, How to make sure that the table is updated ONLY AFTER information arrives from the server? I understand that I need to play with thread, but I can't get the result.
public void updateList(Path path) {
try {
String correctPath = getCorrectPath(path);
pathField.setText(correctPath);
filesTable.getItems().clear();
if (!correctPath.startsWith(CLOUD)) {
filesTable.getItems().addAll(Files.list(path).map(FileInfo::new).collect(Collectors.toList()));
} else {
List<FileInfo> fileInfoList = null;
fileInfoList = files.get(userName);
filesTable.getItems().addAll(files.get(userName));
files.remove(userName);
}
filesTable.sort();
} catch (Exception e) {
Alert alert = new Alert(Alert.AlertType.WARNING, "По какой-то причине не удалось обновить список файлов", ButtonType.OK);
alert.showAndWait();
}
}
....
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
System.out.println(msg);
if (msg.startsWith(ROOT)) {
String[] commands = msg.split(" ");
String jsonString = msg.substring(ROOT.length()).substring(commands[1].length()).substring(FILE_INFO.length()).trim();
files.put(userName, getFileInfos(jsonString));
}
}
.....
private List<FileInfo> getFileInfos(String jsonString) {
Gson g = new Gson();
List<FileInfo> fileInfoList = new CopyOnWriteArrayList<>();
String[] fileInfos = jsonString.split("/");
FileInfo fileInfo;
for (int i = 0; i < fileInfos.length - 1; i++) {
fileInfo = g.fromJson(fileInfos[i].substring(1).trim(), FileInfo.class);
fileInfoList.add(fileInfo);
}
return fileInfoList;
}