diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-01-05 15:24:36 +0100 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-01-05 15:24:36 +0100 |
commit | 9325737ff613f7f14e44338b68ab657e0ed52d37 (patch) | |
tree | 77777e499ff7c4d9a660b9e0ec186f7743fd562d /src/main/java/pl/edu/mimuw/cloudatlas/agent/modules | |
parent | 69480d460a698a78b90d8d111f5fb4d761ffda81 (diff) |
Don't apply stale zone updates
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java | 21 |
1 files changed, 15 insertions, 6 deletions
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<Attribute, Entry<ValueQuery, ValueTime>> queries; + private long freshnessPeriod; public Stanik() { super(ModuleType.STATE); hierarchy = new ZMI(); queries = new HashMap<Attribute, Entry<ValueQuery, ValueTime>>(); 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()); |