m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-12 22:12:09 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-12 22:12:09 +0100
commit411bf8f0dae524d70a0754049b5494182ade4a05 (patch)
tree0ca12678f5acf95ad4a5cfa64893ba06c5d5c615 /src/main/java/pl/edu/mimuw/cloudatlas/agent/modules
parent84df6c11a868e8cd98fa14455456d313e25234db (diff)
Set owner of ZMIs on our path
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java21
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java21
2 files changed, 14 insertions, 28 deletions
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 251d8b3..0525f41 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
@@ -280,26 +280,7 @@ public class GossipGirlState {
}
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;
+ return ValueUtils.isPrefix(zmiPath.levelUp(), recipientPath) && !ValueUtils.isPrefix(zmiPath, recipientPath);
}
public void sentInfo() {
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 f572efe..a428232 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
@@ -19,9 +19,11 @@ public class Stanik extends Module {
private long freshnessPeriod;
private Set<ValueContact> contacts;
private ValueTime contactsTimestamp;
+ private PathName ourPath;
- public Stanik(long freshnessPeriod) {
+ public Stanik(PathName ourPath, long freshnessPeriod) {
super(ModuleType.STATE);
+ this.ourPath = ourPath;
hierarchy = new ZMI();
queries = new HashMap<Attribute, Entry<ValueQuery, ValueTime>>();
hierarchy.getAttributes().add("timestamp", new ValueTime(0l));
@@ -30,8 +32,8 @@ public class Stanik extends Module {
this.contacts = new HashSet<>();
}
- public Stanik() {
- this(60 * 1000);
+ public Stanik(PathName ourPath) {
+ this(ourPath, 60 * 1000);
}
public void handleTyped(StanikMessage message) throws InterruptedException, InvalidMessageType {
@@ -61,7 +63,7 @@ public class Stanik extends Module {
public void handleGetState(GetStateMessage message) throws InterruptedException {
pruneHierarchy();
- addLevels();
+ addValues();
StateMessage response = new StateMessage(
"",
message.getRequestingModule(),
@@ -79,14 +81,17 @@ public class Stanik extends Module {
pruneZMI(hierarchy, now);
}
- private void addLevels() {
- addLevelsRecursive(hierarchy, 0);
+ private void addValues() {
+ addValuesRecursive(hierarchy, 0);
}
- private void addLevelsRecursive(ZMI zmi, long level) {
+ private void addValuesRecursive(ZMI zmi, long level) {
zmi.getAttributes().addOrChange("level", new ValueInt(level));
+ if (ValueUtils.isPrefix(zmi.getPathName(), ourPath)) {
+ zmi.getAttributes().addOrChange("owner", new ValueString(ourPath.toString()));
+ }
for (ZMI son : zmi.getSons()) {
- addLevelsRecursive(son, level + 1);
+ addValuesRecursive(son, level + 1);
}
}