From c631dee52c21df09816ece63d6e6816a408da2f5 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sat, 11 Jan 2020 21:02:34 +0100 Subject: Fix things --- src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 2 +- src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java | 1 + .../pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java | 14 +++++++++----- .../edu/mimuw/cloudatlas/agent/messages/StateMessage.java | 10 +++++++++- .../java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java | 6 ++++-- 5 files changed, 24 insertions(+), 9 deletions(-) (limited to 'src/main/java/pl') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java index a7d2d55..0cbda2d 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -38,7 +38,7 @@ public class Agent { agentConfig.runRegistry(eventBus); agentConfig.startNonModuleThreads(eventBus); - initZones(eventBus); + // initZones(eventBus); // TODO: make query period confiurable with config file and from tests diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java index a9b25ed..0e972f4 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/EventBus.java @@ -54,6 +54,7 @@ public class EventBus implements Runnable { } public void addMessage(AgentMessage msg) throws InterruptedException { + System.out.println("INFO: message added for " + msg.getDestinationModule().toString()); this.events.put(msg); } } 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 04b9b5b..dc5241d 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java @@ -71,7 +71,7 @@ public class HierarchyConfig { List siblings = getSiblings(root, path); filterEmptyContacts(siblings); if (siblings.isEmpty()) { - return selectFallbackContact(); + return selectFallbackContact(response.getContacts()); } ZMI zmi = selectZMI(siblings); ValueSet contactsValue = (ValueSet) zmi.getAttributes().getOrNull("contacts"); @@ -80,8 +80,12 @@ public class HierarchyConfig { } // TODO - private ValueContact selectFallbackContact() throws Exception { - return null; + private ValueContact selectFallbackContact(Set contacts) throws Exception { + if (contacts.isEmpty()) { + return null; + } else { + return selectContactFromSet(contacts); + } } private ZMI selectZMI(List zmis) throws Exception { @@ -96,9 +100,9 @@ public class HierarchyConfig { throw new Exception("empty list passed to selectZMI"); } - private ValueContact selectContactFromSet(Set contacts) throws Exception { + private ValueContact selectContactFromSet(Set contacts) throws Exception { int i = random.nextInt(contacts.size()); - for (Value contact : contacts) { + for (T contact : contacts) { if (i == 0) { return (ValueContact) contact; } diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StateMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StateMessage.java index 759723b..806d41f 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StateMessage.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/StateMessage.java @@ -2,9 +2,11 @@ package pl.edu.mimuw.cloudatlas.agent.messages; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType; import pl.edu.mimuw.cloudatlas.model.Attribute; +import pl.edu.mimuw.cloudatlas.model.ValueContact; import pl.edu.mimuw.cloudatlas.model.ValueQuery; import pl.edu.mimuw.cloudatlas.model.ValueTime; import pl.edu.mimuw.cloudatlas.model.ZMI; @@ -12,11 +14,13 @@ import pl.edu.mimuw.cloudatlas.model.ZMI; public class StateMessage extends ResponseMessage { private ZMI zmi; private Map> queries; + private Set contacts; - public StateMessage(String messageId, ModuleType destinationModule, long timestamp, long requestId, ZMI zmi, Map> queries) { + public StateMessage(String messageId, ModuleType destinationModule, long timestamp, long requestId, ZMI zmi, Map> queries, Set contacts) { super(messageId, destinationModule, timestamp, Type.STATE, requestId); this.zmi = zmi; this.queries = queries; + this.contacts = contacts; } public StateMessage() {} @@ -28,4 +32,8 @@ public class StateMessage extends ResponseMessage { public Map> getQueries() { return queries; } + + public Set getContacts() { + return contacts; + } } diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java index c713827..999c193 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java @@ -53,8 +53,9 @@ public class Stanik extends Module { break; case UPDATE_CONTACTS: handleUpdateContacts((UpdateContactsMessage) message); + break; default: - throw new InvalidMessageType("This type of message cannot be handled by Stanik"); + throw new InvalidMessageType("This type of message cannot be handled by Stanik" + message.getType().toString()); } } @@ -66,7 +67,8 @@ public class Stanik extends Module { 0, message.getRequestId(), hierarchy.clone(), - (HashMap>) queries.clone() + (HashMap>) queries.clone(), + contacts ); sendMessage(response); } -- cgit v1.2.3