m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java13
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java55
2 files changed, 57 insertions, 11 deletions
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 01119bf..ccc7ee5 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
@@ -69,8 +69,8 @@ public class GossipGirl extends Module {
"",
0,
state.gossipId,
- getZoneTimestamps(message.getZMI()),
- getQueryTimestamps(message.getQueries())
+ state.getZoneTimestampsToSend(),
+ state.getQueryTimestampsToSend()
);
UDUPMessage udupMessage = new UDUPMessage("", 0, state.theirContact, hejka);
sendMessage(udupMessage);
@@ -96,13 +96,4 @@ public class GossipGirl extends Module {
System.out.println("ERROR: GossipGirl got state for a nonexistent gossip");
}
}
-
- public Map<PathName, ValueTime> getZoneTimestamps(ZMI root) {
- return new HashMap();
- }
-
- public Map<Attribute, ValueTime> getQueryTimestamps(Map<Attribute, Entry<ValueQuery, ValueTime>> queries) {
- return new HashMap();
- }
-
}
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 726a9b2..8ec8ed2 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
@@ -1,5 +1,7 @@
package pl.edu.mimuw.cloudatlas.agent.modules;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -95,10 +97,63 @@ public class GossipGirlState {
}
}
+ public Map<PathName, ValueTime> getZoneTimestampsToSend() {
+ Map<PathName, ValueTime> timestamps = new HashMap();
+ collectZoneTimestamps(timestamps, hierarchy, theirContact.getName());
+ return timestamps;
+ }
+
+ public Map<Attribute, ValueTime> getQueryTimestampsToSend() {
+ Map<Attribute, ValueTime> queryTimestamps= new HashMap();
+ for (Entry<Attribute, Entry<ValueQuery, ValueTime>> query : queries.entrySet()) {
+ queryTimestamps.put(query.getKey(), query.getValue().getValue());
+ }
+
+ return queryTimestamps;
+ }
+
public List<ZMI> getZMIsToSend() {
return new LinkedList();
}
+ public void collectZoneTimestamps(Map<PathName, ValueTime> timestamps, ZMI currentZMI, PathName recipientPath) {
+ for (ZMI zmi : currentZMI.getSons()) {
+ if (interestedIn(recipientPath, zmi.getPathName())) {
+ ValueTime timestamp = (ValueTime) zmi.getAttributes().getOrNull("timestamp");
+ if (timestamp != null) {
+ timestamps.put(zmi.getPathName(), timestamp);
+ } else {
+ System.out.println("ERROR: collectZoneTimestamps encountered a zone with no timestamp");
+ }
+ } else {
+ collectZoneTimestamps(timestamps, zmi, recipientPath);
+ }
+ }
+ }
+
+ public boolean interestedIn(PathName recipientPath, PathName zmiPath) {
+ return isPrefix(zmiPath.levelUp(), recipientPath) && !isPrefix(zmiPath, recipientPath);
+ }
+
+ public boolean isPrefix(PathName prefix, PathName path) {
+ List<String> prefixComponents = prefix.getComponents();
+ List<String> pathComponents = path.getComponents();
+
+ if (prefixComponents.size() > pathComponents.size()) {
+ return false;
+ }
+
+ Iterator<String> prefixIterator = prefixComponents.iterator();
+ Iterator<String> pathIterator = pathComponents.iterator();
+
+ while (prefixIterator.hasNext()) {
+ if (!prefixIterator.next().equals(pathIterator.next())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
public void sentInfo() {
switch (state) {
case SEND_INFO: