From c6f148b33422f0d1660a4289f413193011736475 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 30 Dec 2019 11:46:07 +0100 Subject: Test multiple queries in Qurnik --- .../pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java | 5 ++++- .../pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java | 18 ++---------------- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java index 3864aba..9b7268a 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java @@ -15,6 +15,7 @@ import pl.edu.mimuw.cloudatlas.interpreter.InterpreterException; import pl.edu.mimuw.cloudatlas.interpreter.QueryResult; import pl.edu.mimuw.cloudatlas.model.Attribute; import pl.edu.mimuw.cloudatlas.model.AttributesMap; +import pl.edu.mimuw.cloudatlas.model.AttributesUtil; import pl.edu.mimuw.cloudatlas.model.PathName; import pl.edu.mimuw.cloudatlas.model.TypePrimitive; import pl.edu.mimuw.cloudatlas.model.Value; @@ -92,9 +93,11 @@ public class Qurnik extends Module { if (!currentPath.toString().equals("/")) { newAttributes.add("name", new ValueString(currentPath.getSingletonName())); } - long currentTime = System.currentTimeMillis() / 1000; + long currentTime = System.currentTimeMillis(); newAttributes.add("timestamp", new ValueTime(currentTime)); + AttributesUtil.transferAttributes(newAttributes, zmi.getAttributes()); + UpdateAttributesMessage message = new UpdateAttributesMessage("", currentTime, currentPath.toString(), newAttributes); sendMessage(message); } 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 e8721b3..4694219 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 @@ -12,6 +12,7 @@ import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage; import pl.edu.mimuw.cloudatlas.agent.messages.UpdateQueriesMessage; import pl.edu.mimuw.cloudatlas.model.Attribute; import pl.edu.mimuw.cloudatlas.model.AttributesMap; +import pl.edu.mimuw.cloudatlas.model.AttributesUtil; import pl.edu.mimuw.cloudatlas.model.PathName; import pl.edu.mimuw.cloudatlas.model.Type; import pl.edu.mimuw.cloudatlas.model.TypePrimitive; @@ -67,7 +68,7 @@ public class Stanik extends Module { ZMI zone = hierarchy.findDescendant(message.getPathName()); AttributesMap attributes = zone.getAttributes(); if (valueLower(attributes.get("timestamp"), message.getAttributes().get("timestamp"))) { - transferAttributes(message.getAttributes(), attributes); + AttributesUtil.transferAttributes(message.getAttributes(), attributes); } else { System.out.println("DEBUG: not applying update with older attributes"); } @@ -127,21 +128,6 @@ public class Stanik extends Module { return value != null && !value.isNull() && value.getType().isCompatible(type); } - private void transferAttributes(AttributesMap fromAttributes, AttributesMap toAttributes) { - Iterator> iterator = toAttributes.iterator(); - while (iterator.hasNext()) { - Entry entry = iterator.next(); - Attribute attribute = entry.getKey(); - Value newValue = fromAttributes.getOrNull(attribute); - if (newValue == null) { - iterator.remove(); - } - } - for (Entry entry : fromAttributes) { - toAttributes.addOrChange(entry.getKey(), entry.getValue()); - } - } - private void addMissingZones(PathName path) { try { if (!hierarchy.descendantExists(path)) { -- cgit v1.2.3