m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java12
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java18
2 files changed, 27 insertions, 3 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java
index 4b933b5..7a0da70 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java
@@ -1,7 +1,19 @@
package pl.edu.mimuw.cloudatlas.agent.modules;
+import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage;
+
import java.util.TimerTask;
public abstract class TimerScheduledTask extends TimerTask {
+ private TimerScheduler scheduler;
+
public abstract void run();
+
+ public void setScheduler(TimerScheduler scheduler) {
+ this.scheduler = scheduler;
+ }
+
+ protected void sendMessage(AgentMessage msg) throws InterruptedException {
+ this.scheduler.passMessageFromTask(msg);
+ }
}
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
index a08d060..9390940 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java
@@ -13,7 +13,6 @@ import java.util.Timer;
* Tasks declared as inherited from TimerTask
*
* TODO: add request id and custom time
- * TODO: enable messaging from scheduled tasks
*/
public class TimerScheduler extends Module {
private Timer timer;
@@ -29,7 +28,20 @@ public class TimerScheduler extends Module {
public void handle(AgentMessage event) throws InterruptedException {
assert event.getDestinationModule() == event.getCorrectMessageType();
TimerSchedulerMessage timerEvent = (TimerSchedulerMessage) event;
- this.timer.schedule(timerEvent.getTask(), timerEvent.getDelay());
- System.out.println("Task with delay " + timerEvent.getDelay() + " scheduled");
+ addTask(timerEvent);
+ }
+
+ public void addTask(TimerSchedulerMessage msg) {
+ TimerScheduledTask task = msg.getTask();
+ task.setScheduler(this);
+ this.timer.schedule(task, msg.getDelay());
+ System.out.println("Task with delay " + msg.getDelay() + " scheduled");
+ }
+
+ // TODO
+ public void removeTask(String requestId) {}
+
+ public void passMessageFromTask(AgentMessage msg) throws InterruptedException {
+ this.executor.passMessage(msg);
}
}