m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/agent
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-29 16:49:43 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-29 16:49:43 +0100
commitc3121bfa6c00682173a7f1fba9d4c524b8ef517e (patch)
tree55bd25630a090c91e1a4362b68e32da22389dd1d /src/main/java/pl/edu/mimuw/cloudatlas/agent
parentaf6f6f37403d0e23a09a6ba4476271c2a0eaf623 (diff)
Handle queries in state
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StanikMessage.java3
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateQueriesMessage.java21
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java15
3 files changed, 38 insertions, 1 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StanikMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StanikMessage.java
index da35f2d..b23f6e0 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StanikMessage.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StanikMessage.java
@@ -6,7 +6,8 @@ import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType;
public abstract class StanikMessage extends AgentMessage {
public enum Type {
GET_STATE,
- UPDATE_ATTRIBUTES
+ UPDATE_ATTRIBUTES,
+ UPDATE_QUERIES
}
private Type type;
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
new file mode 100644
index 0000000..58ad55a
--- /dev/null
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateQueriesMessage.java
@@ -0,0 +1,21 @@
+package pl.edu.mimuw.cloudatlas.agent.messages;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import pl.edu.mimuw.cloudatlas.model.Attribute;
+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;
+
+ public UpdateQueriesMessage(String messageId, long timestamp, Map<Attribute, Entry<ValueQuery, ValueTime>> queries) {
+ super(messageId, timestamp, Type.UPDATE_QUERIES);
+ this.queries = queries;
+ }
+
+ public Map<Attribute, Entry<ValueQuery, ValueTime>> getQueries() {
+ return queries;
+ }
+}
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 a31f265..e8721b3 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
@@ -9,6 +9,7 @@ import pl.edu.mimuw.cloudatlas.agent.messages.GetStateMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.StateMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.StanikMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.UpdateQueriesMessage;
import pl.edu.mimuw.cloudatlas.model.Attribute;
import pl.edu.mimuw.cloudatlas.model.AttributesMap;
import pl.edu.mimuw.cloudatlas.model.PathName;
@@ -46,6 +47,9 @@ public class Stanik extends Module {
case UPDATE_ATTRIBUTES:
handleUpdateAttributes((UpdateAttributesMessage) message);
break;
+ case UPDATE_QUERIES:
+ handleUpdateQueries((UpdateQueriesMessage) message);
+ break;
default:
throw new InvalidMessageType("This type of message cannot be handled by Stanik");
}
@@ -74,6 +78,17 @@ public class Stanik extends Module {
}
}
+ public void handleUpdateQueries(UpdateQueriesMessage message) {
+ for (Entry<Attribute, Entry<ValueQuery, ValueTime>> entry : message.getQueries().entrySet()) {
+ Attribute attribute = entry.getKey();
+ ValueTime timestamp = entry.getValue().getValue();
+ Entry<ValueQuery, ValueTime> currentTimestampedQuery = queries.get(attribute);
+ if (currentTimestampedQuery == null || valueLower(currentTimestampedQuery.getValue(), timestamp)) {
+ queries.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
private boolean valueLower(Value a, Value b) {
return ((ValueBoolean) a.isLowerThan(b)).getValue();
}