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>2020-01-12 17:10:36 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-12 17:10:36 +0100
commita07000c6dae6f84dd221454fca24b65e9579afae (patch)
treecd647a463f073840842a7d8283597031322d7c59 /src/main/java/pl/edu/mimuw/cloudatlas/agent/modules
parent9c6a9bb5a8ce6d3282d1fd669214911c302e9aca (diff)
parentf0076abd246bdf40ba4a03c0c894f6f75173eac8 (diff)
Merge branch 'master' into logs-n-stuff
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java22
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java6
2 files changed, 27 insertions, 1 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java
index 0ec9d6c..440df33 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java
@@ -2,10 +2,12 @@ package pl.edu.mimuw.cloudatlas.agent.modules;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import pl.edu.mimuw.cloudatlas.agent.messages.AttributesMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.CleanOldGossipsMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.GetStateMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.GossipGirlMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.HejkaMessage;
@@ -52,6 +54,9 @@ public class GossipGirl extends Module {
case QUERY:
handleQuery((QueryMessage) message);
break;
+ case CLEAN:
+ cleanOldGossips((CleanOldGossipsMessage) message);
+ break;
default:
throw new InvalidMessageType("This type of message cannot be handled by GossipGirl");
}
@@ -100,6 +105,7 @@ public class GossipGirl extends Module {
GossipGirlState state = gossipStates.get(message.getRequestId());
if (state != null) {
System.out.println("INFO: setting state in gossip " + Long.toString(message.getRequestId()));
+ state.setLastAction();
state.setState(message.getZMI(), message.getQueries());
if (state.state == GossipGirlState.State.SEND_HEJKA) {
HejkaMessage hejka = new HejkaMessage(
@@ -140,6 +146,7 @@ public class GossipGirl extends Module {
GossipGirlState state = gossipStates.get(message.getReceiverGossipId());
if (state != null) {
System.out.println("INFO: handling NoCoTamMessage in" + Long.toString(message.getReceiverGossipId()));
+ state.setLastAction();
state.handleNoCoTam(message);
System.out.println("DEBUG: handled NoCoTam in GossipGirlState");
sendInfo(state);
@@ -171,8 +178,9 @@ public class GossipGirl extends Module {
GossipGirlState state = gossipStates.get(message.getReceiverGossipId());
if (state != null) {
System.out.println("INFO: handling Attributes in " + Long.toString(message.getReceiverGossipId()));
+ state.setLastAction();
state.gotAttributes(message);
- if (state.state == GossipGirlState.State.SEND_INFO) {
+ if (state.state == GossipGirlState.State.SEND_INFO || state.state == GossipGirlState.State.SEND_INFO_AND_FINISH) {
sendInfo(state);
}
UpdateAttributesMessage updateMessage = new UpdateAttributesMessage("", 0, message.getPath().toString(), message.getAttributes());
@@ -190,6 +198,7 @@ public class GossipGirl extends Module {
GossipGirlState state = gossipStates.get(message.getReceiverGossipId());
if (state != null) {
System.out.println("INFO: handling Query in " + Long.toString(message.getReceiverGossipId()));
+ state.setLastAction();
state.gotQuery(message.getName());
Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap();
queries.put(
@@ -206,4 +215,15 @@ public class GossipGirl extends Module {
System.out.println("ERROR: GossipGirl got query for a nonexistent gossip");
}
}
+
+ private void cleanOldGossips(CleanOldGossipsMessage message) {
+ Iterator<Entry<Long, GossipGirlState>> iterator = gossipStates.entrySet().iterator();
+ while (iterator.hasNext()) {
+ GossipGirlState state = iterator.next().getValue();
+ if (state.lastAction.isLowerThan(message.getAgeThreshold()).getValue()) {
+ System.out.println("INFO: GossipGirl removing old gossip " + Long.toString(state.gossipId));
+ iterator.remove();
+ }
+ }
+ }
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java
index 6ee7474..e9bc02a 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java
@@ -36,6 +36,7 @@ public class GossipGirlState {
FINISHED,
ERROR
}
+ public ValueTime lastAction;
public PathName ourPath;
public ValueContact theirContact;
public long gossipId;
@@ -65,6 +66,11 @@ public class GossipGirlState {
} else {
state = State.APPLY_HEJKA;
}
+ this.lastAction = ValueUtils.currentTime();
+ }
+
+ public void setLastAction() {
+ lastAction = ValueUtils.currentTime();
}
public void setState(ZMI hierarchy, Map<Attribute, Entry<ValueQuery, ValueTime>> queries) {