m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages
diff options
context:
space:
mode:
authorMartin <marcin.j.chrzanowski@gmail.com>2019-12-26 15:27:44 +0100
committerGitHub <noreply@github.com>2019-12-26 15:27:44 +0100
commit8b076ed54b692381a3c1410b704bdad33ad5ca0b (patch)
tree004c318b28166e70d3ef8fd988d75fef136c68ff /src/main/java/pl/edu/mimuw/cloudatlas/agent/messages
parentcbb43ba62d11888ce73314465dcffb537b6cd295 (diff)
Refactor handle (#75)
* Refactor passing messages to handler * Add RMIMessage skeleton * Handle RMI message in RMI module
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/messages')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java29
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/RMIMessage.java14
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/TimerSchedulerMessage.java14
3 files changed, 31 insertions, 26 deletions
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; }
}