Merge pull request 'Upgrade to Event Bus 1.0.0' (#112) from event-bus-1.0.0 into develop

Reviewed-on: https://git.kske.dev/zdm/envoy/pulls/112
Reviewed-by: delvh <leon@kske.dev>
This commit is contained in:
Kai S. K. Engelbart 2021-02-20 22:29:38 +01:00
commit 544210a811
Signed by: Käfer & Engelbart Git
GPG Key ID: 70F2F9206EDC1FCE
21 changed files with 107 additions and 97 deletions

View File

@ -13,9 +13,8 @@ import java.util.stream.Stream;
import javafx.application.Platform;
import javafx.collections.*;
import dev.kske.eventbus.Event;
import dev.kske.eventbus.EventBus;
import dev.kske.eventbus.EventListener;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.core.Event;
import envoy.data.*;
import envoy.data.Message.MessageStatus;
@ -35,7 +34,7 @@ import envoy.client.event.*;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.3-alpha
*/
public final class LocalDB implements EventListener {
public final class LocalDB {
// Data
private User user;
@ -246,7 +245,8 @@ public final class LocalDB implements EventListener {
* @throws IOException if the saving process failed
* @since Envoy Client v0.3-alpha
*/
@Event(eventType = EnvoyCloseEvent.class, priority = 500)
@Event(EnvoyCloseEvent.class)
@Priority(500)
private synchronized void save() {
// Stop saving if this account has been deleted
@ -300,37 +300,43 @@ public final class LocalDB implements EventListener {
onLogout();
}
@Event(priority = 500)
@Event
@Priority(500)
private void onMessage(Message msg) {
if (msg.getStatus() == MessageStatus.SENT)
msg.nextStatus();
}
@Event(priority = 500)
@Event
@Priority(500)
private void onGroupMessage(GroupMessage msg) {
// TODO: Cancel event once EventBus is updated
if (msg.getStatus() == MessageStatus.WAITING || msg.getStatus() == MessageStatus.READ)
logger.warning("The groupMessage has the unexpected status " + msg.getStatus());
}
@Event(priority = 500)
@Event
@Priority(500)
private void onMessageStatusChange(MessageStatusChange evt) {
getMessage(evt.getID()).ifPresent(msg -> msg.setStatus(evt.get()));
}
@Event(priority = 500)
@Event
@Priority(500)
private void onGroupMessageStatusChange(GroupMessageStatusChange evt) {
this.<GroupMessage>getMessage(evt.getID())
.ifPresent(msg -> msg.getMemberStatuses().replace(evt.getMemberID(), evt.get()));
}
@Event(priority = 500)
@Event
@Priority(500)
private void onUserStatusChange(UserStatusChange evt) {
getChat(evt.getID()).map(Chat::getRecipient).map(User.class::cast)
.ifPresent(u -> u.setStatus(evt.get()));
}
@Event(priority = 500)
@Event
@Priority(500)
private void onUserOperation(UserOperation operation) {
final var eventUser = operation.get();
switch (operation.getOperationType()) {
@ -356,13 +362,15 @@ public final class LocalDB implements EventListener {
Platform.runLater(() -> chats.add(new GroupChat(user, newGroup)));
}
@Event(priority = 500)
@Event
@Priority(500)
private void onGroupResize(GroupResize evt) {
getChat(evt.getGroupID()).map(Chat::getRecipient).map(Group.class::cast)
.ifPresent(evt::apply);
}
@Event(priority = 500)
@Event
@Priority(500)
private void onNameChange(NameChange evt) {
chats.stream().map(Chat::getRecipient).filter(c -> c.getID() == evt.getID()).findAny()
.ifPresent(c -> c.setName(evt.get()));
@ -384,7 +392,8 @@ public final class LocalDB implements EventListener {
*
* @since Envoy Client v0.2-beta
*/
@Event(eventType = Logout.class, priority = 50)
@Event(Logout.class)
@Priority(50)
private void onLogout() {
autoSaver.cancel();
autoSaveRestart = true;
@ -416,22 +425,26 @@ public final class LocalDB implements EventListener {
});
}
@Event(priority = 500)
@Event
@Priority(500)
private void onOwnStatusChange(OwnStatusChange statusChange) {
user.setStatus(statusChange.get());
}
@Event(eventType = ContactsChangedSinceLastLogin.class, priority = 500)
@Event(ContactsChangedSinceLastLogin.class)
@Priority(500)
private void onContactsChangedSinceLastLogin() {
contactsChanged = true;
}
@Event(priority = 500)
@Event
@Priority(500)
private void onContactDisabled(ContactDisabled event) {
getChat(event.get().getID()).ifPresent(chat -> chat.setDisabled(true));
}
@Event(priority = 500)
@Event
@Priority(500)
private void onAccountDeletion(AccountDeletion deletion) {
if (user.getID() == deletion.get())
logger.log(Level.WARNING,
@ -496,7 +509,8 @@ public final class LocalDB implements EventListener {
* @param idGenerator the message ID generator to set
* @since Envoy Client v0.3-alpha
*/
@Event(priority = 150)
@Event
@Priority(150)
public void setIDGenerator(IDGenerator idGenerator) { this.idGenerator = idGenerator; }
/**

View File

@ -5,8 +5,7 @@ import java.util.*;
import java.util.logging.Level;
import java.util.prefs.Preferences;
import dev.kske.eventbus.*;
import dev.kske.eventbus.EventListener;
import dev.kske.eventbus.core.*;
import envoy.util.*;
@ -21,7 +20,7 @@ import envoy.client.event.EnvoyCloseEvent;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.2-alpha
*/
public final class Settings implements EventListener {
public final class Settings {
// Actual settings accessible by the rest of the application
private Map<String, SettingsItem<?>> items;
@ -69,7 +68,7 @@ public final class Settings implements EventListener {
* @throws IOException if an error occurs while saving the themes
* @since Envoy Client v0.2-alpha
*/
@Event(eventType = EnvoyCloseEvent.class)
@Event(EnvoyCloseEvent.class)
private void save() {
EnvoyLog.getLogger(Settings.class).log(Level.INFO, "Saving settings...");

View File

@ -1,6 +1,6 @@
package envoy.client.helper;
import dev.kske.eventbus.EventBus;
import dev.kske.eventbus.core.EventBus;
import envoy.client.data.*;
import envoy.client.event.EnvoyCloseEvent;

View File

@ -5,8 +5,8 @@ import java.net.Socket;
import java.util.concurrent.TimeoutException;
import java.util.logging.*;
import dev.kske.eventbus.*;
import dev.kske.eventbus.Event;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.core.Event;
import envoy.data.*;
import envoy.event.*;
@ -24,7 +24,7 @@ import envoy.client.event.EnvoyCloseEvent;
* @author Leon Hofmeister
* @since Envoy Client v0.1-alpha
*/
public final class Client implements EventListener, Closeable {
public final class Client implements Closeable {
// Connection handling
private Socket socket;
@ -153,13 +153,15 @@ public final class Client implements EventListener, Closeable {
send(new IDGeneratorRequest());
}
@Event(eventType = HandshakeRejection.class, priority = 1000)
@Event(HandshakeRejection.class)
@Priority(1000)
private void onHandshakeRejection() {
rejected = true;
}
@Override
@Event(eventType = EnvoyCloseEvent.class, priority = 50)
@Event(EnvoyCloseEvent.class)
@Priority(50)
public void close() {
if (online) {
logger.log(Level.INFO, "Closing connection...");

View File

@ -6,7 +6,7 @@ import java.util.*;
import java.util.function.Consumer;
import java.util.logging.*;
import dev.kske.eventbus.*;
import dev.kske.eventbus.core.EventBus;
import envoy.util.*;
@ -87,15 +87,17 @@ public final class Receiver extends Thread {
// Dispatch to the processor if present
if (processor != null)
processor.accept(obj);
// Dispatch to the event bus if the object is an event without a processor
else if (obj instanceof IEvent)
eventBus.dispatch((IEvent) obj);
// Notify if no processor could be located
// Dispatch to the event bus if the object has no processor
else
logger.log(Level.WARNING,
String.format(
"The received object has the %s for which no processor is defined.",
obj.getClass()));
eventBus.dispatch(obj);
// TODO: Log DeadEvent from Event Bus 1.1.0
// Notify if no processor could be located
// else
// logger.log(Level.WARNING,
// String.format(
// "The received object has the %s for which no processor is defined.",
// obj.getClass()));
}
} catch (final SocketException | EOFException e) {
// Connection probably closed by client.

View File

@ -8,7 +8,7 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.*;
import javafx.stage.Stage;
import dev.kske.eventbus.*;
import dev.kske.eventbus.core.*;
import envoy.util.EnvoyLog;
@ -25,7 +25,7 @@ import envoy.client.event.*;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
public final class SceneContext implements EventListener {
public final class SceneContext {
private final Stage stage;
private final Stack<Parent> roots = new Stack<>();
@ -126,13 +126,15 @@ public final class SceneContext implements EventListener {
}
}
@Event(eventType = Logout.class, priority = 150)
@Event(Logout.class)
@Priority(150)
private void onLogout() {
roots.clear();
controllers.clear();
}
@Event(priority = 150, eventType = ThemeChangeEvent.class)
@Event(ThemeChangeEvent.class)
@Priority(150)
private void onThemeChange() {
applyCSS();
}

View File

@ -9,8 +9,8 @@ import java.awt.image.BufferedImage;
import javafx.application.Platform;
import javafx.stage.Stage;
import dev.kske.eventbus.*;
import dev.kske.eventbus.Event;
import dev.kske.eventbus.core.Event;
import dev.kske.eventbus.core.EventBus;
import envoy.data.Message;
import envoy.data.User.UserStatus;
@ -31,7 +31,7 @@ import envoy.client.util.*;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.2-alpha
*/
public final class StatusTrayIcon implements EventListener {
public final class StatusTrayIcon {
/**
* The {@link TrayIcon} provided by the System Tray API for controlling the system tray. This
@ -136,7 +136,7 @@ public final class StatusTrayIcon implements EventListener {
*
* @since Envoy Client v0.2-beta
*/
@Event(eventType = Logout.class)
@Event(Logout.class)
public void hide() {
SystemTray.getSystemTray().remove(trayIcon);
}

View File

@ -21,14 +21,14 @@ import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.*;
import javafx.scene.input.*;
import javafx.scene.layout.*;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.FileChooser;
import javafx.util.Duration;
import dev.kske.eventbus.*;
import dev.kske.eventbus.Event;
import dev.kske.eventbus.core.*;
import dev.kske.eventbus.core.Event;
import envoy.data.*;
import envoy.data.Attachment.AttachmentType;
@ -55,7 +55,7 @@ import envoy.client.util.*;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
public final class ChatScene implements EventListener, Restorable, KeyboardMapping {
public final class ChatScene implements Restorable, KeyboardMapping {
@FXML
private ListView<Message> messageList;
@ -220,12 +220,13 @@ public final class ChatScene implements EventListener, Restorable, KeyboardMappi
});
}
@Event(eventType = BackEvent.class)
@Event(BackEvent.class)
private void onBackEvent() {
tabPane.getSelectionModel().select(Tabs.CONTACT_LIST.ordinal());
}
@Event(includeSubtypes = true)
@Event
@Polymorphic
private void onMessage(Message message) {
// The sender of the message is the recipient of the chat
@ -304,7 +305,7 @@ public final class ChatScene implements EventListener, Restorable, KeyboardMappi
}));
}
@Event(eventType = NoAttachments.class)
@Event(NoAttachments.class)
private void onNoAttachments() {
Platform.runLater(() -> {
attachmentButton.setDisable(true);
@ -317,12 +318,13 @@ public final class ChatScene implements EventListener, Restorable, KeyboardMappi
});
}
@Event(priority = 150)
@Event
@Priority(150)
private void onGroupCreationResult(GroupCreationResult result) {
Platform.runLater(() -> newGroupButton.setDisable(result.get() == null));
}
@Event(eventType = ThemeChangeEvent.class)
@Event(ThemeChangeEvent.class)
private void onThemeChange() {
settingsButton.setGraphic(
new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE)));
@ -345,12 +347,13 @@ public final class ChatScene implements EventListener, Restorable, KeyboardMappi
recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43));
}
@Event(eventType = Logout.class, priority = 200)
@Event(Logout.class)
@Priority(200)
private void onLogout() {
eventBus.removeListener(this);
}
@Event(eventType = AccountDeletion.class)
@Event(AccountDeletion.class)
private void onAccountDeletion() {
Platform.runLater(chatList::refresh);
}
@ -782,7 +785,8 @@ public final class ChatScene implements EventListener, Restorable, KeyboardMappi
attachmentView.setVisible(visible);
}
@Event(eventType = OwnStatusChange.class, priority = 50)
@Event(OwnStatusChange.class)
@Priority(50)
private void generateOwnStatusControl() {
// Update the own user status if present
@ -793,7 +797,7 @@ public final class ChatScene implements EventListener, Restorable, KeyboardMappi
// Else prepend it to the HBox children
final var ownUserControl = new ContactControl(localDB.getUser());
ownUserControl.setAlignment(Pos.CENTER_LEFT);
HBox.setHgrow(ownUserControl, Priority.NEVER);
HBox.setHgrow(ownUserControl, javafx.scene.layout.Priority.NEVER);
ownContactControl.getChildren().add(1, ownUserControl);
}
}

View File

@ -7,7 +7,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import dev.kske.eventbus.*;
import dev.kske.eventbus.core.*;
import envoy.data.User;
import envoy.event.ElementOperation;
@ -34,7 +34,7 @@ import envoy.client.ui.listcell.ListCellFactory;
* @author Maximilian K&auml;fer
* @since Envoy Client v0.1-beta
*/
public class ContactSearchTab implements EventListener {
public class ContactSearchTab {
@FXML
private TextArea searchBar;

View File

@ -10,11 +10,11 @@ import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import dev.kske.eventbus.*;
import dev.kske.eventbus.core.*;
import envoy.data.*;
import envoy.event.GroupCreation;
import envoy.event.contact.*;
import envoy.event.contact.UserOperation;
import envoy.util.Bounds;
import envoy.client.data.*;
@ -33,7 +33,7 @@ import envoy.client.ui.listcell.ListCellFactory;
* @author Maximilian K&auml;fer
* @since Envoy Client v0.1-beta
*/
public class GroupCreationTab implements EventListener {
public class GroupCreationTab {
@FXML
private Button createButton;

View File

@ -10,7 +10,7 @@ import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.ImageView;
import dev.kske.eventbus.*;
import dev.kske.eventbus.core.*;
import envoy.data.LoginCredentials;
import envoy.event.HandshakeRejection;
@ -27,7 +27,7 @@ import envoy.client.util.IconUtil;
* @author Maximilian K&auml;fer
* @since Envoy Client v0.1-beta
*/
public final class LoginScene implements EventListener {
public final class LoginScene {
@FXML
private TextField userTextField;

View File

@ -2,7 +2,7 @@ package envoy.client.ui.settings;
import javafx.scene.control.*;
import dev.kske.eventbus.EventBus;
import dev.kske.eventbus.core.EventBus;
import envoy.data.User.UserStatus;

View File

@ -15,7 +15,7 @@ import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import javafx.util.Duration;
import dev.kske.eventbus.EventBus;
import dev.kske.eventbus.core.EventBus;
import envoy.event.*;
import envoy.util.*;

View File

@ -7,7 +7,7 @@ import java.util.logging.*;
import javafx.stage.FileChooser;
import dev.kske.eventbus.EventBus;
import dev.kske.eventbus.core.EventBus;
import envoy.data.Message;
import envoy.util.EnvoyLog;

View File

@ -5,7 +5,7 @@ import java.util.logging.*;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import dev.kske.eventbus.EventBus;
import dev.kske.eventbus.core.EventBus;
import envoy.data.*;
import envoy.data.User.UserStatus;

View File

@ -16,12 +16,13 @@ module envoy.client {
requires javafx.fxml;
requires javafx.base;
requires javafx.graphics;
requires dev.kske.eventbus.core;
opens envoy.client.ui to javafx.graphics, javafx.fxml, dev.kske.eventbus;
opens envoy.client.ui.controller to javafx.graphics, javafx.fxml, envoy.client.util, dev.kske.eventbus;
opens envoy.client.ui.chatscene to javafx.graphics, javafx.fxml, envoy.client.util, dev.kske.eventbus;
opens envoy.client.ui to javafx.graphics, javafx.fxml, dev.kske.eventbus.core;
opens envoy.client.ui.controller to javafx.graphics, javafx.fxml, envoy.client.util, dev.kske.eventbus.core;
opens envoy.client.ui.chatscene to javafx.graphics, javafx.fxml, envoy.client.util, dev.kske.eventbus.core;
opens envoy.client.ui.control to javafx.graphics, javafx.fxml;
opens envoy.client.ui.settings to envoy.client.util;
opens envoy.client.net to dev.kske.eventbus;
opens envoy.client.data to dev.kske.eventbus;
opens envoy.client.net to dev.kske.eventbus.core;
opens envoy.client.data to dev.kske.eventbus.core;
}

View File

@ -12,18 +12,11 @@
<version>0.2-beta</version>
</parent>
<repositories>
<repository>
<id>kske-repo</id>
<url>https://kske.dev/maven-repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>dev.kske</groupId>
<artifactId>event-bus</artifactId>
<version>0.0.4</version>
<artifactId>event-bus-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>

View File

@ -2,15 +2,13 @@ package envoy.data;
import java.io.Serializable;
import dev.kske.eventbus.IEvent;
/**
* Generates increasing IDs between two numbers.
*
* @author Kai S. K. Engelbart
* @since Envoy Common v0.2-alpha
*/
public final class IDGenerator implements IEvent, Serializable {
public final class IDGenerator implements Serializable {
private final long end;
private long current;

View File

@ -4,8 +4,6 @@ import java.io.Serializable;
import java.time.Instant;
import java.util.Objects;
import dev.kske.eventbus.IEvent;
/**
* Represents a unique message with a unique, numeric ID. Further metadata includes the sender and
* recipient {@link User}s, as well as the creation date and the current {@link MessageStatus}.<br>
@ -14,7 +12,7 @@ import dev.kske.eventbus.IEvent;
* @author Leon Hofmeister
* @since Envoy Common v0.2-alpha
*/
public class Message implements Serializable, IEvent {
public class Message implements Serializable {
/**
* This enumeration defines all possible statuses a {link Message} can have.

View File

@ -3,18 +3,15 @@ package envoy.event;
import java.io.Serializable;
import java.util.Objects;
import dev.kske.eventbus.IEvent;
/**
* This class serves as a convenience base class for all events. It implements the {@link IEvent}
* interface and provides a generic value. For events without a value there also is
* {@link envoy.event.Event.Valueless}.
* This class serves as a convenience base class for all events. It provides a generic value. For
* events without a value there also is {@link envoy.event.Event.Valueless}.
*
* @author Kai S. K. Engelbart
* @param <T> the type of the Event
* @since Envoy v0.2-alpha
*/
public abstract class Event<T> implements IEvent, Serializable {
public abstract class Event<T> implements Serializable {
protected final T value;

View File

@ -16,5 +16,5 @@ module envoy.common {
exports envoy.event.contact;
requires transitive java.logging;
requires transitive dev.kske.eventbus;
requires transitive dev.kske.eventbus.core;
}