From 387cabccea7985ed7d85cd6c3737946c644db2d3 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 27 Jan 2020 16:24:32 +0100 Subject: Sometimes select fallback contacts --- .../mimuw/cloudatlas/agent/HierarchyConfig.java | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src') 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 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 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 responseFuture = new CompletableFuture(); + this.eventBus.addMessage(new RequestStateMessage("", 0, responseFuture)); + return (StateMessage) responseFuture.get(); + } + private ValueContact selectFallbackContact(Set contacts) throws Exception { if (contacts.isEmpty()) { return null; -- cgit v1.2.3