Create all controlled components with an event bus.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / sink / Icecast2Sink.java
index 359c262..4d492fd 100644 (file)
@@ -38,6 +38,7 @@ import com.google.common.base.Function;
 import com.google.common.base.Joiner;
 import com.google.common.base.Optional;
 import com.google.common.collect.FluentIterable;
+import com.google.common.eventbus.EventBus;
 import com.google.common.io.BaseEncoding;
 import com.google.common.io.Closeables;
 
@@ -52,6 +53,9 @@ public class Icecast2Sink implements Sink {
        /** The logger. */
        private static final Logger logger = Logger.getLogger(Icecast2Sink.class.getName());
 
+       /** The event bus. */
+       private final EventBus eventBus;
+
        /** The server name. */
        private final String server;
 
@@ -78,9 +82,14 @@ public class Icecast2Sink implements Sink {
 
        private OutputStream socketOutputStream;
 
+       /** The current metadata. */
+       private Metadata metadata;
+
        /**
         * Creates a new Icecast2 sink.
         *
+        * @param eventBus
+        *              The event bus
         * @param server
         *              The hostname of the server
         * @param port
@@ -99,7 +108,8 @@ public class Icecast2Sink implements Sink {
         *              {@code true} to publish the server in a public directory, {@code false} to
         *              not publish it
         */
-       public Icecast2Sink(String server, int port, String password, String mountPoint, String serverName, String serverDescription, String genre, boolean publishServer) {
+       public Icecast2Sink(EventBus eventBus, String server, int port, String password, String mountPoint, String serverName, String serverDescription, String genre, boolean publishServer) {
+               this.eventBus = eventBus;
                this.server = server;
                this.port = port;
                this.password = password;
@@ -115,7 +125,17 @@ public class Icecast2Sink implements Sink {
        //
 
        @Override
-       public List<Controller> controllers() {
+       public String name() {
+               return String.format("icecast://%s:%d/%s", server, port, mountPoint);
+       }
+
+       @Override
+       public Metadata metadata() {
+               return metadata;
+       }
+
+       @Override
+       public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
 
@@ -157,6 +177,7 @@ public class Icecast2Sink implements Sink {
 
        @Override
        public void metadataUpdated(final Metadata metadata) {
+               this.metadata = metadata;
                new Thread(new Runnable() {
 
                        @Override