Don’t forget to subscribe to ConnectionFailed events.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / core / Core.java
index fb3e61e..24d9c38 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.xdcc.core;
 
+import static net.pterodactylus.xdcc.data.Channel.TO_NETWORK;
 import static net.pterodactylus.xdcc.data.Download.FILTER_RUNNING;
 
 import java.io.File;
@@ -69,6 +70,7 @@ import net.pterodactylus.xdcc.data.Network;
 import net.pterodactylus.xdcc.data.Pack;
 import net.pterodactylus.xdcc.data.Server;
 
+import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.collect.FluentIterable;
@@ -158,6 +160,29 @@ public class Core extends AbstractExecutionThreadService {
        }
 
        /**
+        * Returns all defined networks.
+        *
+        * @return All defined networks
+        */
+       public Collection<Network> networks() {
+               return FluentIterable.from(channels).transform(TO_NETWORK).toSet();
+       }
+
+       /**
+        * Returns all connected networks.
+        *
+        * @return All connected networks
+        */
+       public Collection<Network> connectedNetworks() {
+               return Lists.newArrayList(Optional.presentInstances(FluentIterable.from(networkConnections.values()).transform(new Function<Connection, Optional<Network>>() {
+                       @Override
+                       public Optional<Network> apply(Connection connection) {
+                               return getNetwork(connection);
+                       }
+               })));
+       }
+
+       /**
         * Returns all configured channels. Due to various circumstances, configured
         * channels might not actually be joined.
         *
@@ -479,6 +504,7 @@ public class Core extends AbstractExecutionThreadService {
         * @param connectionFailed
         *              The connection failed event
         */
+       @Subscribe
        public void connectionFailed(ConnectionFailed connectionFailed) {
                removeConnection(connectionFailed.connection());
        }