diff options
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 2 | ||||
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/Executor.java | 1 | ||||
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java (renamed from src/main/java/pl/edu/mimuw/cloudatlas/agent/Module.java) | 5 | ||||
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java (renamed from src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java) | 2 | ||||
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java | 33 | ||||
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java | 32 |
6 files changed, 39 insertions, 36 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 0cfdfd6..e695773 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -1,6 +1,5 @@ package pl.edu.mimuw.cloudatlas.agent; -import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; @@ -10,6 +9,7 @@ import java.util.Iterator; import java.util.Map; import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; +import pl.edu.mimuw.cloudatlas.agent.modules.Module; import pl.edu.mimuw.cloudatlas.api.Api; import pl.edu.mimuw.cloudatlas.interpreter.Main; import pl.edu.mimuw.cloudatlas.model.ZMI; diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Executor.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Executor.java index f3cf2ea..6d29d13 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Executor.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Executor.java @@ -3,6 +3,7 @@ package pl.edu.mimuw.cloudatlas.agent; import java.util.concurrent.LinkedBlockingQueue; import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; +import pl.edu.mimuw.cloudatlas.agent.modules.Module; /* * Queues messages sent to a particular module and ensures they are eventually diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Module.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java index 167f3b7..dd6a5f8 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Module.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java @@ -1,5 +1,6 @@ -package pl.edu.mimuw.cloudatlas.agent; +package pl.edu.mimuw.cloudatlas.agent.modules; +import pl.edu.mimuw.cloudatlas.agent.Executor; import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; /* @@ -9,7 +10,7 @@ public abstract class Module { private AgentMessage.AgentModule moduleType; private Executor executor; - Module(AgentMessage.AgentModule moduleType) { + public Module(AgentMessage.AgentModule moduleType) { this.moduleType = moduleType; } diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java index d9bd2d2..db9dd26 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java @@ -1,4 +1,4 @@ -package pl.edu.mimuw.cloudatlas.agent.timer; +package pl.edu.mimuw.cloudatlas.agent.modules; import java.util.TimerTask; diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java new file mode 100644 index 0000000..b7ce435 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java @@ -0,0 +1,33 @@ +package pl.edu.mimuw.cloudatlas.agent.modules; + +import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; +import pl.edu.mimuw.cloudatlas.agent.message.TimerSchedulerMessage; + +import java.util.Timer; +import java.util.TimerTask; + +/** + * Initializes a timer within a constructor during its attachment to the executor + * Runs in a thread separate from executor - maybe refactor so that it's attached to executor's thread + * + * Handle used to attach tasks to schedule + * Tasks declared as inherited from TimerTask + * + * TODO: add request id and custom time + */ +public class TimerScheduler extends Module { + private Timer timer; + + public TimerScheduler(AgentMessage.AgentModule moduleType) { + super(moduleType); + this.timer = new Timer(); + System.out.println("TimerScheduler instance initialized"); + } + + @Override + public void handle(AgentMessage event) throws InterruptedException { + TimerSchedulerMessage timerEvent = (TimerSchedulerMessage) event; + this.timer.schedule(timerEvent.getTask(), timerEvent.getDelay()); + System.out.println("Task with delay " + timerEvent.getDelay() + " scheduled"); + } +} diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java deleted file mode 100644 index 6408a52..0000000 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java +++ /dev/null @@ -1,32 +0,0 @@ -package pl.edu.mimuw.cloudatlas.agent.timer; - -import java.util.Timer; -import java.util.TimerTask; - -/** - * Initializes a timer within a constructor during its attachment to the executor - * Runs in a thread separate from executor - maybe refactor so that it's attached to executor's thread - * - * Handle used to attach tasks to schedule - * Tasks declared as inherited from TimerTask - * - * TODO: add request id and custom time - */ -public class TimerScheduler { - private Timer timer; - - TimerScheduler() { - this.timer = new Timer(); - System.out.println("TimerScheduler instance initialized"); - } - - public void handle(TimerTask task, long delay, long period) { - this.timer.scheduleAtFixedRate(task, delay, period); - System.out.println("Task with delay " + delay + " and period " + period + " scheduled"); - } - - public void handle(TimerTask task, long delay) { - this.timer.schedule(task, delay); - System.out.println("Task with delay " + delay + " scheduled"); - } -} |