m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin <marcin.j.chrzanowski@gmail.com>2019-12-30 14:53:51 +0100
committerGitHub <noreply@github.com>2019-12-30 14:53:51 +0100
commitfda20e7aa496926d4f4d78921925025040414d9b (patch)
tree1c9f6a0d9e19f083ab8160f18c2d1bc2acb546e3
parent71452a391ecb6620ff3a06b80da5824b88cb4ad0 (diff)
parent9e047485e990bd5dabbee4f1e9cf58489da964df (diff)
Merge pull request #82 from m-chrzan/agent-modules
Agent modules
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java15
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java6
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java1
3 files changed, 7 insertions, 15 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java
index 1b078cf..392e0a1 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java
@@ -2,12 +2,13 @@ package pl.edu.mimuw.cloudatlas.agent;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import pl.edu.mimuw.cloudatlas.agent.modules.Module;
import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType;
+import pl.edu.mimuw.cloudatlas.agent.modules.Qurnik;
import pl.edu.mimuw.cloudatlas.agent.modules.RMI;
+import pl.edu.mimuw.cloudatlas.agent.modules.Stanik;
import pl.edu.mimuw.cloudatlas.agent.modules.TimerScheduler;
public class Agent {
@@ -16,6 +17,8 @@ public class Agent {
HashMap<ModuleType, Module> modules = new HashMap<ModuleType, Module>();
modules.put(ModuleType.TIMER_SCHEDULER, new TimerScheduler(ModuleType.TIMER_SCHEDULER));
modules.put(ModuleType.RMI, new RMI(ModuleType.RMI));
+ modules.put(ModuleType.STATE, new Stanik());
+ modules.put(ModuleType.QUERY, new Qurnik());
// TODO add modules as we implement them
return modules;
}
@@ -23,11 +26,8 @@ public class Agent {
public static HashMap<ModuleType, Executor> initializeExecutors(
HashMap<ModuleType, Module> modules) {
HashMap<ModuleType, Executor> executors = new HashMap<ModuleType, Executor>();
- Iterator it = modules.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<ModuleType, Module> moduleEntry =
- (Map.Entry<ModuleType, Module>) it.next();
+ for (Map.Entry<ModuleType, Module> moduleEntry : modules.entrySet()) {
Module module = moduleEntry.getValue();
Executor executor = new Executor(module);
executors.put(moduleEntry.getKey(), executor);
@@ -38,11 +38,8 @@ public class Agent {
public static ArrayList<Thread> initializeExecutorThreads(HashMap<ModuleType, Executor> executors) {
ArrayList<Thread> executorThreads = new ArrayList<Thread>();
- Iterator it = executors.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<ModuleType, Executor> executorEntry =
- (Map.Entry<ModuleType, Executor>) it.next();
+ for (Map.Entry<ModuleType, Executor> executorEntry : executors.entrySet()) {
Thread thread = new Thread(executorEntry.getValue());
thread.setDaemon(true);
System.out.println("Initializing executor " + executorEntry.getKey());
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java
index 4f939b6..5b09253 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java
@@ -4,7 +4,6 @@ import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage;
import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
@@ -16,10 +15,7 @@ public class EventBus implements Runnable {
private HashMap<ModuleType, Executor> executors;
void setEventBusReference() {
- Iterator it = this.executors.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<ModuleType, Executor> executorEntry =
- (Map.Entry<ModuleType, Executor>) it.next();
+ for (Map.Entry<ModuleType, Executor> executorEntry : this.executors.entrySet()) {
executorEntry.getValue().setEventBus(this);
}
}
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
index ea893d9..b030901 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
@@ -1,6 +1,5 @@
package pl.edu.mimuw.cloudatlas.agent.modules;
-import java.util.Iterator;
import java.util.HashMap;
import java.util.Map.Entry;