add ConfigSource callback logit


git-svn-id: https://svn.apache.org/repos/asf/geronimo/components/config/trunk@1825299 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
index 43fa8c0..fc0c760 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
@@ -155,6 +155,8 @@
 
     public synchronized void addConfigSources(List<ConfigSource> configSourcesToAdd) {
         List<ConfigSource> allConfigSources = new ArrayList<>(configSources);
+
+        configSourcesToAdd.forEach(cs -> cs.setOnAttributeChange(this::reportConfigChange));
         allConfigSources.addAll(configSourcesToAdd);
 
         // finally put all the configSources back into the map
@@ -203,4 +205,28 @@
             configListenerLock.writeLock().unlock();;
         }
     }
+
+    /**
+     * This method gets called back from a ConfigSource if the ConfigSource
+     * did detect a config change
+     */
+    public void reportConfigChange(Set<String> changedAttributeNames) {
+        configListenerLock.readLock().lock();
+        try {
+            Iterator<WeakReference<Consumer<Set<String>>>> it = configChangedListeners.iterator();
+            while (it.hasNext()) {
+                WeakReference<Consumer<Set<String>>> changeListenerRef = it.next();
+                Consumer<Set<String>> changeListener = changeListenerRef.get();
+                if (changeListener == null) {
+                    it.remove();
+                }
+                else {
+                    changeListener.accept(changedAttributeNames);
+                }
+            }
+        }
+        finally {
+            configListenerLock.readLock().unlock();
+        }
+    }
 }
\ No newline at end of file