From 9325737ff613f7f14e44338b68ab657e0ed52d37 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sun, 5 Jan 2020 15:24:36 +0100 Subject: Don't apply stale zone updates --- .../edu/mimuw/cloudatlas/agent/modules/Stanik.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java index 3e5b790..1b1824f 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java @@ -34,12 +34,14 @@ public class Stanik extends Module { private ZMI hierarchy; private HashMap> queries; + private long freshnessPeriod; public Stanik() { super(ModuleType.STATE); hierarchy = new ZMI(); queries = new HashMap>(); hierarchy.getAttributes().add("timestamp", new ValueTime(0l)); + freshnessPeriod = 60 * 1000; } public void handleTyped(StanikMessage message) throws InterruptedException, InvalidMessageType { @@ -113,13 +115,20 @@ public class Stanik extends Module { public void handleUpdateAttributes(UpdateAttributesMessage message) { try { validateUpdateAttributesMessage(message); - addMissingZones(new PathName(message.getPathName())); - ZMI zone = hierarchy.findDescendant(message.getPathName()); - AttributesMap attributes = zone.getAttributes(); - if (ValueUtils.valueLower(attributes.get("timestamp"), message.getAttributes().get("timestamp"))) { - AttributesUtil.transferAttributes(message.getAttributes(), attributes); + if (!ValueUtils.valueLower( + message.getAttributes().get("timestamp"), + new ValueTime(System.currentTimeMillis() - freshnessPeriod) + )) { + addMissingZones(new PathName(message.getPathName())); + ZMI zone = hierarchy.findDescendant(message.getPathName()); + AttributesMap attributes = zone.getAttributes(); + if (ValueUtils.valueLower(attributes.get("timestamp"), message.getAttributes().get("timestamp"))) { + AttributesUtil.transferAttributes(message.getAttributes(), attributes); + } else { + System.out.println("DEBUG: not applying update with older attributes"); + } } else { - System.out.println("DEBUG: not applying update with older attributes"); + System.out.println("DEBUG: not applying update with stale attributes"); } } catch (InvalidUpdateAttributesMessage e) { System.out.println("ERROR: invalid UpdateAttributesMessage " + e.getMessage()); -- cgit v1.2.3