Added improved logging capabilities

This commit is contained in:
delvh 2020-06-13 22:36:52 +02:00
parent 2261e3713c
commit 753791e8c9
14 changed files with 157 additions and 129 deletions

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
@ -35,7 +36,7 @@ public class Cache<T> implements Consumer<T>, Serializable {
*/ */
@Override @Override
public void accept(T element) { public void accept(T element) {
logger.fine(String.format("Adding element %s to cache", element)); logger.log(Level.FINE, String.format("Adding element %s to cache", element));
elements.offer(element); elements.offer(element);
} }

View File

@ -7,6 +7,7 @@ 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.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import envoy.client.data.Cache; import envoy.client.data.Cache;
@ -56,25 +57,29 @@ public class Client implements Closeable {
* will block for up to 5 seconds. If the handshake does exceed this time limit, * will block for up to 5 seconds. If the handshake does exceed this time limit,
* an exception is thrown. * an exception is thrown.
* *
* @param credentials the login credentials of the user * @param credentials the login credentials of the
* @param receivedMessageCache a message cache containing all unread messages * user
* from the server that can be relayed after * @param receivedMessageCache a message cache containing all
* unread messages from the server
* that can be relayed after
* initialization * initialization
* @param receivedMessageStatusChangeEventCache an event cache containing all received messageStatusChangeEvents from the server that can be relayed after initialization * @param receivedMessageStatusChangeEventCache an event cache containing all
* received
* messageStatusChangeEvents from
* the server that can be relayed
* after initialization
* @throws TimeoutException 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,
Cache<MessageStatusChangeEvent> receivedMessageStatusChangeEventCache) Cache<MessageStatusChangeEvent> receivedMessageStatusChangeEventCache) throws TimeoutException, 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.log(Level.FINER, String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort()));
socket = new Socket(config.getServer(), config.getPort()); socket = new Socket(config.getServer(), config.getPort());
logger.fine("Successfully established TCP connection to server"); logger.log(Level.FINE, "Successfully established TCP connection to server");
// Create object receiver // Create object receiver
receiver = new Receiver(socket.getInputStream()); receiver = new Receiver(socket.getInputStream());
@ -114,19 +119,25 @@ public class Client implements Closeable {
// Remove all processors as they are only used during the handshake // Remove all processors as they are only used during the handshake
receiver.removeAllProcessors(); receiver.removeAllProcessors();
logger.info("Handshake completed."); logger.log(Level.INFO, "Handshake completed.");
} }
/** /**
* Initializes the {@link Receiver} used to process data sent from the server to * Initializes the {@link Receiver} used to process data sent from the server to
* this client. * this client.
* *
* @param localDB the local database used to persist the current * @param localDB the local database used to
* persist the current
* {@link IDGenerator} * {@link IDGenerator}
* @param receivedMessageCache a message cache containing all unread messages * @param receivedMessageCache a message cache containing all
* from the server that can be relayed after * unread messages from the server
* that can be relayed after
* initialization * initialization
* @param receivedMessageStatusChangeEventCache an event cache containing all received messageStatusChangeEvents from the server that can be relayed after initialization * @param receivedMessageStatusChangeEventCache an event cache containing all
* received
* messageStatusChangeEvents from
* the server that can be relayed
* after initialization
* @throws IOException if no {@link IDGenerator} is present and none could be * @throws IOException if no {@link IDGenerator} is present and none could be
* requested from the server * requested from the server
* @since Envoy Client v0.2-alpha * @since Envoy Client v0.2-alpha
@ -172,6 +183,7 @@ public class Client implements Closeable {
sendEvent(evt.get()); sendEvent(evt.get());
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
logger.log(Level.WARNING, "An error occurred when trying to send Event " + evt, e);
} }
}); });
@ -218,7 +230,7 @@ public class Client implements Closeable {
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public void requestIdGenerator() throws IOException { public void requestIdGenerator() throws IOException {
logger.info("Requesting new id generator..."); logger.log(Level.INFO, "Requesting new id generator...");
writeObject(new IDGeneratorRequest()); writeObject(new IDGeneratorRequest());
} }
@ -240,7 +252,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 " + obj); logger.log(Level.FINE, "Sending " + obj);
SerializationUtils.writeBytesWithLength(obj, socket.getOutputStream()); SerializationUtils.writeBytesWithLength(obj, socket.getOutputStream());
} }
@ -258,7 +270,7 @@ public class Client implements Closeable {
* @param clientUser the client user to set * @param clientUser the client user to set
* @since Envoy Client v0.2-alpha * @since Envoy Client v0.2-alpha
*/ */
public void setSender(User clientUser) { this.sender = clientUser; } public void setSender(User clientUser) { sender = clientUser; }
/** /**
* @return the {@link Receiver} used by this {@link Client} * @return the {@link Receiver} used by this {@link Client}

View File

@ -1,6 +1,7 @@
package envoy.client.net; package envoy.client.net;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import envoy.data.Message.MessageStatus; import envoy.data.Message.MessageStatus;
@ -29,7 +30,7 @@ public class MessageStatusChangeEventProcessor implements Consumer<MessageStatus
*/ */
@Override @Override
public void accept(MessageStatusChangeEvent evt) { public void accept(MessageStatusChangeEvent evt) {
if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.warning("Received invalid message status change " + evt); if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.log(Level.WARNING, "Received invalid message status change " + evt);
else EventBus.getInstance().dispatch(evt); else EventBus.getInstance().dispatch(evt);
} }
} }

