Use a single thread if a source/filter has only a single sink.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / Pipeline.java
index 3ee0c9d..93648bc 100644 (file)
@@ -35,6 +35,7 @@ import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
+import com.google.common.util.concurrent.MoreExecutors;
 
 /**
  * A pipeline is responsible for streaming audio data from a {@link Source} to
@@ -234,7 +235,7 @@ public class Pipeline {
                        this.source = source;
                        this.sinks = sinks;
                        if (sinks.size() == 1) {
-                               executorService = Executors.newSingleThreadExecutor();
+                               executorService = MoreExecutors.sameThreadExecutor();
                        } else {
                                executorService = Executors.newCachedThreadPool();
                        }
@@ -255,7 +256,7 @@ public class Pipeline {
 
                @Override
                public void run() {
-                       Metadata firstMetadata = source.metadata();
+                       Metadata firstMetadata = null;
                        while (!stopped.get()) {
                                try {
                                        final Metadata lastMetadata = firstMetadata;
@@ -285,12 +286,15 @@ public class Pipeline {
                                } catch (IOException e) {
                                        /* TODO */
                                        e.printStackTrace();
+                                       break;
                                } catch (InterruptedException e) {
                                        /* TODO */
                                        e.printStackTrace();
+                                       break;
                                } catch (ExecutionException e) {
                                        /* TODO */
                                        e.printStackTrace();
+                                       break;
                                }
                        }
                }