From 8b076ed54b692381a3c1410b704bdad33ad5ca0b Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 26 Dec 2019 15:27:44 +0100 Subject: Refactor handle (#75) * Refactor passing messages to handler * Add RMIMessage skeleton * Handle RMI message in RMI module --- .../cloudatlas/agent/messages/AgentMessage.java | 29 ++++++++-------------- .../cloudatlas/agent/messages/RMIMessage.java | 14 +++++++++++ .../agent/messages/TimerSchedulerMessage.java | 14 +++++------ 3 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/RMIMessage.java (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/messages') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java index b71831f..f343e0f 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java @@ -1,36 +1,25 @@ package pl.edu.mimuw.cloudatlas.agent.messages; -public abstract class AgentMessage { - - public enum AgentModule { - TIMER_SCHEDULER, - TIMER_GTP, - RMI, - UDP, - GOSSIP_IN, - GOSSIP_OUT, - STATE, - QUERY - } +import pl.edu.mimuw.cloudatlas.agent.modules.Module; +import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType; +public abstract class AgentMessage { private String messageId; - private AgentModule destinationModule; + private ModuleType destinationModule; private long timestamp; - public AgentMessage(String messageId, AgentModule destinationModule, long timestamp) { + public AgentMessage(String messageId, ModuleType destinationModule, long timestamp) { this.messageId = messageId; this.destinationModule = destinationModule; this.timestamp = timestamp; } - public AgentMessage(String messageId, AgentModule destinationModule) { + public AgentMessage(String messageId, ModuleType destinationModule) { this.messageId = messageId; this.destinationModule = destinationModule; this.timestamp = System.currentTimeMillis() / 1000L; } - public abstract AgentModule getCorrectMessageType(); - public String getMessageId() { return messageId; } @@ -39,14 +28,16 @@ public abstract class AgentMessage { this.messageId = messageId; } - public AgentModule getDestinationModule() { + public ModuleType getDestinationModule() { return destinationModule; } - public void setDestinationModule(AgentModule destinationModule) { + public void setDestinationModule(ModuleType destinationModule) { this.destinationModule = destinationModule; } + public abstract void callMe(Module module) throws InterruptedException, Module.InvalidMessageType; + public long getTimestamp() { return timestamp; } diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/RMIMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/RMIMessage.java new file mode 100644 index 0000000..a8e3afb --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/RMIMessage.java @@ -0,0 +1,14 @@ +package pl.edu.mimuw.cloudatlas.agent.messages; + +import pl.edu.mimuw.cloudatlas.agent.modules.Module; +import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType; + +public class RMIMessage extends AgentMessage { + public RMIMessage(String messageId, long timestamp) { + super(messageId, ModuleType.RMI, timestamp); + } + + public void callMe(Module module) throws InterruptedException, Module.InvalidMessageType { + module.handleTyped(this); + } +} diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/TimerSchedulerMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/TimerSchedulerMessage.java index 333b381..8566d67 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/TimerSchedulerMessage.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/TimerSchedulerMessage.java @@ -1,6 +1,8 @@ package pl.edu.mimuw.cloudatlas.agent.messages; import pl.edu.mimuw.cloudatlas.agent.modules.TimerScheduledTask; +import pl.edu.mimuw.cloudatlas.agent.modules.Module; +import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType; public class TimerSchedulerMessage extends AgentMessage { private String requestId; @@ -9,13 +11,12 @@ public class TimerSchedulerMessage extends AgentMessage { private TimerScheduledTask task; public TimerSchedulerMessage(String messageId, - AgentModule destinationModule, long timestamp, String requestId, long delay, long baseTime, TimerScheduledTask task) { - super(messageId, destinationModule, timestamp); + super(messageId, ModuleType.TIMER_SCHEDULER, timestamp); this.requestId = requestId; this.delay = delay; this.baseTime = baseTime; @@ -48,10 +49,9 @@ public class TimerSchedulerMessage extends AgentMessage { public String getRequestId() { return requestId; } - public void setRequestId(String requestId) { this.requestId = requestId; } - - @Override - public AgentModule getCorrectMessageType() { - return AgentModule.TIMER_SCHEDULER; + public void callMe(Module module) throws InterruptedException, Module.InvalidMessageType { + module.handleTyped(this); } + + public void setRequestId(String requestId) { this.requestId = requestId; } } -- cgit v1.2.3