From eb55e8e86b861abe24dbd2b845b83522a0e5d186 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Fri, 10 Apr 2020 21:57:05 +0200 Subject: [PATCH 1/2] Replaced TimeLimitExceededException by TimeoutException This allows the removal of the java.naming module dependency. --- src/main/java/envoy/client/net/Client.java | 17 ++++++++--------- src/main/java/envoy/client/ui/LoginDialog.java | 5 ++--- src/main/java/module-info.java | 1 - 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index ea684a9..2440d8b 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -6,10 +6,9 @@ import java.net.Socket; import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeoutException; import java.util.logging.Logger; -import javax.naming.TimeLimitExceededException; - import envoy.client.data.Cache; import envoy.client.data.ClientConfig; import envoy.client.data.LocalDB; @@ -61,14 +60,14 @@ public class Client implements Closeable { * @param receivedMessageCache a message cache containing all unread messages * from the server that can be relayed after * initialization - * @throws TimeLimitExceededException if the server could not be reached - * @throws IOException if the login credentials could not be - * written - * @throws InterruptedException if the current thread is interrupted while - * waiting for the handshake response + * @throws TimeoutException if the server could not be reached + * @throws IOException if the login credentials could not be + * written + * @throws InterruptedException if the current thread is interrupted while + * waiting for the handshake response */ public void performHandshake(LoginCredentials credentials, Cache receivedMessageCache) - throws TimeLimitExceededException, IOException, InterruptedException { + throws TimeoutException, IOException, InterruptedException { if (online) throw new IllegalStateException("Handshake has already been performed successfully"); // Establish TCP connection logger.finer(String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort())); @@ -103,7 +102,7 @@ public class Client implements Closeable { return; } - if (System.currentTimeMillis() - start > 5000) throw new TimeLimitExceededException("Did not log in after 5 seconds"); + if (System.currentTimeMillis() - start > 5000) throw new TimeoutException("Did not log in after 5 seconds"); Thread.sleep(500); } diff --git a/src/main/java/envoy/client/ui/LoginDialog.java b/src/main/java/envoy/client/ui/LoginDialog.java index 8fbd78d..9126a67 100644 --- a/src/main/java/envoy/client/ui/LoginDialog.java +++ b/src/main/java/envoy/client/ui/LoginDialog.java @@ -1,10 +1,9 @@ package envoy.client.ui; import java.io.IOException; +import java.util.concurrent.TimeoutException; import java.util.logging.Logger; -import javax.naming.TimeLimitExceededException; - import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -135,7 +134,7 @@ public final class LoginDialog extends Dialog { client.initReceiver(localDB, receivedMessageCache); Platform.runLater(this::hide); } - } catch (IOException | InterruptedException | TimeLimitExceededException e) { + } catch (IOException | InterruptedException | TimeoutException e) { logger.warning("Could not connect to server. Trying offline mode..."); e.printStackTrace(); try { diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 2de5fa8..3ac8357 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -12,7 +12,6 @@ module envoy { requires transitive envoy.common; requires transitive java.desktop; requires transitive java.logging; - requires transitive java.naming; requires transitive java.prefs; requires javafx.controls; requires javafx.fxml; From 13a7a38debc30f5fdc1fa58f8d4a39bdf9d0be70 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 18 Apr 2020 10:34:03 +0200 Subject: [PATCH 2/2] Fixed bug duplicating messages --- src/main/java/envoy/client/net/Client.java | 2 +- src/main/java/envoy/client/net/Receiver.java | 2 +- .../java/envoy/client/ui/ChatSceneController.java | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index 2440d8b..00a6ddf 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -231,7 +231,7 @@ public class Client implements Closeable { private void writeObject(Object obj) throws IOException { checkOnline(); - logger.fine("Sending object " + obj); + logger.fine("Sending " + obj); SerializationUtils.writeBytesWithLength(obj, socket.getOutputStream()); } diff --git a/src/main/java/envoy/client/net/Receiver.java b/src/main/java/envoy/client/net/Receiver.java index bdaf853..b3dd763 100644 --- a/src/main/java/envoy/client/net/Receiver.java +++ b/src/main/java/envoy/client/net/Receiver.java @@ -54,7 +54,7 @@ public class Receiver extends Thread { try (ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(objBytes))) { Object obj = oin.readObject(); - logger.fine("Received object " + obj); + logger.fine("Received " + obj); // Get appropriate processor @SuppressWarnings("rawtypes") diff --git a/src/main/java/envoy/client/ui/ChatSceneController.java b/src/main/java/envoy/client/ui/ChatSceneController.java index b8927d4..f6d9b4f 100644 --- a/src/main/java/envoy/client/ui/ChatSceneController.java +++ b/src/main/java/envoy/client/ui/ChatSceneController.java @@ -5,6 +5,13 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; +import javafx.application.Platform; +import javafx.collections.FXCollections; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; + import envoy.client.data.Chat; import envoy.client.data.LocalDB; import envoy.client.event.MessageCreationEvent; @@ -17,12 +24,6 @@ import envoy.event.EventBus; import envoy.event.MessageStatusChangeEvent; import envoy.event.UserStatusChangeEvent; import envoy.util.EnvoyLog; -import javafx.application.Platform; -import javafx.collections.FXCollections; -import javafx.fxml.FXML; -import javafx.scene.control.*; -import javafx.scene.input.KeyCode; -import javafx.scene.input.KeyEvent; /** * Project: envoy-client
@@ -72,7 +73,6 @@ public final class ChatSceneController { eventBus.register(MessageCreationEvent.class, e -> { final var message = e.get(); final var chat = localDB.getChats().stream().filter(c -> c.getRecipient().getID() == message.getSenderID()).findAny().get(); - chat.getMessages().add(message); // Update UI if in current chat if (chat == currentChat) Platform.runLater(() -> messageList.getItems().add(message));