From 237a7caa6971b67d6f98aa4f2aae3cbab7d86def Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sat, 4 Jan 2020 16:18:22 +0100 Subject: Run queries on an interval --- .../java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.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 70da4af..0efa710 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -6,14 +6,19 @@ import java.rmi.server.UnicastRemoteObject; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.function.Supplier; import pl.edu.mimuw.cloudatlas.agent.NewApiImplementation; +import pl.edu.mimuw.cloudatlas.agent.messages.RunQueriesMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.TimerSchedulerMessage; import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage; 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.Remik; import pl.edu.mimuw.cloudatlas.agent.modules.Stanik; +import pl.edu.mimuw.cloudatlas.agent.modules.RecursiveScheduledTask; +import pl.edu.mimuw.cloudatlas.agent.modules.TimerScheduledTask; import pl.edu.mimuw.cloudatlas.agent.modules.TimerScheduler; import pl.edu.mimuw.cloudatlas.api.Api; import pl.edu.mimuw.cloudatlas.interpreter.Main; @@ -101,11 +106,30 @@ public class Agent { } } + private static void startQueries(long queriesPeriod) { + Supplier taskSupplier = () -> + new TimerScheduledTask() { + public void run() { + try { + sendMessage(new RunQueriesMessage("", 0)); + } catch (InterruptedException e) { + System.out.println("Interrupted while triggering queries"); + } + } + }; + + TimerScheduledTask timerTask = new RecursiveScheduledTask(queriesPeriod, taskSupplier); + + try { + eventBus.addMessage(new TimerSchedulerMessage("", 0, "", queriesPeriod, 0, timerTask)); + } catch (InterruptedException e) { + System.out.println("Interrupted while starting queries"); + } + } + private static void addZoneAndChildren(ZMI zmi, PathName pathName) { try { - System.out.println("trying to add " + pathName.toString()); UpdateAttributesMessage message = new UpdateAttributesMessage("", 0, pathName.toString(), zmi.getAttributes()); - System.out.println("added it!"); eventBus.addMessage(message); for (ZMI son : zmi.getSons()) { addZoneAndChildren(son, pathName.levelDown(son.getAttributes().getOrNull("name").toString())); @@ -119,5 +143,7 @@ public class Agent { runModulesAsThreads(); runRegistry(); initZones(); + // TODO: make query period confiurable with config file and from tests + startQueries(100l); } } -- cgit v1.2.3