m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java10
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java4
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java31
3 files changed, 44 insertions, 1 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java
index a50a95f..d0bf083 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java
@@ -3,7 +3,9 @@ package pl.edu.mimuw.cloudatlas.agent.modules;
import pl.edu.mimuw.cloudatlas.agent.Executor;
import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.TimerSchedulerMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.ResponseMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.RMIMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.StanikMessage;
/*
* A Module is a (potentially stateful) event handler.
@@ -34,6 +36,14 @@ public abstract class Module {
throw new InvalidMessageType("Got an RMIMessage in module " + moduleType.toString());
}
+ public void handleTyped(StanikMessage message) throws InterruptedException, InvalidMessageType {
+ throw new InvalidMessageType("Got a StanikMessage in module " + moduleType.toString());
+ }
+
+ public void handleTyped(ResponseMessage message) throws InterruptedException, InvalidMessageType {
+ throw new InvalidMessageType("Got a ResponseMessage in module " + moduleType.toString());
+ }
+
public void setExecutor(Executor executor) {
this.executor = executor;
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java
index ff4a92e..d221f06 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java
@@ -8,5 +8,7 @@ public enum ModuleType {
GOSSIP_IN,
GOSSIP_OUT,
STATE,
- QUERY
+ QUERY,
+ // for testing
+ TEST
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
new file mode 100644
index 0000000..b8db08a
--- /dev/null
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
@@ -0,0 +1,31 @@
+package pl.edu.mimuw.cloudatlas.agent.modules;
+
+import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.GetHierarchyMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.HierarchyMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.StanikMessage;
+import pl.edu.mimuw.cloudatlas.model.ZMI;
+
+public class Stanik extends Module {
+ private ZMI hierarchy;
+
+ public Stanik() {
+ super(ModuleType.STATE);
+ hierarchy = new ZMI();
+ }
+
+ public void handleTyped(StanikMessage message) throws InterruptedException, InvalidMessageType {
+ switch(message.getType()) {
+ case GET_HIERARCHY:
+ handleGetHierarchy((GetHierarchyMessage) message);
+ break;
+ default:
+ throw new InvalidMessageType("This type of message cannot be handled by Stanik");
+ }
+ }
+
+ public void handleGetHierarchy(GetHierarchyMessage message) throws InterruptedException {
+ HierarchyMessage response = new HierarchyMessage("", message.getRequestingModule(), 0, message.getRequestId(), hierarchy.clone());
+ sendMessage(response);
+ }
+}