From b9f576727fef502fade2370e309d8b238a6a6214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sun, 22 Dec 2019 13:26:55 +0100 Subject: Add simple scheduler class - no request id or custom time --- .../cloudatlas/agent/timer/TimerScheduler.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java (limited to 'src/main/java') 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 new file mode 100644 index 0000000..8eddb21 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java @@ -0,0 +1,27 @@ +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 + */ +public class TimerScheduler { + private Timer timer; + + TimerScheduler() { + this.timer = new Timer(); + } + + public void handle(TimerTask task, long delay, long period) { + this.timer.scheduleAtFixedRate(task, delay, period); + } + + public void handle(TimerTask task, long delay) { + this.timer.schedule(task, delay); + } +} -- cgit v1.2.3 From cf8373137e283736620da5cb225907671fa83d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sun, 22 Dec 2019 13:27:20 +0100 Subject: Add task skeleton --- .../edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java (limited to 'src/main/java') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java new file mode 100644 index 0000000..d9bd2d2 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java @@ -0,0 +1,11 @@ +package pl.edu.mimuw.cloudatlas.agent.timer; + +import java.util.TimerTask; + +public class TimerScheduledTask extends TimerTask { + + @Override + public void run() { + + } +} -- cgit v1.2.3 From 45aad6c3b76c294ce217883b3b3add3ccc7abc14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sun, 22 Dec 2019 13:28:44 +0100 Subject: Add todo comment --- src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main/java') 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 index 8eddb21..6eef931 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java @@ -9,6 +9,8 @@ import java.util.TimerTask; * * 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; -- cgit v1.2.3 From 9d24163dc71c345fb2197f91abb62478e1e9e3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sun, 22 Dec 2019 14:21:52 +0100 Subject: Add log messages --- src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/main/java') 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 index 6eef931..6408a52 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java @@ -17,13 +17,16 @@ public class TimerScheduler { 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"); } } -- cgit v1.2.3 From 4c728b0ba906799afd30f0a337b540cf167a0cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 23 Dec 2019 19:50:46 +0100 Subject: Make timer inherit from module, move to modules package --- .../java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 2 +- .../pl/edu/mimuw/cloudatlas/agent/Executor.java | 1 + .../java/pl/edu/mimuw/cloudatlas/agent/Module.java | 30 -------------------- .../edu/mimuw/cloudatlas/agent/modules/Module.java | 31 ++++++++++++++++++++ .../agent/modules/TimerScheduledTask.java | 11 ++++++++ .../cloudatlas/agent/modules/TimerScheduler.java | 33 ++++++++++++++++++++++ .../cloudatlas/agent/timer/TimerScheduledTask.java | 11 -------- .../cloudatlas/agent/timer/TimerScheduler.java | 32 --------------------- 8 files changed, 77 insertions(+), 74 deletions(-) delete mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/Module.java create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java delete mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java delete mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduler.java (limited to 'src/main/java') 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/Module.java deleted file mode 100644 index 167f3b7..0000000 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Module.java +++ /dev/null @@ -1,30 +0,0 @@ -package pl.edu.mimuw.cloudatlas.agent; - -import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; - -/* - * A Module is a (potentially stateful) event handler. - */ -public abstract class Module { - private AgentMessage.AgentModule moduleType; - private Executor executor; - - Module(AgentMessage.AgentModule moduleType) { - this.moduleType = moduleType; - } - - public abstract void handle(AgentMessage event) throws InterruptedException ; - - public void setExecutor(Executor executor) { - this.executor = executor; - } - - public void sendMessage(AgentMessage event) throws InterruptedException { - this.executor.passMessage(event); - } - - @Override - public String toString() { - return moduleType.toString(); - } -} 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 new file mode 100644 index 0000000..dd6a5f8 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java @@ -0,0 +1,31 @@ +package pl.edu.mimuw.cloudatlas.agent.modules; + +import pl.edu.mimuw.cloudatlas.agent.Executor; +import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; + +/* + * A Module is a (potentially stateful) event handler. + */ +public abstract class Module { + private AgentMessage.AgentModule moduleType; + private Executor executor; + + public Module(AgentMessage.AgentModule moduleType) { + this.moduleType = moduleType; + } + + public abstract void handle(AgentMessage event) throws InterruptedException ; + + public void setExecutor(Executor executor) { + this.executor = executor; + } + + public void sendMessage(AgentMessage event) throws InterruptedException { + this.executor.passMessage(event); + } + + @Override + public String toString() { + return moduleType.toString(); + } +} 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 new file mode 100644 index 0000000..db9dd26 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java @@ -0,0 +1,11 @@ +package pl.edu.mimuw.cloudatlas.agent.modules; + +import java.util.TimerTask; + +public class TimerScheduledTask extends TimerTask { + + @Override + public void run() { + + } +} 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/TimerScheduledTask.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java deleted file mode 100644 index d9bd2d2..0000000 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/timer/TimerScheduledTask.java +++ /dev/null @@ -1,11 +0,0 @@ -package pl.edu.mimuw.cloudatlas.agent.timer; - -import java.util.TimerTask; - -public class TimerScheduledTask extends TimerTask { - - @Override - public void run() { - - } -} 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"); - } -} -- cgit v1.2.3 From 219431065b335fdf250394ba66da8220d9bb868f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 23 Dec 2019 19:54:24 +0100 Subject: Rename messages package --- .../java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 2 +- .../pl/edu/mimuw/cloudatlas/agent/EventBus.java | 2 +- .../pl/edu/mimuw/cloudatlas/agent/Executor.java | 2 +- .../cloudatlas/agent/message/AgentMessage.java | 57 ---------------------- .../agent/message/TimerSchedulerMessage.java | 46 ----------------- .../cloudatlas/agent/messages/AgentMessage.java | 57 ++++++++++++++++++++++ .../agent/messages/TimerSchedulerMessage.java | 46 +++++++++++++++++ .../edu/mimuw/cloudatlas/agent/modules/Module.java | 2 +- .../cloudatlas/agent/modules/TimerScheduler.java | 4 +- 9 files changed, 109 insertions(+), 109 deletions(-) delete mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/message/AgentMessage.java delete mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/message/TimerSchedulerMessage.java create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/TimerSchedulerMessage.java (limited to 'src/main/java') 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 e695773..4bd522d 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -8,7 +8,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; import pl.edu.mimuw.cloudatlas.agent.modules.Module; import pl.edu.mimuw.cloudatlas.api.Api; import pl.edu.mimuw.cloudatlas.interpreter.Main; 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 afb4e27..8cdda62 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java @@ -1,6 +1,6 @@ package pl.edu.mimuw.cloudatlas.agent; -import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; import java.util.HashMap; import java.util.Iterator; 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 6d29d13..6ebf6a6 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Executor.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Executor.java @@ -2,7 +2,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.messages.AgentMessage; import pl.edu.mimuw.cloudatlas.agent.modules.Module; /* diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/message/AgentMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/message/AgentMessage.java deleted file mode 100644 index 6e8f51c..0000000 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/message/AgentMessage.java +++ /dev/null @@ -1,57 +0,0 @@ -package pl.edu.mimuw.cloudatlas.agent.message; - -import pl.edu.mimuw.cloudatlas.agent.Agent; - -public class AgentMessage { - - public enum AgentModule { - TIMER_SCHEDULER, - TIMER_GTP, - RMI, - UDP, - GOSSIP_IN, - GOSSIP_OUT, - STATE, - QUERY - } - - private String messageId; - private AgentModule destinationModule; - private long timestamp; - - public AgentMessage(String messageId, AgentModule destinationModule, long timestamp) { - this.messageId = messageId; - this.destinationModule = destinationModule; - this.timestamp = timestamp; - } - - public AgentMessage(String messageId, AgentModule destinationModule) { - this.messageId = messageId; - this.destinationModule = destinationModule; - this.timestamp = System.currentTimeMillis() / 1000L; - } - - public String getMessageId() { - return messageId; - } - - public void setMessageId(String messageId) { - this.messageId = messageId; - } - - public AgentModule getDestinationModule() { - return destinationModule; - } - - public void setDestinationModule(AgentModule destinationModule) { - this.destinationModule = destinationModule; - } - - public long getTimestamp() { - return timestamp; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } -} diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/message/TimerSchedulerMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/message/TimerSchedulerMessage.java deleted file mode 100644 index 9743533..0000000 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/message/TimerSchedulerMessage.java +++ /dev/null @@ -1,46 +0,0 @@ -package pl.edu.mimuw.cloudatlas.agent.message; - -import java.util.TimerTask; - -public class TimerSchedulerMessage extends AgentMessage { - private String requestId; - private long delay; - private long baseTime; - private TimerTask task; - - public TimerSchedulerMessage(String messageId, AgentModule destinationModule, long timestamp, String requestId, long delay, long baseTime, TimerTask task) { - super(messageId, destinationModule, timestamp); - this.requestId = requestId; - this.delay = delay; - this.baseTime = baseTime; - this.task = task; - } - - public long getDelay() { - return delay; - } - - public void setDelay(long delay) { - this.delay = delay; - } - - public long getBaseTime() { - return baseTime; - } - - public void setBaseTime(long baseTime) { - this.baseTime = baseTime; - } - - public TimerTask getTask() { - return task; - } - - public void setTask(TimerTask task) { - this.task = task; - } - - public String getRequestId() { return requestId; } - - public void setRequestId(String requestId) { this.requestId = requestId; } -} 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 new file mode 100644 index 0000000..4f5a69c --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java @@ -0,0 +1,57 @@ +package pl.edu.mimuw.cloudatlas.agent.messages; + +import pl.edu.mimuw.cloudatlas.agent.Agent; + +public class AgentMessage { + + public enum AgentModule { + TIMER_SCHEDULER, + TIMER_GTP, + RMI, + UDP, + GOSSIP_IN, + GOSSIP_OUT, + STATE, + QUERY + } + + private String messageId; + private AgentModule destinationModule; + private long timestamp; + + public AgentMessage(String messageId, AgentModule destinationModule, long timestamp) { + this.messageId = messageId; + this.destinationModule = destinationModule; + this.timestamp = timestamp; + } + + public AgentMessage(String messageId, AgentModule destinationModule) { + this.messageId = messageId; + this.destinationModule = destinationModule; + this.timestamp = System.currentTimeMillis() / 1000L; + } + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public AgentModule getDestinationModule() { + return destinationModule; + } + + public void setDestinationModule(AgentModule destinationModule) { + this.destinationModule = destinationModule; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } +} 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 new file mode 100644 index 0000000..23ec700 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/TimerSchedulerMessage.java @@ -0,0 +1,46 @@ +package pl.edu.mimuw.cloudatlas.agent.messages; + +import java.util.TimerTask; + +public class TimerSchedulerMessage extends AgentMessage { + private String requestId; + private long delay; + private long baseTime; + private TimerTask task; + + public TimerSchedulerMessage(String messageId, AgentModule destinationModule, long timestamp, String requestId, long delay, long baseTime, TimerTask task) { + super(messageId, destinationModule, timestamp); + this.requestId = requestId; + this.delay = delay; + this.baseTime = baseTime; + this.task = task; + } + + public long getDelay() { + return delay; + } + + public void setDelay(long delay) { + this.delay = delay; + } + + public long getBaseTime() { + return baseTime; + } + + public void setBaseTime(long baseTime) { + this.baseTime = baseTime; + } + + public TimerTask getTask() { + return task; + } + + public void setTask(TimerTask task) { + this.task = task; + } + + public String getRequestId() { return requestId; } + + public void setRequestId(String requestId) { this.requestId = requestId; } +} 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 dd6a5f8..04d002d 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 @@ -1,7 +1,7 @@ package pl.edu.mimuw.cloudatlas.agent.modules; import pl.edu.mimuw.cloudatlas.agent.Executor; -import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; /* * A Module is a (potentially stateful) event handler. 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 b7ce435..8f6c2f0 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 @@ -1,7 +1,7 @@ package pl.edu.mimuw.cloudatlas.agent.modules; -import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage; -import pl.edu.mimuw.cloudatlas.agent.message.TimerSchedulerMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.TimerSchedulerMessage; import java.util.Timer; import java.util.TimerTask; -- cgit v1.2.3 From 23c86416390fdbcfc8d749e9117564d25c7ef729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 23 Dec 2019 19:56:37 +0100 Subject: Import fixes --- src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java | 2 -- src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java | 1 - 2 files changed, 3 deletions(-) (limited to 'src/main/java') 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 4f5a69c..31fc6f8 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,7 +1,5 @@ package pl.edu.mimuw.cloudatlas.agent.messages; -import pl.edu.mimuw.cloudatlas.agent.Agent; - public class AgentMessage { public enum AgentModule { 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 8f6c2f0..921f985 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 @@ -4,7 +4,6 @@ import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; import pl.edu.mimuw.cloudatlas.agent.messages.TimerSchedulerMessage; import java.util.Timer; -import java.util.TimerTask; /** * Initializes a timer within a constructor during its attachment to the executor -- cgit v1.2.3 From 054c14ae3d1c2f02d6012c6133fa78c5a1a15c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 23 Dec 2019 23:22:57 +0100 Subject: Make scheduled task abstract --- src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java | 2 ++ .../java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java | 1 + .../pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduledTask.java | 8 ++------ 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src/main/java') 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 8cdda62..b84d693 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java @@ -43,11 +43,13 @@ public class EventBus implements Runnable { } public void routeMessage(AgentMessage msg) throws InterruptedException { + assert msg.correctType == msg.getDestinationModule(); System.out.println("Event bus routing message"); executors.get(msg.getDestinationModule()).addMessage(msg); } public void addMessage(AgentMessage msg) throws InterruptedException { + assert msg.correctType == msg.getDestinationModule(); this.events.put(msg); } } 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 31fc6f8..ba15a7a 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,6 +1,7 @@ package pl.edu.mimuw.cloudatlas.agent.messages; public class AgentMessage { + public AgentModule correctType; public enum AgentModule { TIMER_SCHEDULER, 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 db9dd26..4b933b5 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 @@ -2,10 +2,6 @@ package pl.edu.mimuw.cloudatlas.agent.modules; import java.util.TimerTask; -public class TimerScheduledTask extends TimerTask { - - @Override - public void run() { - - } +public abstract class TimerScheduledTask extends TimerTask { + public abstract void run(); } -- cgit v1.2.3 From 6bd93c4fc80624eb83e9a1eb9b93e5781a796505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 23 Dec 2019 23:27:01 +0100 Subject: Fix agent message type checks --- src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java | 4 ++-- .../java/pl/edu/mimuw/cloudatlas/agent/messages/AgentMessage.java | 5 +++-- .../edu/mimuw/cloudatlas/agent/messages/TimerSchedulerMessage.java | 5 +++++ .../java/pl/edu/mimuw/cloudatlas/agent/modules/TimerScheduler.java | 3 +++ 4 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src/main/java') 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 b84d693..37c125a 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java @@ -43,13 +43,13 @@ public class EventBus implements Runnable { } public void routeMessage(AgentMessage msg) throws InterruptedException { - assert msg.correctType == msg.getDestinationModule(); + assert msg.getCorrectMessageType() == msg.getDestinationModule(); System.out.println("Event bus routing message"); executors.get(msg.getDestinationModule()).addMessage(msg); } public void addMessage(AgentMessage msg) throws InterruptedException { - assert msg.correctType == msg.getDestinationModule(); + assert msg.getCorrectMessageType() == msg.getDestinationModule(); this.events.put(msg); } } 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 ba15a7a..b71831f 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,7 +1,6 @@ package pl.edu.mimuw.cloudatlas.agent.messages; -public class AgentMessage { - public AgentModule correctType; +public abstract class AgentMessage { public enum AgentModule { TIMER_SCHEDULER, @@ -30,6 +29,8 @@ public class AgentMessage { this.timestamp = System.currentTimeMillis() / 1000L; } + public abstract AgentModule getCorrectMessageType(); + public String getMessageId() { return messageId; } 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 23ec700..9a558b7 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 @@ -43,4 +43,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; + } } 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 921f985..a08d060 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,18 +13,21 @@ 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; public TimerScheduler(AgentMessage.AgentModule moduleType) { super(moduleType); + assert moduleType == AgentMessage.AgentModule.TIMER_SCHEDULER; this.timer = new Timer(); System.out.println("TimerScheduler instance initialized"); } @Override 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"); -- cgit v1.2.3 From 26c750550b9fa6bdbebc8acbb39a34281205c140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 25 Dec 2019 12:53:39 +0100 Subject: Fix task type in timer message --- .../agent/messages/TimerSchedulerMessage.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/main/java') 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 9a558b7..333b381 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,14 +1,20 @@ package pl.edu.mimuw.cloudatlas.agent.messages; -import java.util.TimerTask; +import pl.edu.mimuw.cloudatlas.agent.modules.TimerScheduledTask; public class TimerSchedulerMessage extends AgentMessage { private String requestId; private long delay; private long baseTime; - private TimerTask task; - - public TimerSchedulerMessage(String messageId, AgentModule destinationModule, long timestamp, String requestId, long delay, long baseTime, TimerTask task) { + private TimerScheduledTask task; + + public TimerSchedulerMessage(String messageId, + AgentModule destinationModule, + long timestamp, + String requestId, + long delay, + long baseTime, + TimerScheduledTask task) { super(messageId, destinationModule, timestamp); this.requestId = requestId; this.delay = delay; @@ -32,11 +38,11 @@ public class TimerSchedulerMessage extends AgentMessage { this.baseTime = baseTime; } - public TimerTask getTask() { + public TimerScheduledTask getTask() { return task; } - public void setTask(TimerTask task) { + public void setTask(TimerScheduledTask task) { this.task = task; } -- cgit v1.2.3 From 8e8a49a7477042d5424ecf8ddc432d9297f3e005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 25 Dec 2019 12:54:37 +0100 Subject: Add messaging capability to tasks --- .../cloudatlas/agent/modules/TimerScheduledTask.java | 12 ++++++++++++ .../mimuw/cloudatlas/agent/modules/TimerScheduler.java | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src/main/java') 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); } } -- cgit v1.2.3 From 44b899400150c0183fede3b530ab9aa850fa4fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 25 Dec 2019 12:55:28 +0100 Subject: Fix access in module members --- src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java') 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 04d002d..9744971 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 @@ -7,8 +7,8 @@ import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; * A Module is a (potentially stateful) event handler. */ public abstract class Module { - private AgentMessage.AgentModule moduleType; - private Executor executor; + protected AgentMessage.AgentModule moduleType; + protected Executor executor; public Module(AgentMessage.AgentModule moduleType) { this.moduleType = moduleType; -- cgit v1.2.3