m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-11 20:22:15 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-11 20:22:15 +0100
commitfd554f89eeff6ffb3dcd80447c4284c976090e9c (patch)
treeb32b9ff33cb070ab00aedd484b015c9c88f79af1
parent0953e404e7dacbe397cc60d8715af72bd59b8c1c (diff)
Add message to remove old gossips
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java13
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java6
2 files changed, 16 insertions, 3 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 175c238..ec34c7f 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
@@ -7,6 +7,7 @@ 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;
@@ -53,7 +54,7 @@ public class GossipGirl extends Module {
handleQuery((QueryMessage) message);
break;
case CLEAN:
- cleanOldGossips();
+ cleanOldGossips((CleanOldGossipsMessage) message);
break;
default:
throw new InvalidMessageType("This type of message cannot be handled by GossipGirl");
@@ -99,6 +100,7 @@ public class GossipGirl extends Module {
private void setState(StateMessage message) throws InterruptedException {
GossipGirlState state = gossipStates.get(message.getRequestId());
if (state != null) {
+ state.setLastAction();
state.setState(message.getZMI(), message.getQueries());
if (state.state == GossipGirlState.State.SEND_HEJKA) {
HejkaMessage hejka = new HejkaMessage(
@@ -136,6 +138,7 @@ public class GossipGirl extends Module {
private void handleNoCoTam(NoCoTamMessage message) throws InterruptedException {
GossipGirlState state = gossipStates.get(message.getReceiverGossipId());
if (state != null) {
+ state.setLastAction();
state.handleNoCoTam(message);
sendInfo(state);
} else {
@@ -161,6 +164,7 @@ public class GossipGirl extends Module {
private void handleAttributes(AttributesMessage message) throws InterruptedException {
GossipGirlState state = gossipStates.get(message.getReceiverGossipId());
if (state != null) {
+ state.setLastAction();
state.gotAttributes(message);
if (state.state == GossipGirlState.State.SEND_INFO) {
sendInfo(state);
@@ -178,6 +182,7 @@ public class GossipGirl extends Module {
private void handleQuery(QueryMessage message) throws InterruptedException {
GossipGirlState state = gossipStates.get(message.getReceiverGossipId());
if (state != null) {
+ state.setLastAction();
state.gotQuery(message.getName());
Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap();
queries.put(
@@ -194,11 +199,13 @@ public class GossipGirl extends Module {
}
}
- private void cleanOldGossips() {
+ private void cleanOldGossips(CleanOldGossipsMessage message) {
Iterator<Entry<Long, GossipGirlState>> iterator = gossipStates.entrySet().iterator();
while (iterator.hasNext()) {
GossipGirlState state = iterator.next().getValue();
- // TODO: remove
+ if (state.lastAction.isLowerThan(message.getAgeThreshold()).getValue()) {
+ 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 eafbcca..70d57d9 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;
@@ -64,6 +65,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) {