From: David ‘Bombe’ Roden Date: Sat, 16 Mar 2013 18:49:48 +0000 (+0100) Subject: Store the source instead of only the format. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ab9e62794abd0430bf2c79ecd41e311675d8b7c4;p=sonitus.git Store the source instead of only the format. --- diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java index 497ba2a..73d4b5f 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java @@ -49,8 +49,8 @@ public abstract class ExternalFilter implements Filter { /** The logger. */ private final Logger logger = Logger.getLogger(getClass().getName()); - /** The format of the source. */ - private Format format; + /** The source. */ + private Source source; /** The input stream that will hold the converted source. */ private PipedInputStream pipedInputStream; @@ -61,7 +61,7 @@ public abstract class ExternalFilter implements Filter { @Override public Format format() { - return format; + return source.format(); } @Override @@ -78,9 +78,9 @@ public abstract class ExternalFilter implements Filter { public void connect(Source source) throws ConnectException { Preconditions.checkNotNull(source, "source must not be null"); - format = source.format(); + this.source = source; try { - final Process process = Runtime.getRuntime().exec(Iterables.toArray(ImmutableList.builder().add(binary(format)).addAll(parameters(format)).build(), String.class)); + final Process process = Runtime.getRuntime().exec(Iterables.toArray(ImmutableList.builder().add(binary(source.format())).addAll(parameters(source.format())).build(), String.class)); final InputStream processOutput = process.getInputStream(); final OutputStream processInput = process.getOutputStream(); final InputStream processError = process.getErrorStream(); diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/MultiSourceFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/MultiSourceFilter.java index 704324d..a6566ed 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/MultiSourceFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/MultiSourceFilter.java @@ -59,9 +59,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 +66,9 @@ public class MultiSourceFilter implements Filter, ReusableSink { @Override public Format format() { - return format; + synchronized (syncObject) { + return connection.source.format(); + } } @Override @@ -86,10 +85,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) { diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java index c40f90f..c87a986 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java @@ -49,7 +49,7 @@ public class RateLimitingFilter implements Filter { private final int rate; /** The source’s format. */ - private Format format; + private Source source; /** The input stream to read from. */ private PipedInputStream pipedInputStream = new PipedInputStream(); @@ -70,7 +70,7 @@ public class RateLimitingFilter implements Filter { @Override public Format format() { - return format; + return source.format(); } @Override @@ -87,7 +87,7 @@ public class RateLimitingFilter implements Filter { public void connect(Source source) throws ConnectException { Preconditions.checkNotNull(source, "source must not be null"); - format = source.format(); + this.source = source; final long start = System.currentTimeMillis(); try { pipedInputStream = new PipedInputStream();