Skip to content
Snippets Groups Projects
Commit b867dab6 authored by Alexis Durgnat's avatar Alexis Durgnat :milky_way:
Browse files

ChatMessage

parent a4a3513a
No related branches found
No related tags found
1 merge request!21*poof* final version
package ch.hepia; package ch.hepia;
import ch.hepia.config.AppConfig; import ch.hepia.config.AppConfig;
import ch.hepia.events.JoinedJourney; import ch.hepia.events.*;
import ch.hepia.models.User; import ch.hepia.models.User;
import ch.hepia.mq.MessageManager; import ch.hepia.mq.MessageManager;
import javafx.application.Application; import javafx.application.Application;
...@@ -28,6 +28,8 @@ public class Main extends Application { ...@@ -28,6 +28,8 @@ public class Main extends Application {
AppConfig.RABBITMQ_HOSTNAME, "frog", "poney1234", "broadcaster"); AppConfig.RABBITMQ_HOSTNAME, "frog", "poney1234", "broadcaster");
m.sendJoinedJourney(new JoinedJourney(new User("Théo"), new ArrayList<>())); m.sendJoinedJourney(new JoinedJourney(new User("Théo"), new ArrayList<>()));
m.subscribeJoinedJourney(joinedJourney -> System.out.println("When I was hungary")); m.subscribeJoinedJourney(joinedJourney -> System.out.println("When I was hungary"));
m.subscribeChatMessage(chatMessage -> System.out.println(chatMessage.getUser().toString() + ": " + chatMessage.getMessage()));
m.sendChatMessage(new ChatMessage(new User("Alexis"), "Bonjour le monde !"));
//launch(args); //launch(args);
} }
......
...@@ -3,7 +3,7 @@ import java.io.Serializable; ...@@ -3,7 +3,7 @@ import java.io.Serializable;
public final class Message implements Serializable { public final class Message implements Serializable {
public static enum Type { public static enum Type {
JoinedJourney, LeftJourney JoinedJourney, LeftJourney, ChatMessage
} }
private static final long serialVersionUID = 0xAEF34565673L; private static final long serialVersionUID = 0xAEF34565673L;
......
...@@ -66,4 +66,17 @@ public class MessageManager extends MessageQueue { ...@@ -66,4 +66,17 @@ public class MessageManager extends MessageQueue {
public void sendLeftJourney(LeftJourney event) { public void sendLeftJourney(LeftJourney event) {
this.sendEvent(Message.Type.LeftJourney, event); this.sendEvent(Message.Type.LeftJourney, event);
} }
public void subscribeChatMessage(Consumer<ChatMessage> eventHandler) {
this.conditionalSubscribeChatMessage(eventHandler, (event) -> true);
}
public void conditionalSubscribeChatMessage(Consumer<ChatMessage> eventHandler, Predicate<ChatMessage> condition) {
this.conditionalSubscribe(Message.Type.ChatMessage, eventHandler, condition);
}
public void sendChatMessage(ChatMessage event) {
this.sendEvent(Message.Type.ChatMessage, event);
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment