m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java10
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java10
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java5
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java20
4 files changed, 24 insertions, 21 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 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<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap();
- queries.put(
- message.getName(),
- new SimpleImmutableEntry(message.getQuery(), state.getTheirQueryTimestamp(message.getName()))
- );
+ Map<Attribute, ValueQuery> 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<Attribute, Entry<ValueQuery, ValueTime>> queries;
+ public Map<Attribute, ValueQuery> 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<Attribute, Entry<ValueQuery, ValueTime>> queries) {
+ public void setState(ZMI hierarchy, Map<Attribute, ValueQuery> queries) {
switch (state) {
case WAIT_FOR_STATE_INITIALIZER:
this.hierarchy = hierarchy;
@@ -211,8 +211,8 @@ public class GossipGirlState {
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());
+ for (Entry<Attribute, ValueQuery> 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<ValueQuery> queries = new LinkedList();
- for (Entry<ValueQuery, ValueTime> 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<ValueQuery> 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<Attribute, Entry<ValueQuery, ValueTime>> queries;
+ private HashMap<Attribute, ValueQuery> queries;
private long freshnessPeriod;
private Set<ValueContact> 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<Attribute, Entry<ValueQuery, ValueTime>>();
+ queries = new HashMap<Attribute, ValueQuery>();
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<Attribute, Entry<ValueQuery, ValueTime>>) queries.clone(),
+ (HashMap<Attribute, ValueQuery>) queries.clone(),
contacts
);
sendMessage(response);
@@ -210,11 +210,13 @@ public class Stanik extends Module {
}
public void handleUpdateQueries(UpdateQueriesMessage message) {
- for (Entry<Attribute, Entry<ValueQuery, ValueTime>> entry : message.getQueries().entrySet()) {
+ System.out.println("INFO: Stanik handles update queries");
+ for (Entry<Attribute, ValueQuery> entry : message.getQueries().entrySet()) {
Attribute attribute = entry.getKey();
- ValueTime timestamp = entry.getValue().getValue();
- Entry<ValueQuery, ValueTime> 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<Attribute, Entry<ValueQuery, ValueTime>> getQueries() {
+ public HashMap<Attribute, ValueQuery> getQueries() {
return queries;
}