m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-14 21:28:10 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-14 21:28:10 +0100
commit83feb6ad13187af9be55cc71408611f67d280955 (patch)
tree2ef512092714fe3ae7a26a767cd5779bbe78ef51 /src/main/java
parent99b7023aba5c09f069badc35d05ea3ef53f3a6d2 (diff)
Fix timestamps and ValueQuery
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java8
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StateMessage.java6
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateQueriesMessage.java6
-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
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java18
8 files changed, 46 insertions, 37 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
index affad86..bd3f524 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
@@ -82,8 +82,8 @@ public class NewApiImplementation implements Api {
QuerySignerApiImplementation.validateInstallQuery(name, query, this.publicKey);
Attribute attributeName = new Attribute(name);
ValueTime timestamp = new ValueTime(System.currentTimeMillis());
- Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap();
- queries.put(attributeName, new SimpleImmutableEntry(new ValueQuery(query), timestamp));
+ Map<Attribute, ValueQuery> queries = new HashMap();
+ queries.put(attributeName, new ValueQuery(query));
UpdateQueriesMessage message = new UpdateQueriesMessage("", 0, queries);
eventBus.addMessage(message);
} catch (Exception e) {
@@ -97,8 +97,8 @@ public class NewApiImplementation implements Api {
QuerySignerApiImplementation.validateUninstallQuery(queryName, query, this.publicKey);
Attribute attributeName = new Attribute(queryName);
ValueTime timestamp = new ValueTime(System.currentTimeMillis());
- Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap();
- queries.put(attributeName, new SimpleImmutableEntry(null, timestamp));
+ Map<Attribute, ValueQuery> queries = new HashMap();
+ queries.put(attributeName, new ValueQuery(query));
UpdateQueriesMessage message = new UpdateQueriesMessage("", 0, queries);
eventBus.addMessage(message);
} catch (Exception e) {
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StateMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StateMessage.java
index 806d41f..c70f215 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StateMessage.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StateMessage.java
@@ -13,10 +13,10 @@ import pl.edu.mimuw.cloudatlas.model.ZMI;
public class StateMessage extends ResponseMessage {
private ZMI zmi;
- private Map<Attribute, Entry<ValueQuery, ValueTime>> queries;
+ private Map<Attribute, ValueQuery> queries;
private Set<ValueContact> contacts;
- public StateMessage(String messageId, ModuleType destinationModule, long timestamp, long requestId, ZMI zmi, Map<Attribute, Entry<ValueQuery, ValueTime>> queries, Set<ValueContact> contacts) {
+ public StateMessage(String messageId, ModuleType destinationModule, long timestamp, long requestId, ZMI zmi, Map<Attribute, ValueQuery> queries, Set<ValueContact> contacts) {
super(messageId, destinationModule, timestamp, Type.STATE, requestId);
this.zmi = zmi;
this.queries = queries;
@@ -29,7 +29,7 @@ public class StateMessage extends ResponseMessage {
return zmi;
}
- public Map<Attribute, Entry<ValueQuery, ValueTime>> getQueries() {
+ public Map<Attribute, ValueQuery> getQueries() {
return queries;
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateQueriesMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateQueriesMessage.java
index 4b0b9c8..7f156df 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateQueriesMessage.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateQueriesMessage.java
@@ -8,16 +8,16 @@ import pl.edu.mimuw.cloudatlas.model.ValueQuery;
import pl.edu.mimuw.cloudatlas.model.ValueTime;
public class UpdateQueriesMessage extends StanikMessage {
- private Map<Attribute, Entry<ValueQuery, ValueTime>> queries;
+ private Map<Attribute, ValueQuery> queries;
- public UpdateQueriesMessage(String messageId, long timestamp, Map<Attribute, Entry<ValueQuery, ValueTime>> queries) {
+ public UpdateQueriesMessage(String messageId, long timestamp, Map<Attribute, ValueQuery> queries) {
super(messageId, timestamp, Type.UPDATE_QUERIES);
this.queries = queries;
}
public UpdateQueriesMessage() {}
- public Map<Attribute, Entry<ValueQuery, ValueTime>> getQueries() {
+ public Map<Attribute, ValueQuery> getQueries() {
return queries;
}
}
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;
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java
index ece50b5..3edda69 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java
@@ -28,24 +28,30 @@ public class ValueQuery extends Value {
*/
public ValueQuery(String query) throws Exception {
this.code = query;
- Yylex lex = new Yylex(new ByteArrayInputStream(query.getBytes()));
- this.query = (new parser(lex)).pProgram();
+ if (!query.isEmpty()) {
+ Yylex lex = new Yylex(new ByteArrayInputStream(query.getBytes()));
+ this.query = (new parser(lex)).pProgram();
+ }
this.signature = null;
this.timestamp = System.currentTimeMillis();
}
public ValueQuery(String query, byte[] querySignature) throws Exception {
this.code = query;
- Yylex lex = new Yylex(new ByteArrayInputStream(query.getBytes()));
- this.query = (new parser(lex)).pProgram();
+ if (!query.isEmpty()) {
+ Yylex lex = new Yylex(new ByteArrayInputStream(query.getBytes()));
+ this.query = (new parser(lex)).pProgram();
+ }
this.signature = querySignature;
this.timestamp = System.currentTimeMillis();
}
public ValueQuery(QueryData queryData) throws Exception {
this.code = queryData.getCode();
- Yylex lex = new Yylex(new ByteArrayInputStream(queryData.getCode().getBytes()));
- this.query = (new parser(lex)).pProgram();
+ if (!queryData.getCode().isEmpty()) {
+ Yylex lex = new Yylex(new ByteArrayInputStream(queryData.getCode().getBytes()));
+ this.query = (new parser(lex)).pProgram();
+ }
this.signature = queryData.getSignature();
this.timestamp = System.currentTimeMillis();
}