diff --git a/coma/src/org/tangram/coma/ComaBeanFactory.java b/coma/src/org/tangram/coma/ComaBeanFactory.java index 8e0779b4..fe0dd50f 100644 --- a/coma/src/org/tangram/coma/ComaBeanFactory.java +++ b/coma/src/org/tangram/coma/ComaBeanFactory.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -37,6 +38,8 @@ public class ComaBeanFactory extends AbstractComaBeanFactory { private static final Logger LOG = LoggerFactory.getLogger(ComaBeanFactory.class); + private final Map, List> attachedListeners = new HashMap<>(); + @Inject private Set populators; @@ -134,14 +137,24 @@ public Set getChildren(String startFolderId, String pattern) { /** - * Empty implementation. - * Coma is read only and does not even deal with external changes. + * Attach a listener for any changes dealing with classes of the given type. + * Coma is read only and does not even deal with external changes so far. * - * @see org.tangram.content.BeanFactory#addListener(java.lang.Class, org.tangram.content.BeanListener) + * @param cls class to be notified when instances of that class have been changed + * @param listener listener to be notified about changes */ @Override public void addListener(Class cls, BeanListener listener) { - // Since we don't have any changes, we don't need to register listeners + synchronized (attachedListeners) { + List listeners = attachedListeners.get(cls); + if (listeners==null) { + listeners = new ArrayList<>(); + attachedListeners.put(cls, listeners); + } // if + listeners.add(listener); + } // synchronized + listener.reset(); + LOG.info("addListener() {}: {}", cls.getSimpleName(), attachedListeners.get(cls).size()); } // addListener() } // ComaBeanFactory