/* * (non-Javadoc) * * @see cz.cuni.mff.d3s.deeco.knowledge.ShadowKnowledgeManagerRegistry# * getOthersKnowledgeManagers() */ @Override public Collection<ReadOnlyKnowledgeManager> getShadowKnowledgeManagers() { List<ReadOnlyKnowledgeManager> result = new LinkedList<>(); result.addAll(container.getLocals()); result.addAll(container.getReplicas(knowledgeManager.getComponent())); result.remove(knowledgeManager); return result; }
/* * (non-Javadoc) * * @see * cz.cuni.mff.d3s.deeco.knowledge.ReplicaListener#replicaRemoved(cz.cuni * .mff.d3s.deeco.knowledge.KnowledgeManager) */ @Override public void replicaUnregistered(KnowledgeManager km, KnowledgeManagerContainer container) { List<KnowledgeManagerTriggerListener> toRemove = new LinkedList<>(); for (List<KnowledgeManagerTriggerListener> tListeners : listenerToTriggerListeners.values()) { toRemove.clear(); for (KnowledgeManagerTriggerListener tListener : tListeners) if (tListener.getKnowledgeManager().equals(km)) { km.unregister(tListener.getTrigger(), tListener); toRemove.add(tListener); } tListeners.removeAll(toRemove); } }
private void registerTriggerAtKnowledgeManager( KnowledgeManager km, Trigger trigger, ShadowsTriggerListener triggerListener) { List<KnowledgeManagerTriggerListener> tListeners; KnowledgeManagerTriggerListener tListener = new KnowledgeManagerTriggerListener(km, triggerListener, trigger); // Update map of listenerToTriggerListeners if (listenerToTriggerListeners.containsKey(triggerListener)) tListeners = listenerToTriggerListeners.get(triggerListener); else { tListeners = new LinkedList<>(); listenerToTriggerListeners.put(triggerListener, tListeners); } tListeners.add(tListener); // Register the listener in the km km.register(trigger, tListener); }