m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-31 17:31:38 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-31 17:32:33 +0100
commiteb7fbbd08bb003a47d9788a9f6476695ab46b271 (patch)
tree7bdd6f9a29877345e538b1cebb99277fa1aa41d4 /src/main/java/pl/edu/mimuw/cloudatlas/agent/modules
parent17d87268246d32a75407590f8fef118148b87ccd (diff)
Add message to set a single attribute
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java25
1 files changed, 25 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 b030901..3e5b790 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
@@ -6,6 +6,7 @@ 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;
@@ -49,6 +50,9 @@ public class Stanik extends Module {
case REMOVE_ZMI:
handleRemoveZMI((RemoveZMIMessage) message);
break;
+ case SET_ATTRIBUTE:
+ handleSetAttribte((SetAttributeMessage) message);
+ break;
case UPDATE_ATTRIBUTES:
handleUpdateAttributes((UpdateAttributesMessage) message);
break;
@@ -85,6 +89,27 @@ public class Stanik extends Module {
}
}
+ /*
+ * Always adds the new attribute.
+ * The zone must already exist.
+ * The zone's timestamp will be the maximum of its current timestamp or the
+ * timestamp provided with the new value.
+ */
+ public void handleSetAttribte(SetAttributeMessage message) {
+ try {
+ ZMI zmi = hierarchy.findDescendant(new PathName(message.getPathName()));
+ ValueTime updateTimestamp = message.getUpdateTimestamp();
+ ValueTime currentTimestamp = (ValueTime) zmi.getAttributes().getOrNull("timestamp");
+ if (ValueUtils.valueLower(currentTimestamp, updateTimestamp)) {
+ zmi.getAttributes().addOrChange("timestamp", updateTimestamp);
+ }
+
+ zmi.getAttributes().addOrChange(message.getAttribute(), message.getValue());
+ } catch (ZMI.NoSuchZoneException e) {
+ System.out.println("DEBUG: trying to set attribute in zone that doesn't exist");
+ }
+ }
+
public void handleUpdateAttributes(UpdateAttributesMessage message) {
try {
validateUpdateAttributesMessage(message);