diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-01-11 20:12:34 +0100 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-01-11 20:12:34 +0100 |
commit | 0953e404e7dacbe397cc60d8715af72bd59b8c1c (patch) | |
tree | 3689aab02ae709b9b4edc666956f08770eba3423 /src/main/java/pl/edu/mimuw/cloudatlas | |
parent | 55be079e9b183c430662606548548ef935bbdf40 (diff) |
Start implementing gossip cleanup
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas')
3 files changed, 30 insertions, 1 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/CleanOldGossipsMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/CleanOldGossipsMessage.java new file mode 100644 index 0000000..6c3cb7e --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/CleanOldGossipsMessage.java @@ -0,0 +1,16 @@ +package pl.edu.mimuw.cloudatlas.agent.messages; + +import pl.edu.mimuw.cloudatlas.model.ValueTime; + +public class CleanOldGossipsMessage extends GossipGirlMessage { + private ValueTime ageThreshold; + + public CleanOldGossipsMessage(String messageId, long timestamp, ValueTime ageThreshold) { + super(messageId, timestamp, Type.CLEAN); + this.ageThreshold = ageThreshold; + } + + public ValueTime getAgeThreshold() { + return ageThreshold; + } +} diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/GossipGirlMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/GossipGirlMessage.java index 03525bb..6255e3b 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/GossipGirlMessage.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/GossipGirlMessage.java @@ -9,7 +9,8 @@ public abstract class GossipGirlMessage extends AgentMessage { HEJKA, INITIATE, NO_CO_TAM, - QUERY + QUERY, + CLEAN } private Type type; 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 dd8f0b7..175c238 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,6 +2,7 @@ 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; @@ -51,6 +52,9 @@ public class GossipGirl extends Module { case QUERY: handleQuery((QueryMessage) message); break; + case CLEAN: + cleanOldGossips(); + break; default: throw new InvalidMessageType("This type of message cannot be handled by GossipGirl"); } @@ -189,4 +193,12 @@ public class GossipGirl extends Module { System.out.println("ERROR: GossipGirl got query for a nonexistent gossip"); } } + + private void cleanOldGossips() { + Iterator<Entry<Long, GossipGirlState>> iterator = gossipStates.entrySet().iterator(); + while (iterator.hasNext()) { + GossipGirlState state = iterator.next().getValue(); + // TODO: remove + } + } } |