m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java27
-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/UpdateContactsMessage.java20
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java41
-rw-r--r--src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html9
5 files changed, 51 insertions, 49 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 def1d72..b293446 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
@@ -15,27 +15,12 @@ import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
-import pl.edu.mimuw.cloudatlas.agent.messages.RequestStateMessage;
-import pl.edu.mimuw.cloudatlas.agent.messages.ResponseMessage;
-import pl.edu.mimuw.cloudatlas.agent.messages.SetAttributeMessage;
-import pl.edu.mimuw.cloudatlas.agent.messages.StateMessage;
-import pl.edu.mimuw.cloudatlas.agent.messages.UpdateQueriesMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.*;
import pl.edu.mimuw.cloudatlas.interpreter.Interpreter;
import pl.edu.mimuw.cloudatlas.interpreter.InterpreterException;
import pl.edu.mimuw.cloudatlas.interpreter.Main;
import pl.edu.mimuw.cloudatlas.interpreter.QueryResult;
-import pl.edu.mimuw.cloudatlas.model.Attribute;
-import pl.edu.mimuw.cloudatlas.model.AttributesMap;
-import pl.edu.mimuw.cloudatlas.model.PathName;
-import pl.edu.mimuw.cloudatlas.model.ValueContact;
-import pl.edu.mimuw.cloudatlas.model.Value;
-import pl.edu.mimuw.cloudatlas.model.ValueNull;
-import pl.edu.mimuw.cloudatlas.model.ValueQuery;
-import pl.edu.mimuw.cloudatlas.model.ValueSet;
-import pl.edu.mimuw.cloudatlas.model.ValueTime;
-import pl.edu.mimuw.cloudatlas.model.Type;
-import pl.edu.mimuw.cloudatlas.model.TypePrimitive;
-import pl.edu.mimuw.cloudatlas.model.ZMI;
+import pl.edu.mimuw.cloudatlas.model.*;
import pl.edu.mimuw.cloudatlas.api.Api;
public class NewApiImplementation implements Api {
@@ -138,6 +123,12 @@ public class NewApiImplementation implements Api {
}
public void setFallbackContacts(Set<ValueContact> contacts) throws RemoteException {
- // this.contacts = contacts;
+ try {
+ UpdateContactsMessage message = new UpdateContactsMessage("", System.currentTimeMillis(), contacts);
+ eventBus.addMessage(message);
+ } catch (Exception e) {
+ System.out.println("ERROR: failed to set contacts");
+ throw new RemoteException("Failed to set contacts", e);
+ }
}
}
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 3daa5f9..d59acda 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
@@ -9,7 +9,8 @@ public abstract class StanikMessage extends AgentMessage {
REMOVE_ZMI,
SET_ATTRIBUTE,
UPDATE_ATTRIBUTES,
- UPDATE_QUERIES
+ UPDATE_QUERIES,
+ UPDATE_CONTACTS
}
private Type type;
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateContactsMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateContactsMessage.java
new file mode 100644
index 0000000..227d213
--- /dev/null
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/UpdateContactsMessage.java
@@ -0,0 +1,20 @@
+package pl.edu.mimuw.cloudatlas.agent.messages;
+
+import java.util.Set;
+
+import pl.edu.mimuw.cloudatlas.model.ValueContact;
+
+public class UpdateContactsMessage extends StanikMessage {
+ private Set<ValueContact> contacts;
+
+ public UpdateContactsMessage(String messageId, long timestamp, Set<ValueContact> contacts) {
+ super(messageId, timestamp, Type.UPDATE_CONTACTS);
+ this.contacts = contacts;
+ }
+
+ public UpdateContactsMessage() {}
+
+ public Set<ValueContact> getContacts() {
+ return contacts;
+ }
+}
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 3fca1d5..c713827 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
@@ -1,33 +1,11 @@
package pl.edu.mimuw.cloudatlas.agent.modules;
import java.nio.file.Path;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
import java.util.Map.Entry;
-import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage;
-import pl.edu.mimuw.cloudatlas.agent.messages.GetStateMessage;
-import pl.edu.mimuw.cloudatlas.agent.messages.RemoveZMIMessage;
-import pl.edu.mimuw.cloudatlas.agent.messages.SetAttributeMessage;
-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.AttributesUtil;
-import pl.edu.mimuw.cloudatlas.model.PathName;
-import pl.edu.mimuw.cloudatlas.model.Type;
-import pl.edu.mimuw.cloudatlas.model.TypePrimitive;
-import pl.edu.mimuw.cloudatlas.model.Value;
-import pl.edu.mimuw.cloudatlas.model.ValueBoolean;
-import pl.edu.mimuw.cloudatlas.model.ValueDuration;
-import pl.edu.mimuw.cloudatlas.model.ValueQuery;
-import pl.edu.mimuw.cloudatlas.model.ValueString;
-import pl.edu.mimuw.cloudatlas.model.ValueTime;
-import pl.edu.mimuw.cloudatlas.model.ValueUtils;
-import pl.edu.mimuw.cloudatlas.model.ZMI;
+import pl.edu.mimuw.cloudatlas.agent.messages.*;
+import pl.edu.mimuw.cloudatlas.model.*;
public class Stanik extends Module {
private class InvalidUpdateAttributesMessage extends Exception {
@@ -39,6 +17,8 @@ public class Stanik extends Module {
private ZMI hierarchy;
private HashMap<Attribute, Entry<ValueQuery, ValueTime>> queries;
private long freshnessPeriod;
+ private Set<ValueContact> contacts;
+ private ValueTime contactsTimestamp;
public Stanik(long freshnessPeriod) {
super(ModuleType.STATE);
@@ -46,6 +26,8 @@ public class Stanik extends Module {
queries = new HashMap<Attribute, Entry<ValueQuery, ValueTime>>();
hierarchy.getAttributes().add("timestamp", new ValueTime(0l));
this.freshnessPeriod = freshnessPeriod;
+ this.contactsTimestamp = ValueUtils.currentTime();
+ this.contacts = new HashSet<>();
}
public Stanik() {
@@ -69,6 +51,8 @@ public class Stanik extends Module {
case UPDATE_QUERIES:
handleUpdateQueries((UpdateQueriesMessage) message);
break;
+ case UPDATE_CONTACTS:
+ handleUpdateContacts((UpdateContactsMessage) message);
default:
throw new InvalidMessageType("This type of message cannot be handled by Stanik");
}
@@ -251,4 +235,11 @@ public class Stanik extends Module {
public HashMap<Attribute, Entry<ValueQuery, ValueTime>> getQueries() {
return queries;
}
+
+ private void handleUpdateContacts(UpdateContactsMessage message) {
+ if (message.getContacts() != null && !message.getContacts().isEmpty() &&
+ ValueUtils.valueLower(contactsTimestamp, new ValueTime(message.getTimestamp()))) {
+ this.contacts = message.getContacts();
+ }
+ }
}
diff --git a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html
index 841d995..bfb306c 100644
--- a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html
+++ b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html
@@ -7,17 +7,16 @@
<link rel="preload" href="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js" as="script">
<link rel="preload" href="https://www.gstatic.com/charts/loader.js" as="script">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
- <script async type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
- <script async type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
+ <script async defer type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
+ <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart', 'table', 'controls', 'charteditor']});
- google.charts.setOnLoadCallback(refreshChart());
+ google.charts.setOnLoadCallback(refreshChart);
var chartState = [];
function refreshChart() {
- setTimeout(getData(), 500);
- setTimeout(getData(), 1500);
+ getData();
setInterval(getData, 5000);
}