Merge branch 'f/javafx' into f/settings
This commit is contained in:
commit
7d8b242099
@ -6,10 +6,9 @@ import java.net.Socket;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.naming.TimeLimitExceededException;
|
|
||||||
|
|
||||||
import envoy.client.data.Cache;
|
import envoy.client.data.Cache;
|
||||||
import envoy.client.data.ClientConfig;
|
import envoy.client.data.ClientConfig;
|
||||||
import envoy.client.data.LocalDB;
|
import envoy.client.data.LocalDB;
|
||||||
@ -61,14 +60,14 @@ public class Client implements Closeable {
|
|||||||
* @param receivedMessageCache a message cache containing all unread messages
|
* @param receivedMessageCache a message cache containing all unread messages
|
||||||
* from the server that can be relayed after
|
* from the server that can be relayed after
|
||||||
* initialization
|
* initialization
|
||||||
* @throws TimeLimitExceededException if the server could not be reached
|
* @throws TimeoutException if the server could not be reached
|
||||||
* @throws IOException if the login credentials could not be
|
* @throws IOException if the login credentials could not be
|
||||||
* written
|
* written
|
||||||
* @throws InterruptedException if the current thread is interrupted while
|
* @throws InterruptedException if the current thread is interrupted while
|
||||||
* waiting for the handshake response
|
* waiting for the handshake response
|
||||||
*/
|
*/
|
||||||
public void performHandshake(LoginCredentials credentials, Cache<Message> receivedMessageCache)
|
public void performHandshake(LoginCredentials credentials, Cache<Message> receivedMessageCache)
|
||||||
throws TimeLimitExceededException, IOException, InterruptedException {
|
throws TimeoutException, IOException, InterruptedException {
|
||||||
if (online) throw new IllegalStateException("Handshake has already been performed successfully");
|
if (online) throw new IllegalStateException("Handshake has already been performed successfully");
|
||||||
// Establish TCP connection
|
// Establish TCP connection
|
||||||
logger.finer(String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort()));
|
logger.finer(String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort()));
|
||||||
@ -103,7 +102,7 @@ public class Client implements Closeable {
|
|||||||
return;
|
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);
|
Thread.sleep(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +231,7 @@ public class Client implements Closeable {
|
|||||||
|
|
||||||
private void writeObject(Object obj) throws IOException {
|
private void writeObject(Object obj) throws IOException {
|
||||||
checkOnline();
|
checkOnline();
|
||||||
logger.fine("Sending object " + obj);
|
logger.fine("Sending " + obj);
|
||||||
SerializationUtils.writeBytesWithLength(obj, socket.getOutputStream());
|
SerializationUtils.writeBytesWithLength(obj, socket.getOutputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ public class Receiver extends Thread {
|
|||||||
|
|
||||||
try (ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(objBytes))) {
|
try (ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(objBytes))) {
|
||||||
Object obj = oin.readObject();
|
Object obj = oin.readObject();
|
||||||
logger.fine("Received object " + obj);
|
logger.fine("Received " + obj);
|
||||||
|
|
||||||
// Get appropriate processor
|
// Get appropriate processor
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@ -79,7 +79,6 @@ public final class ChatSceneController {
|
|||||||
eventBus.register(MessageCreationEvent.class, e -> {
|
eventBus.register(MessageCreationEvent.class, e -> {
|
||||||
final var message = e.get();
|
final var message = e.get();
|
||||||
final var chat = localDB.getChats().stream().filter(c -> c.getRecipient().getID() == message.getSenderID()).findAny().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
|
// Update UI if in current chat
|
||||||
if (chat == currentChat) Platform.runLater(() -> messageList.getItems().add(message));
|
if (chat == currentChat) Platform.runLater(() -> messageList.getItems().add(message));
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package envoy.client.ui;
|
package envoy.client.ui;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.naming.TimeLimitExceededException;
|
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
@ -135,7 +134,7 @@ public final class LoginDialog extends Dialog<Void> {
|
|||||||
client.initReceiver(localDB, receivedMessageCache);
|
client.initReceiver(localDB, receivedMessageCache);
|
||||||
Platform.runLater(this::hide);
|
Platform.runLater(this::hide);
|
||||||
}
|
}
|
||||||
} catch (IOException | InterruptedException | TimeLimitExceededException e) {
|
} catch (IOException | InterruptedException | TimeoutException e) {
|
||||||
logger.warning("Could not connect to server. Trying offline mode...");
|
logger.warning("Could not connect to server. Trying offline mode...");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
try {
|
try {
|
||||||
|
@ -12,7 +12,6 @@ module envoy {
|
|||||||
requires transitive envoy.common;
|
requires transitive envoy.common;
|
||||||
requires transitive java.desktop;
|
requires transitive java.desktop;
|
||||||
requires transitive java.logging;
|
requires transitive java.logging;
|
||||||
requires transitive java.naming;
|
|
||||||
requires transitive java.prefs;
|
requires transitive java.prefs;
|
||||||
requires javafx.controls;
|
requires javafx.controls;
|
||||||
requires javafx.fxml;
|
requires javafx.fxml;
|
||||||
|
Reference in New Issue
Block a user