m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StanikMessage.java1
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java35
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java4
3 files changed, 33 insertions, 7 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 b23f6e0..d86de4a 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,6 +6,7 @@ import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType;
public abstract class StanikMessage extends AgentMessage {
public enum Type {
GET_STATE,
+ REMOVE_ZMI,
UPDATE_ATTRIBUTES,
UPDATE_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 4694219..ea893d9 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.StateMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.StanikMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage;
@@ -21,6 +22,7 @@ import pl.edu.mimuw.cloudatlas.model.ValueBoolean;
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;
public class Stanik extends Module {
@@ -45,6 +47,9 @@ public class Stanik extends Module {
case GET_STATE:
handleGetState((GetStateMessage) message);
break;
+ case REMOVE_ZMI:
+ handleRemoveZMI((RemoveZMIMessage) message);
+ break;
case UPDATE_ATTRIBUTES:
handleUpdateAttributes((UpdateAttributesMessage) message);
break;
@@ -57,17 +62,37 @@ public class Stanik extends Module {
}
public void handleGetState(GetStateMessage message) throws InterruptedException {
- StateMessage response = new StateMessage("", message.getRequestingModule(), 0, message.getRequestId(), hierarchy.clone(), (HashMap<Attribute, Entry<ValueQuery, ValueTime>>) queries.clone());
+ StateMessage response = new StateMessage(
+ "",
+ message.getRequestingModule(),
+ 0,
+ message.getRequestId(),
+ hierarchy.clone(),
+ (HashMap<Attribute, Entry<ValueQuery, ValueTime>>) queries.clone()
+ );
sendMessage(response);
}
+ public void handleRemoveZMI(RemoveZMIMessage message) {
+ try {
+ ZMI zmi = hierarchy.findDescendant(new PathName(message.getPathName()));
+ if (ValueUtils.valueLower(zmi.getAttributes().getOrNull("timestamp"), message.getRemovalTimestamp())) {
+ zmi.getFather().removeSon(zmi);
+ } else {
+ System.out.println("DEBUG: not removing zone with fresher timestamp than removal");
+ }
+ } catch (ZMI.NoSuchZoneException e) {
+ System.out.println("DEBUG: trying to remove zone that doesn't exist");
+ }
+ }
+
public void handleUpdateAttributes(UpdateAttributesMessage message) {
try {
validateUpdateAttributesMessage(message);
addMissingZones(new PathName(message.getPathName()));
ZMI zone = hierarchy.findDescendant(message.getPathName());
AttributesMap attributes = zone.getAttributes();
- if (valueLower(attributes.get("timestamp"), message.getAttributes().get("timestamp"))) {
+ if (ValueUtils.valueLower(attributes.get("timestamp"), message.getAttributes().get("timestamp"))) {
AttributesUtil.transferAttributes(message.getAttributes(), attributes);
} else {
System.out.println("DEBUG: not applying update with older attributes");
@@ -84,16 +109,12 @@ public class Stanik extends Module {
Attribute attribute = entry.getKey();
ValueTime timestamp = entry.getValue().getValue();
Entry<ValueQuery, ValueTime> currentTimestampedQuery = queries.get(attribute);
- if (currentTimestampedQuery == null || valueLower(currentTimestampedQuery.getValue(), timestamp)) {
+ if (currentTimestampedQuery == null || ValueUtils.valueLower(currentTimestampedQuery.getValue(), timestamp)) {
queries.put(entry.getKey(), entry.getValue());
}
}
}
- private boolean valueLower(Value a, Value b) {
- return ((ValueBoolean) a.isLowerThan(b)).getValue();
- }
-
private void validateUpdateAttributesMessage(UpdateAttributesMessage message) throws InvalidUpdateAttributesMessage {
validateZoneName(message);
validateHasTimeStamp(message);
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java
index 01a45b5..02b2ce4 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java
@@ -4,4 +4,8 @@ public class ValueUtils {
public static boolean valueNonNullOfType(Value value, Type type) {
return value != null && !value.isNull() && value.getType().isCompatible(type);
}
+
+ public static boolean valueLower(Value a, Value b) {
+ return ((ValueBoolean) a.isLowerThan(b)).getValue();
+ }
}