From edec7f92b20f1f873083bdf3198283fa822e0f64 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sun, 12 Jan 2020 16:36:42 +0100 Subject: Start removing old gossips --- src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 3 +++ .../pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java | 16 ++++++++++++++++ .../java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java | 4 ++++ 3 files changed, 23 insertions(+) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') 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 24ed0c1..06e067b 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -46,9 +46,12 @@ public class Agent { String selectionStrategy = System.getProperty("Gossip.zone_strategy"); Long queryPeriod = Long.getLong("query_period"); Long gossipPeriod = Long.getLong("gossip_period"); + Long freshnessPeriod = Long.getLong("freshness_period"); HierarchyConfig hierarchyConfig = new HierarchyConfig(eventBus, zonePath, selectionStrategy); hierarchyConfig.startQueries(queryPeriod); hierarchyConfig.startGossip(gossipPeriod, zonePath); + // TODO: should this be different than ZMI freshness period? + hierarchyConfig.startCleaningGossips(freshnessPeriod); } } diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java index f9e323a..92b7f66 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java @@ -153,4 +153,20 @@ public class HierarchyConfig { AgentUtils.startRecursiveTask(taskSupplier, queriesPeriod, eventBus); } + + public void startCleaningGossips(long gossipCleanPeriod) { + Supplier taskSupplier = () -> + new TimerScheduledTask() { + public void run() { + try { + System.out.println("INFO: Scheduling old gossip cleanup"); + sendMessage(new CleanOldGossipsMessage("", 0, ValueUtils.addToTime(ValueUtils.currentTime(), -gossipCleanPeriod))); + } catch (InterruptedException e) { + System.out.println("Interrupted while triggering queries"); + } + } + }; + + AgentUtils.startRecursiveTask(taskSupplier, gossipCleanPeriod, eventBus); + } } diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java index 3df8231..866349f 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java @@ -12,4 +12,8 @@ public class ValueUtils { public static ValueTime currentTime() { return new ValueTime(System.currentTimeMillis()); } + + public static ValueTime addToTime(ValueTime time, long millis) { + return time.addValue(new ValueDuration(millis)); + } } -- cgit v1.2.3