Skip to content
Snippets Groups Projects
Verified Commit 330e9bd2 authored by Michaël El Kharroubi's avatar Michaël El Kharroubi :satellite:
Browse files

Refactor MessageType

parent 52ac8f67
No related branches found
No related tags found
2 merge requests!21*poof* final version,!17Gui mq
......@@ -2,16 +2,20 @@ package ch.hepia.mq;
import java.io.Serializable;
public final class Message implements Serializable {
public static enum Type {
JoinedJourney, LeftJourney
}
private static final long serialVersionUID = 0xAEF34565673L;
private final MessageType type;
private final Type type;
private byte[] data;
public <T extends Serializable> Message(MessageType type, T object) {
public <T extends Serializable> Message(Type type, T object) {
this.type = type;
this.data = MessageQueue.serialize(object);
}
public MessageType getMessageType() {
public Type getMessageType() {
return this.type;
}
......
......@@ -16,7 +16,7 @@ public class MessageManager extends MessageQueue {
/*
* Private functions
*/
private <T extends Serializable> void sendEvent(MessageType type, T event) {
private <T extends Serializable> void sendEvent(Message.Type type, T event) {
Message m = new Message(type, event);
try {
this.sendBytes(MessageQueue.serialize(m));
......@@ -25,7 +25,7 @@ public class MessageManager extends MessageQueue {
}
}
private <T extends Serializable> void conditionalSubscribe(MessageType type, Consumer<T> eventHandler,
private <T extends Serializable> void conditionalSubscribe(Message.Type type, Consumer<T> eventHandler,
Predicate<T> condition) {
Consumer<byte[]> consumer = (bytes) -> {
Message receivedMessage = MessageQueue.unserialize(bytes);
......@@ -52,18 +52,18 @@ public class MessageManager extends MessageQueue {
public void conditionalSubscribeJoinedJourney(Consumer<JoinedJourney> eventHandler,
Predicate<JoinedJourney> condition) {
this.conditionalSubscribe(MessageType.JoinedJourney, eventHandler, condition);
this.conditionalSubscribe(Message.Type.JoinedJourney, eventHandler, condition);
}
public void conditionalSubscribeLeftJourney(Consumer<LeftJourney> eventHandler, Predicate<LeftJourney> condition) {
this.conditionalSubscribe(MessageType.LeftJourney, eventHandler, condition);
this.conditionalSubscribe(Message.Type.LeftJourney, eventHandler, condition);
}
public void sendJoinedJourney(JoinedJourney event) {
this.sendEvent(MessageType.JoinedJourney, event);
this.sendEvent(Message.Type.JoinedJourney, event);
}
public void sendLeftJourney(LeftJourney event) {
this.sendEvent(MessageType.LeftJourney, event);
this.sendEvent(Message.Type.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