X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fdata%2Fsource%2FMultiSource.java;h=645a41db47cc27a3178791614d6c58f8b2aa3fd6;hb=34143658ae3c5157af1e145321618b1c244f5410;hp=80c3f562467a4890f225dc18637e527ecab1203a;hpb=6b199b3a9929aa9e0fb9314c82f395d8c9b245fe;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java index 80c3f56..645a41d 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java @@ -27,21 +27,21 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; import javax.swing.event.EventListenerList; -import net.pterodactylus.sonitus.data.AbstractControlledComponent; +import net.pterodactylus.sonitus.data.AbstractFilter; import net.pterodactylus.sonitus.data.Controller; +import net.pterodactylus.sonitus.data.DataPacket; +import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Metadata; -import net.pterodactylus.sonitus.data.Source; import com.google.inject.Inject; /** - * {@link Source} implementation that simply forwards another source and - * supports changing the source without letting the {@link - * net.pterodactylus.sonitus.data.Sink} know. + * {@link Filter} implementation that simply forwards data from another filter + * and supports changing the source without letting downstream filters know. * * @author David ‘Bombe’ Roden */ -public class MultiSource extends AbstractControlledComponent implements Source { +public class MultiSource extends AbstractFilter { /** The logger. */ private static final Logger logger = Logger.getLogger(MultiSource.class.getName()); @@ -50,7 +50,7 @@ public class MultiSource extends AbstractControlledComponent implements Source { private final EventListenerList sourceFinishedListeners = new EventListenerList(); /** The current source. */ - private final AtomicReference source = new AtomicReference(); + private final AtomicReference source = new AtomicReference(); /** Whether the source was changed. */ private boolean sourceChanged; @@ -95,17 +95,17 @@ public class MultiSource extends AbstractControlledComponent implements Source { * @param source * The new source to use */ - public void setSource(Source source) { + public void setSource(Filter source) { checkNotNull(source, "source must not be null"); - Source oldSource = this.source.getAndSet(source); + Filter oldSource = this.source.getAndSet(source); if (!source.equals(oldSource)) { synchronized (this.source) { sourceChanged = true; this.source.notifyAll(); } metadataUpdated(source.metadata()); - logger.info(String.format("Next Source set: %s", source)); + logger.info(String.format("Next Source set: %s", source.name())); } } @@ -115,7 +115,7 @@ public class MultiSource extends AbstractControlledComponent implements Source { /** * Notifies all registered listeners that the current source finished playing - * and that a new source should be {@link #setSource(Source) set}. + * and that a new source should be {@link #setSource(Filter) set}. * * @see SourceFinishedListener */ @@ -126,7 +126,7 @@ public class MultiSource extends AbstractControlledComponent implements Source { } // - // CONTROLLED METHODS + // FILTER METHODS // @Override @@ -136,7 +136,7 @@ public class MultiSource extends AbstractControlledComponent implements Source { @Override public Metadata metadata() { - if (super.metadata() == null) { + if (super.metadata() == Metadata.UNKNOWN) { /* no metadata yet, wait for it. */ waitForNewSource(); sourceChanged = false; @@ -144,16 +144,13 @@ public class MultiSource extends AbstractControlledComponent implements Source { return super.metadata(); } - // - // SOURCE METHODS - // - @Override - public byte[] get(int bufferSize) throws EOFException, IOException { + public DataPacket get(int bufferSize) throws EOFException, IOException { while (true) { try { return source.get().get(bufferSize); } catch (EOFException eofe1) { + logger.info(String.format("Got EOF from %s.", source.get().name())); waitForNewSource(); } finally { synchronized (source) { @@ -167,7 +164,7 @@ public class MultiSource extends AbstractControlledComponent implements Source { // PRIVATE METHODS // - /** Waits for a new source to be {@link #setSource(Source) set}. */ + /** Waits for a new source to be {@link #setSource(Filter) set}. */ private void waitForNewSource() { fireSourceFinished(); synchronized (source) {