View File

@ -1,6 +1,7 @@
package envoy.client.net; package envoy.client.net;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import envoy.client.event.MessageCreationEvent; import envoy.client.event.MessageCreationEvent;
@ -23,7 +24,7 @@ public class ReceivedMessageProcessor implements Consumer<Message> {
@Override @Override
public void accept(Message message) { public void accept(Message message) {
if (message.getStatus() != MessageStatus.SENT) logger.warning("The message has the unexpected status " + message.getStatus()); if (message.getStatus() != MessageStatus.SENT) logger.log(Level.WARNING, "The message has the unexpected status " + message.getStatus());
else { else {
// Update status to RECEIVED // Update status to RECEIVED
message.nextStatus(); message.nextStatus();

View File

@ -54,29 +54,29 @@ public class Receiver extends Thread {
try { try {
while (true) { while (true) {
// Read object length // Read object length
byte[] lenBytes = new byte[4]; final byte[] lenBytes = new byte[4];
in.read(lenBytes); in.read(lenBytes);
int len = SerializationUtils.bytesToInt(lenBytes, 0); final int len = SerializationUtils.bytesToInt(lenBytes, 0);
// Read object into byte array // Read object into byte array
byte[] objBytes = new byte[len]; final byte[] objBytes = new byte[len];
in.read(objBytes); in.read(objBytes);
try (ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(objBytes))) { try (ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(objBytes))) {
Object obj = oin.readObject(); final Object obj = oin.readObject();
logger.fine("Received " + obj); logger.log(Level.FINE, "Received " + obj);
// Get appropriate processor // Get appropriate processor
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Consumer processor = processors.get(obj.getClass()); final Consumer processor = processors.get(obj.getClass());
if (processor == null) if (processor == null) logger.log(Level.WARNING,
logger.warning(String.format("The received object has the class %s for which no processor is defined.", obj.getClass())); String.format("The received object has the class %s for which no processor is defined.", obj.getClass()));
else processor.accept(obj); else processor.accept(obj);
} }
} }
} catch (SocketException e) { } catch (final SocketException e) {
// Connection probably closed by client. // Connection probably closed by client.
} catch (Exception e) { } catch (final Exception e) {
logger.log(Level.SEVERE, "Error on receiver thread", e); logger.log(Level.SEVERE, "Error on receiver thread", e);
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -45,21 +45,21 @@ public class WriteProxy {
// Initialize cache processors for messages and message status change events // Initialize cache processors for messages and message status change events
localDB.getMessageCache().setProcessor(msg -> { localDB.getMessageCache().setProcessor(msg -> {
try { try {
logger.finer("Sending cached " + msg); logger.log(Level.FINER, "Sending cached " + msg);
client.sendMessage(msg); client.sendMessage(msg);
// Update message state to SENT in localDB // Update message state to SENT in localDB
localDB.getMessage(msg.getID()).ifPresent(Message::nextStatus); localDB.getMessage(msg.getID()).ifPresent(Message::nextStatus);
} catch (IOException e) { } catch (final IOException e) {
logger.log(Level.SEVERE, "Could not send cached message", e); logger.log(Level.SEVERE, "Could not send cached message: ", e);
} }
}); });
localDB.getStatusCache().setProcessor(evt -> { localDB.getStatusCache().setProcessor(evt -> {
logger.finer("Sending cached " + evt); logger.log(Level.FINER, "Sending cached " + evt);
try { try {
client.sendEvent(evt); client.sendEvent(evt);
} catch (IOException e) { } catch (final IOException e) {
logger.log(Level.SEVERE, "Could not send cached message status change event", e); logger.log(Level.SEVERE, "Could not send cached message status change event: ", e);
} }
}); });
} }

View File

@ -3,6 +3,7 @@ package envoy.client.ui;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
@ -13,6 +14,7 @@ import javafx.scene.layout.VBox;
import envoy.data.Message; import envoy.data.Message;
import envoy.data.Message.MessageStatus; import envoy.data.Message.MessageStatus;
import envoy.util.EnvoyLog;
/** /**
* Displays a single message inside the message list. * Displays a single message inside the message list.
@ -32,8 +34,9 @@ public class MessageListCell extends ListCell<Message> {
static { static {
try { try {
statusImages = IconUtil.loadByEnum(MessageStatus.class, 32); statusImages = IconUtil.loadByEnum(MessageStatus.class, 32);
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
EnvoyLog.getLogger(MessageListCell.class).log(Level.WARNING, "could not load status icons: ", e);
} }
} }
@ -45,7 +48,7 @@ public class MessageListCell extends ListCell<Message> {
@Override @Override
protected void updateItem(Message message, boolean empty) { protected void updateItem(Message message, boolean empty) {
super.updateItem(message, empty); super.updateItem(message, empty);
if(empty || message == null) { if (empty || message == null) {
setText(null); setText(null);
setGraphic(null); setGraphic(null);
} else { } else {

View File

@ -2,6 +2,7 @@ package envoy.client.ui;
import java.io.IOException; import java.io.IOException;
import java.util.Stack; import java.util.Stack;
import java.util.logging.Level;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
@ -11,6 +12,7 @@ import javafx.stage.Stage;
import envoy.client.data.Settings; import envoy.client.data.Settings;
import envoy.client.event.ThemeChangeEvent; import envoy.client.event.ThemeChangeEvent;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.util.EnvoyLog;
/** /**
* Manages a stack of scenes. The most recently added scene is displayed inside * Manages a stack of scenes. The most recently added scene is displayed inside
@ -35,7 +37,7 @@ public final class SceneContext {
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public static enum SceneInfo { public enum SceneInfo {
/** /**
* The main scene in which chats are displayed. * The main scene in which chats are displayed.
@ -117,7 +119,8 @@ public final class SceneContext {
applyCSS(); applyCSS();
stage.sizeToScene(); stage.sizeToScene();
stage.show(); stage.show();
} catch (IOException e) { } catch (final IOException e) {
EnvoyLog.getLogger(SceneContext.class).log(Level.SEVERE, String.format("Could not load scene for %s: ", sceneInfo), e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

View File

@ -2,6 +2,7 @@ package envoy.client.ui;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Date;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -51,6 +52,7 @@ public final class Startup extends Application {
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
try { try {
// Load the configuration from client.properties first // Load the configuration from client.properties first
logger.log(Level.INFO, "Envoy was started at " + new Date());
final Properties properties = new Properties(); final Properties properties = new Properties();
properties.load(Startup.class.getClassLoader().getResourceAsStream("client.properties")); properties.load(Startup.class.getClassLoader().getResourceAsStream("client.properties"));
config.load(properties); config.load(properties);
@ -63,6 +65,7 @@ public final class Startup extends Application {
if (!config.isInitialized()) throw new EnvoyException("Configuration is not fully initialized"); if (!config.isInitialized()) throw new EnvoyException("Configuration is not fully initialized");
} catch (final Exception e) { } catch (final Exception e) {
new Alert(AlertType.ERROR, "Error loading configuration values:\n" + e); new Alert(AlertType.ERROR, "Error loading configuration values:\n" + e);
logger.log(Level.SEVERE, "Error loading configuration values", e);
e.printStackTrace(); e.printStackTrace();
System.exit(1); System.exit(1);
} }
@ -77,16 +80,14 @@ public final class Startup extends Application {
if (config.isIgnoreLocalDB()) { if (config.isIgnoreLocalDB()) {
localDB = new TransientLocalDB(); localDB = new TransientLocalDB();
new Alert(AlertType.WARNING, "Ignoring local database.\nMessages will not be saved!").showAndWait(); new Alert(AlertType.WARNING, "Ignoring local database.\nMessages will not be saved!").showAndWait();
} else { } else try {
try {
localDB = new PersistentLocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath())); localDB = new PersistentLocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath()));
} catch (final IOException e3) { } catch (final IOException e3) {
logger.log(Level.SEVERE, "Could not initialize local database", e3); logger.log(Level.SEVERE, "Could not initialize local database: ", e3);
new Alert(AlertType.ERROR, "Could not initialize local database!\n" + e3).showAndWait(); new Alert(AlertType.ERROR, "Could not initialize local database!\n" + e3).showAndWait();
System.exit(1); System.exit(1);
return; return;
} }
}
// Initialize client and unread message cache // Initialize client and unread message cache
client = new Client(); client = new Client();
@ -109,14 +110,15 @@ public final class Startup extends Application {
@Override @Override
public void stop() { public void stop() {
try { try {
logger.info("Closing connection..."); logger.log(Level.INFO, "Closing connection...");
client.close(); client.close();
logger.info("Saving local database and settings..."); logger.log(Level.INFO, "Saving local database and settings...");
localDB.save(); localDB.save();
Settings.getInstance().save(); Settings.getInstance().save();
logger.log(Level.INFO, "Envoy was stopped as expected at " + new Date());
} catch (final Exception e) { } catch (final Exception e) {
logger.log(Level.SEVERE, "Unable to save local files", e); logger.log(Level.SEVERE, "Unable to save local files: ", e);
} }
} }

View File

@ -4,11 +4,13 @@ import java.awt.*;
import java.awt.TrayIcon.MessageType; import java.awt.TrayIcon.MessageType;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.util.logging.Level;
import envoy.client.event.MessageCreationEvent; import envoy.client.event.MessageCreationEvent;
import envoy.data.Message; import envoy.data.Message;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
import envoy.util.EnvoyLog;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -25,7 +27,7 @@ public class StatusTrayIcon {
* system tray. This includes displaying the icon, but also creating * system tray. This includes displaying the icon, but also creating
* notifications when new messages are received. * notifications when new messages are received.
*/ */
private TrayIcon trayIcon; private final TrayIcon trayIcon;
/** /**
* A received {@link Message} is only displayed as a system tray notification if * A received {@link Message} is only displayed as a system tray notification if
@ -46,16 +48,16 @@ public class StatusTrayIcon {
public StatusTrayIcon(Window focusTarget) throws EnvoyException { public StatusTrayIcon(Window focusTarget) throws EnvoyException {
if (!SystemTray.isSupported()) throw new EnvoyException("The Envoy tray icon is not supported."); if (!SystemTray.isSupported()) throw new EnvoyException("The Envoy tray icon is not supported.");
ClassLoader loader = Thread.currentThread().getContextClassLoader(); final ClassLoader loader = Thread.currentThread().getContextClassLoader();
Image img = Toolkit.getDefaultToolkit().createImage(loader.getResource("envoy_logo.png")); final Image img = Toolkit.getDefaultToolkit().createImage(loader.getResource("envoy_logo.png"));
trayIcon = new TrayIcon(img, "Envoy Client"); trayIcon = new TrayIcon(img, "Envoy Client");
trayIcon.setImageAutoSize(true); trayIcon.setImageAutoSize(true);
trayIcon.setToolTip("You are notified if you have unread messages."); trayIcon.setToolTip("You are notified if you have unread messages.");
PopupMenu popup = new PopupMenu(); final PopupMenu popup = new PopupMenu();
MenuItem exitMenuItem = new MenuItem("Exit"); final MenuItem exitMenuItem = new MenuItem("Exit");
exitMenuItem.addActionListener((evt) -> System.exit(0)); exitMenuItem.addActionListener(evt -> System.exit(0));
popup.add(exitMenuItem); popup.add(exitMenuItem);
trayIcon.setPopupMenu(popup); trayIcon.setPopupMenu(popup);
@ -71,7 +73,7 @@ public class StatusTrayIcon {
}); });
// Show the window if the user clicks on the icon // Show the window if the user clicks on the icon
trayIcon.addActionListener((evt) -> { focusTarget.setVisible(true); focusTarget.requestFocus(); }); trayIcon.addActionListener(evt -> { focusTarget.setVisible(true); focusTarget.requestFocus(); });
// Start processing message events // Start processing message events
// TODO: Handle other message types // TODO: Handle other message types
@ -90,7 +92,8 @@ public class StatusTrayIcon {
public void show() throws EnvoyException { public void show() throws EnvoyException {
try { try {
SystemTray.getSystemTray().add(trayIcon); SystemTray.getSystemTray().add(trayIcon);
} catch (AWTException e) { } catch (final AWTException e) {
EnvoyLog.getLogger(StatusTrayIcon.class).log(Level.INFO, "Could not display StatusTrayIcon: ", e);
throw new EnvoyException("Could not attach Envoy tray icon to system tray.", e); throw new EnvoyException("Could not attach Envoy tray icon to system tray.", e);
} }
} }

View File

@ -92,14 +92,12 @@ public final class ChatScene {
chat.getMessages().add(message); chat.getMessages().add(message);
// Update UI if in current chat // Update UI if in current chat
if (chat == currentChat) if (chat == currentChat) Platform.runLater(messageList::refresh);
Platform.runLater(messageList::refresh);
}); });
}); });
// Listen to message status changes // Listen to message status changes
eventBus.register(MessageStatusChangeEvent.class, e -> eventBus.register(MessageStatusChangeEvent.class, e -> localDB.getMessage(e.getID()).ifPresent(message -> {
localDB.getMessage(e.getID()).ifPresent(message -> {
message.setStatus(e.get()); message.setStatus(e.get());
// Update UI if in current chat // Update UI if in current chat
@ -107,16 +105,12 @@ public final class ChatScene {
})); }));
// Listen to user status changes // Listen to user status changes
eventBus.register(UserStatusChangeEvent.class, e -> eventBus.register(UserStatusChangeEvent.class,
userList.getItems() e -> userList.getItems()
.stream() .stream()
.filter(c -> c.getID() == e.getID()) .filter(c -> c.getID() == e.getID())
.findAny() .findAny()
.ifPresent(u -> { .ifPresent(u -> { ((User) u).setStatus(e.get()); Platform.runLater(userList::refresh); }));
((User) u).setStatus(e.get());
Platform.runLater(userList::refresh);
})
);
// Listen to contacts changes // Listen to contacts changes
eventBus.register(ContactOperationEvent.class, e -> { eventBus.register(ContactOperationEvent.class, e -> {
@ -169,8 +163,7 @@ public final class ChatScene {
// LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes // LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes
// Load the chat or create a new one and add it to the LocalDB // Load the chat or create a new one and add it to the LocalDB
currentChat = localDB currentChat = localDB.getChat(user.getID())
.getChat(user.getID())
.orElseGet(() -> { final var chat = new Chat(user); localDB.getChats().add(chat); return chat; }); .orElseGet(() -> { final var chat = new Chat(user); localDB.getChats().add(chat); return chat; });
messageList.setItems(FXCollections.observableList(currentChat.getMessages())); messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
@ -264,7 +257,7 @@ public final class ChatScene {
if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator(); if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator();
} catch (final IOException e) { } catch (final IOException e) {
logger.log(Level.SEVERE, "Error sending message", e); logger.log(Level.SEVERE, "Error sending message: ", e);
new Alert(AlertType.ERROR, "An error occured while sending the message!").showAndWait(); new Alert(AlertType.ERROR, "An error occured while sending the message!").showAndWait();
} }

View File

@ -57,6 +57,7 @@ public class ContactSearchScene {
/** /**
* @param sceneContext enables the user to return to the chat scene * @param sceneContext enables the user to return to the chat scene
* @param localDB the {@link LocalDB} that is used to save contacts
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void initializeData(SceneContext sceneContext, LocalDB localDB) { public void initializeData(SceneContext sceneContext, LocalDB localDB) {
@ -67,10 +68,8 @@ public class ContactSearchScene {
@FXML @FXML
private void initialize() { private void initialize() {
contactList.setCellFactory(e -> new ContactListCell()); contactList.setCellFactory(e -> new ContactListCell());
eventBus.register(ContactSearchResult.class, response -> Platform.runLater(() -> { eventBus.register(ContactSearchResult.class,
contactList.getItems().clear(); response -> Platform.runLater(() -> { contactList.getItems().clear(); contactList.getItems().addAll(response.get()); }));
contactList.getItems().addAll(response.get());
}));
} }
/** /**

View File

@ -49,6 +49,7 @@ public class GroupCreationScene {
/** /**
* @param sceneContext enables the user to return to the chat scene * @param sceneContext enables the user to return to the chat scene
* @param localDB the {@link LocalDB} that is used to save contacts
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void initializeData(SceneContext sceneContext, LocalDB localDB) { public void initializeData(SceneContext sceneContext, LocalDB localDB) {

View File

@ -3,6 +3,7 @@ package envoy.client.ui.controller;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javafx.application.Platform; import javafx.application.Platform;
@ -76,12 +77,18 @@ public final class LoginScene {
/** /**
* Loads the login dialog using the FXML file {@code LoginDialog.fxml}. * Loads the login dialog using the FXML file {@code LoginDialog.fxml}.
* *
* @param client the client used to perform the handshake * @param client the client used to perform the
* @param localDB the local database used for offline login * handshake
* @param receivedMessageCache the cache storing messages received during * @param localDB the local database used for
* offline login
* @param receivedMessageCache the cache storing messages
* received during
* the handshake * the handshake
* @param receivedMessageStatusChangeEventCache the cache storing messageStatusChangeEvents received during handshake * @param receivedMessageStatusChangeEventCache the cache storing
* @param sceneContext the scene context used to initialize the chat * messageStatusChangeEvents
* received during handshake
* @param sceneContext the scene context used to
* initialize the chat
* scene * scene
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@ -129,7 +136,7 @@ public final class LoginScene {
@FXML @FXML
private void abortLogin() { private void abortLogin() {
logger.info("The login process has been cancelled. Exiting..."); logger.log(Level.INFO, "The login process has been cancelled. Exiting...");
System.exit(0); System.exit(0);
} }
@ -141,8 +148,8 @@ public final class LoginScene {
loadChatScene(); loadChatScene();
} }
} catch (IOException | InterruptedException | TimeoutException e) { } catch (IOException | InterruptedException | TimeoutException e) {
logger.warning("Could not connect to server: " + e); logger.log(Level.WARNING, "Could not connect to server: ", e);
logger.finer("Attempting offline mode..."); logger.log(Level.FINER, "Attempting offline mode...");
attemptOfflineMode(credentials); attemptOfflineMode(credentials);
} }
} }
@ -158,6 +165,7 @@ public final class LoginScene {
loadChatScene(); loadChatScene();
} catch (final Exception e) { } catch (final Exception e) {
new Alert(AlertType.ERROR, "Client error: " + e).showAndWait(); new Alert(AlertType.ERROR, "Client error: " + e).showAndWait();
logger.log(Level.SEVERE, "Offline mode could not be loaded: ", e);
System.exit(1); System.exit(1);
} }
} }
@ -176,6 +184,7 @@ public final class LoginScene {
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
new Alert(AlertType.ERROR, "Error while loading local database: " + e + "\nChats will not be stored locally.").showAndWait(); new Alert(AlertType.ERROR, "Error while loading local database: " + e + "\nChats will not be stored locally.").showAndWait();
logger.log(Level.WARNING, "Could not load local database: ", e);
} }
// Initialize write proxy // Initialize write proxy