m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-27 16:24:32 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-27 16:24:32 +0100
commit387cabccea7985ed7d85cd6c3737946c644db2d3 (patch)
treec97808e2c3e9eb177f708fb32ce9001d2c4aab75 /src/main
parent105655c78f7d817f99a04b77e4df6a39835997a5 (diff)
Sometimes select fallback contacts
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java
index 2f04a25..4d8842f 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java
@@ -43,8 +43,16 @@ public class HierarchyConfig {
public void run() {
try {
System.out.println("INFO: initiating gossip");
+
+ StateMessage state = getState();
PathName gossipLevel = gossipGirlStrategies.selectStrategy(zoneSelectionStrategy);
- ValueContact contact = selectContactFromLevel(gossipLevel);
+ ValueContact contact;
+ if (random.nextDouble() < 0.2) {
+ contact = selectFallbackContact(state.getContacts());
+ } else {
+ contact = selectContactFromLevel(gossipLevel, state);
+ }
+
if (contact != null) {
System.out.println("INFO: found a contact " + contact.toString());
InitiateGossipMessage message = new InitiateGossipMessage("", 0, new PathName(zonePath), contact);
@@ -63,15 +71,12 @@ public class HierarchyConfig {
AgentUtils.startRecursiveTask(taskSupplier, gossipPeriod, eventBus);
}
- private ValueContact selectContactFromLevel(PathName path) throws Exception {
- CompletableFuture<ResponseMessage> responseFuture = new CompletableFuture();
- this.eventBus.addMessage(new RequestStateMessage("", 0, responseFuture));
- StateMessage response = (StateMessage) responseFuture.get();
- ZMI root = response.getZMI();
+ private ValueContact selectContactFromLevel(PathName path, StateMessage state) throws Exception {
+ ZMI root = state.getZMI();
List<ZMI> siblings = getSiblings(root, path);
filterEmptyContacts(siblings);
if (siblings.isEmpty()) {
- return selectFallbackContact(response.getContacts());
+ return selectFallbackContact(state.getContacts());
}
ZMI zmi = selectZMI(siblings);
ValueSet contactsValue = (ValueSet) zmi.getAttributes().getOrNull("contacts");
@@ -79,6 +84,12 @@ public class HierarchyConfig {
return selectContactFromSet(valueSet);
}
+ private StateMessage getState() throws Exception {
+ CompletableFuture<ResponseMessage> responseFuture = new CompletableFuture();
+ this.eventBus.addMessage(new RequestStateMessage("", 0, responseFuture));
+ return (StateMessage) responseFuture.get();
+ }
+
private ValueContact selectFallbackContact(Set<ValueContact> contacts) throws Exception {
if (contacts.isEmpty()) {
return null;