Add method to notify sink when a source has updated its metadata.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / filter / MultiSourceFilter.java
index 704324d..a505c92 100644 (file)
@@ -32,6 +32,7 @@ import java.util.logging.Logger;
 import net.pterodactylus.sonitus.data.ConnectException;
 import net.pterodactylus.sonitus.data.Filter;
 import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
 import net.pterodactylus.sonitus.data.ReusableSink;
 import net.pterodactylus.sonitus.data.Source;
 import net.pterodactylus.sonitus.data.event.SourceFinishedEvent;
@@ -59,9 +60,6 @@ public class MultiSourceFilter implements Filter, ReusableSink {
        /** The connection. */
        private Connection connection;
 
-       /** The format. */
-       private Format format;
-
        @Inject
        public MultiSourceFilter(EventBus eventBus) {
                this.eventBus = eventBus;
@@ -69,7 +67,16 @@ public class MultiSourceFilter implements Filter, ReusableSink {
 
        @Override
        public Format format() {
-               return format;
+               synchronized (syncObject) {
+                       return connection.source.format();
+               }
+       }
+
+       @Override
+       public Metadata metadata() {
+               synchronized (syncObject) {
+                       return connection.source.metadata();
+               }
        }
 
        @Override
@@ -86,10 +93,8 @@ public class MultiSourceFilter implements Filter, ReusableSink {
        @Override
        public void connect(Source source) throws ConnectException {
                checkNotNull(source, "source must not be null");
-               if (format != null) {
-                       checkArgument(format.equals(source.format()), "source’s format must equal this sink’s format");
-               } else {
-                       format = source.format();
+               if ((connection != null) && (connection.source != null)) {
+                       checkArgument(connection.source.format().equals(source.format()), "source’s format must equal this sink’s format");
                }
 
                if (connection == null) {
@@ -103,6 +108,11 @@ public class MultiSourceFilter implements Filter, ReusableSink {
                }
        }
 
+       @Override
+       public void metadataUpdated() {
+               /* ignore. */
+       }
+
        /**
         * The connection feeds the input from the currently connected source to the
         * input stream that {@link #get(int)} will get its data from.