m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-12 22:25:09 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-12 22:25:09 +0100
commitcd247e8d64b2ef0aed7f0afdccd711008cd60fcd (patch)
treecf54497163b95e32fc8932b0ba13acc3fe2ca503 /src/main
parent411bf8f0dae524d70a0754049b5494182ade4a05 (diff)
Add default queries for contacts and cardinality
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java22
1 files changed, 22 insertions, 0 deletions
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 a428232..6e7d4dc 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
@@ -2,6 +2,7 @@ package pl.edu.mimuw.cloudatlas.agent.modules;
import java.nio.file.Path;
import java.util.*;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map.Entry;
import pl.edu.mimuw.cloudatlas.agent.messages.*;
@@ -30,6 +31,24 @@ public class Stanik extends Module {
this.freshnessPeriod = freshnessPeriod;
this.contactsTimestamp = ValueUtils.currentTime();
this.contacts = new HashSet<>();
+ setDefaultQueries();
+ }
+
+ private void setDefaultQueries() {
+ String cardinalityQuery = "SELECT sum(cardinality) AS cardinality";
+ String contactsQuery = "SELECT random(5, unfold(contacts)) AS contacts";
+
+ setDefaultQuery("&cardinality", cardinalityQuery);
+ setDefaultQuery("&contacts", contactsQuery);
+ }
+
+ private void setDefaultQuery(String name, String query) {
+ try {
+ ValueQuery queryValue = new ValueQuery(query);
+ queries.put(new Attribute(name), new SimpleImmutableEntry(queryValue, new ValueTime(0l)));
+ } catch (Exception e) {
+ System.out.println("ERROR: failed to compile default query");
+ }
}
public Stanik(PathName ourPath) {
@@ -90,6 +109,9 @@ public class Stanik extends Module {
if (ValueUtils.isPrefix(zmi.getPathName(), ourPath)) {
zmi.getAttributes().addOrChange("owner", new ValueString(ourPath.toString()));
}
+ if (zmi.getPathName().equals(ourPath)) {
+ zmi.getAttributes().addOrChange("cardinality", new ValueInt(1l));
+ }
for (ZMI son : zmi.getSons()) {
addValuesRecursive(son, level + 1);
}