diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java | 25 |
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; |