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

MessageType moved out

parent 8982ae7c
No related branches found
No related tags found
1 merge request!21*poof* final version
......@@ -3,15 +3,15 @@ import java.io.Serializable;
public final class Message implements Serializable {
private static final long serialVersionUID = 0xAEF34565673L;
private final String type;
private final MessageType type;
private byte[] data;
public <T extends Serializable> Message(String type, T object) {
public <T extends Serializable> Message(MessageType type, T object) {
this.type = type;
this.data = MessageQueue.serialize(object);
}
public String getMessageType() {
public MessageType getMessageType() {
return this.type;
}
......
......@@ -7,9 +7,7 @@ import java.util.function.Consumer;
import java.util.function.Predicate;
public class MessageManager extends MessageQueue implements Serializable {
private enum MessageType {
JoinedJourney, LeftJourney
}
public MessageManager(String host, String username, String password, String exchange) throws Exception {
super(host, username, password, exchange);
......@@ -18,7 +16,7 @@ public class MessageManager extends MessageQueue implements Serializable {
/*
* Private functions
*/
private <T extends Serializable> void sendEvent(String type, T event) {
private <T extends Serializable> void sendEvent(MessageType type, T event) {
Message m = new Message(type, event);
try {
this.sendBytes(MessageQueue.serialize(m));
......@@ -27,7 +25,7 @@ public class MessageManager extends MessageQueue implements Serializable {
}
}
private <T extends Serializable> void conditionalSubscribe(String type, Consumer<T> eventHandler,
private <T extends Serializable> void conditionalSubscribe(MessageType type, Consumer<T> eventHandler,
Predicate<T> condition) {
Consumer<byte[]> consumer = (bytes) -> {
Message receivedMessage = MessageQueue.unserialize(bytes);
......@@ -54,18 +52,18 @@ public class MessageManager extends MessageQueue implements Serializable {
public void conditionalSubscribeJoinedJourney(Consumer<JoinedJourney> eventHandler,
Predicate<JoinedJourney> condition) {
this.conditionalSubscribe("JoinedJourney", eventHandler, condition);
this.conditionalSubscribe(MessageType.JoinedJourney, eventHandler, condition);
}
public void conditionalSubscribeLeftJourney(Consumer<LeftJourney> eventHandler, Predicate<LeftJourney> condition) {
this.conditionalSubscribe("LeftJourney", eventHandler, condition);
this.conditionalSubscribe(MessageType.LeftJourney, eventHandler, condition);
}
public void sendJoinedJourney(JoinedJourney event) {
this.sendEvent("JoinedJourney", event);
this.sendEvent(MessageType.JoinedJourney, event);
}
public void sendLeftJourney(LeftJourney event) {
this.sendEvent("LeftJourney", event);
this.sendEvent(MessageType.LeftJourney, event);
}
}
\ No newline at end of file
package ch.hepia.mq;
public enum MessageType {
JoinedJourney, LeftJourney
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment