From 22ec12d762db07b6ecc65462b1e7cb38c8ca1578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sat, 11 Jan 2020 20:06:14 +0100 Subject: Refactor agent configs nicely --- .../java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 44 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 4 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 690198b..a7d2d55 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -1,19 +1,55 @@ package pl.edu.mimuw.cloudatlas.agent; +import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage; +import pl.edu.mimuw.cloudatlas.interpreter.Main; +import pl.edu.mimuw.cloudatlas.model.PathName; +import pl.edu.mimuw.cloudatlas.model.ZMI; + public class Agent { + private static void addZoneAndChildren(ZMI zmi, PathName pathName, EventBus eventBus) { + try { + UpdateAttributesMessage message = new UpdateAttributesMessage("", 0, pathName.toString(), zmi.getAttributes()); + eventBus.addMessage(message); + for (ZMI son : zmi.getSons()) { + addZoneAndChildren(son, pathName.levelDown(son.getAttributes().getOrNull("name").toString()), eventBus); + } + } catch (Exception e) { + System.out.println("ERROR: failed to add zone"); + } + } + + public static void initZones(EventBus eventBus) { + try { + ZMI root = Main.createTestHierarchy2(); + addZoneAndChildren(root, new PathName(""), eventBus); + System.out.println("Initialized with test hierarchy"); + } catch (Exception e) { + System.out.println("ERROR: failed to create test hierarchy"); + } + } + public static void main(String[] args) { AgentConfig agentConfig = new AgentConfig(); agentConfig.runModulesAsThreads(); - agentConfig.runRegistry(); - HierarchyConfig hierarchyConfig = new HierarchyConfig(agentConfig.getEventBus()); - hierarchyConfig.initZones(); + EventBus eventBus = new EventBus(agentConfig.getExecutors()); + agentConfig.runRegistry(eventBus); + agentConfig.startNonModuleThreads(eventBus); + + initZones(eventBus); + // TODO: make query period confiurable with config file and from tests + + // TODO config setup + String zonePath = System.getProperty("zone_path"); + String selectionStrategy = System.getProperty("Gossip.zone_strategy"); Long queryPeriod = Long.getLong("query_period"); - hierarchyConfig.startQueries(queryPeriod); Long gossipPeriod = Long.getLong("gossip_period"); + + HierarchyConfig hierarchyConfig = new HierarchyConfig(eventBus, zonePath, selectionStrategy); + hierarchyConfig.startQueries(queryPeriod); hierarchyConfig.startGossip(gossipPeriod); } } -- cgit v1.2.3