Register metadata listeners at all components for metadata updating.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 28 May 2013 08:41:45 +0000 (10:41 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 28 May 2013 08:41:45 +0000 (10:41 +0200)
src/main/java/net/pterodactylus/sonitus/data/Pipeline.java

index 1487d13..75536fc 100644 (file)
@@ -71,6 +71,21 @@ public class Pipeline implements Iterable<ControlledComponent> {
        private Pipeline(Source source, Multimap<Source, Sink> sinks) {
                this.source = Preconditions.checkNotNull(source, "source must not be null");
                this.sinks = Preconditions.checkNotNull(sinks, "sinks must not be null");
+               for (ControlledComponent component : Lists.reverse(components())) {
+                       logger.finest(String.format("Adding Listener to %s.", component));
+                       component.addMetadataListener(new MetadataListener() {
+                               @Override
+                               public void metadataUpdated(ControlledComponent component, Metadata metadata) {
+                                       if (!(component instanceof Source)) {
+                                               return;
+                                       }
+                                       for (ControlledComponent controlledComponent : sinks((Source) component)) {
+                                               logger.fine(String.format("Updating Metadata from %s to %s.", component, controlledComponent));
+                                               controlledComponent.metadataUpdated(metadata);
+                                       }
+                               }
+                       });
+               }
        }
 
        //