From 83feb6ad13187af9be55cc71408611f67d280955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Tue, 14 Jan 2020 21:28:10 +0100 Subject: Fix timestamps and ValueQuery --- .../mimuw/cloudatlas/agent/modules/GossipGirl.java | 10 +++++----- .../cloudatlas/agent/modules/GossipGirlState.java | 10 +++++----- .../edu/mimuw/cloudatlas/agent/modules/Qurnik.java | 5 +++-- .../edu/mimuw/cloudatlas/agent/modules/Stanik.java | 20 +++++++++++--------- 4 files changed, 24 insertions(+), 21 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java index 5199e82..b6087e6 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java @@ -200,11 +200,11 @@ public class GossipGirl extends Module { System.out.println("INFO: handling Query in " + Long.toString(message.getReceiverGossipId())); state.setLastAction(); state.gotQuery(message); - Map> queries = new HashMap(); - queries.put( - message.getName(), - new SimpleImmutableEntry(message.getQuery(), state.getTheirQueryTimestamp(message.getName())) - ); + Map queries = new HashMap(); + ValueQuery vq = message.getQuery(); + ValueTime timestamp = state.getTheirQueryTimestamp(message.getName()); + vq.setTimestamp(timestamp.getValue()); + queries.put(message.getName(), vq); UpdateQueriesMessage updateMessage = new UpdateQueriesMessage("", 0, queries); System.out.println("INFO: GossipGirl sending UpdateQueriesMessage"); sendMessage(updateMessage); diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java index cfaf560..4709eb1 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java @@ -47,7 +47,7 @@ public class GossipGirlState { public long timeOffest; public State state; public ZMI hierarchy; - public Map> queries; + public Map queries; public ValueTime hejkaSendTimestamp; public ValueTime hejkaReceiveTimestamp; public ValueTime noCoTamSendTimestamp; @@ -79,7 +79,7 @@ public class GossipGirlState { lastAction = ValueUtils.currentTime(); } - public void setState(ZMI hierarchy, Map> queries) { + public void setState(ZMI hierarchy, Map queries) { switch (state) { case WAIT_FOR_STATE_INITIALIZER: this.hierarchy = hierarchy; @@ -211,8 +211,8 @@ public class GossipGirlState { public Map getQueryTimestampsToSend() { Map queryTimestamps= new HashMap(); - for (Entry> query : queries.entrySet()) { - queryTimestamps.put(query.getKey(), query.getValue().getValue()); + for (Entry query : queries.entrySet()) { + queryTimestamps.put(query.getKey(), new ValueTime(query.getValue().getTimestamp())); } return queryTimestamps; @@ -259,7 +259,7 @@ public class GossipGirlState { queryList.add( new SimpleImmutableEntry( name, - queries.get(name).getKey() + queries.get(name) ) ); } 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 2119653..9a544d9 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 @@ -59,13 +59,14 @@ public class Qurnik extends Module { private void runQueriesOnState(StateMessage message) throws InterruptedException { List queries = new LinkedList(); - for (Entry timestampedQuery : message.getQueries().values()) { - queries.add(timestampedQuery.getKey()); + for (ValueQuery timestampedQuery : message.getQueries().values()) { + queries.add(timestampedQuery); } executeAllQueries(message.getZMI(), queries, PathName.ROOT); } private void executeAllQueries(ZMI zmi, List queries, PathName currentPath) throws InterruptedException { + System.out.println("INFO: Qurnik executing all queries " + queries); if(!zmi.getSons().isEmpty()) { for(ZMI son : zmi.getSons()) { Value sonName = son.getAttributes().getOrNull("name"); 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 6e7d4dc..9e2a603 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 @@ -16,7 +16,7 @@ public class Stanik extends Module { } private ZMI hierarchy; - private HashMap> queries; + private HashMap queries; private long freshnessPeriod; private Set contacts; private ValueTime contactsTimestamp; @@ -26,7 +26,7 @@ public class Stanik extends Module { super(ModuleType.STATE); this.ourPath = ourPath; hierarchy = new ZMI(); - queries = new HashMap>(); + queries = new HashMap(); hierarchy.getAttributes().add("timestamp", new ValueTime(0l)); this.freshnessPeriod = freshnessPeriod; this.contactsTimestamp = ValueUtils.currentTime(); @@ -45,7 +45,7 @@ public class Stanik extends Module { private void setDefaultQuery(String name, String query) { try { ValueQuery queryValue = new ValueQuery(query); - queries.put(new Attribute(name), new SimpleImmutableEntry(queryValue, new ValueTime(0l))); + queries.put(new Attribute(name), queryValue); } catch (Exception e) { System.out.println("ERROR: failed to compile default query"); } @@ -89,7 +89,7 @@ public class Stanik extends Module { 0, message.getRequestId(), hierarchy.clone(), - (HashMap>) queries.clone(), + (HashMap) queries.clone(), contacts ); sendMessage(response); @@ -210,11 +210,13 @@ public class Stanik extends Module { } public void handleUpdateQueries(UpdateQueriesMessage message) { - for (Entry> entry : message.getQueries().entrySet()) { + System.out.println("INFO: Stanik handles update queries"); + for (Entry entry : message.getQueries().entrySet()) { Attribute attribute = entry.getKey(); - ValueTime timestamp = entry.getValue().getValue(); - Entry currentTimestampedQuery = queries.get(attribute); - if (currentTimestampedQuery == null || ValueUtils.valueLower(currentTimestampedQuery.getValue(), timestamp)) { + ValueTime timestamp = new ValueTime(entry.getValue().getTimestamp()); + ValueQuery currentTimestampedQuery = queries.get(attribute); + ValueTime currentQueryTimestamp = new ValueTime(currentTimestampedQuery.getTimestamp()); + if (currentQueryTimestamp == null || ValueUtils.valueLower(currentQueryTimestamp, timestamp)) { queries.put(entry.getKey(), entry.getValue()); } } @@ -273,7 +275,7 @@ public class Stanik extends Module { return hierarchy; } - public HashMap> getQueries() { + public HashMap getQueries() { return queries; } -- cgit v1.2.3