Let the core verify each minute that all configured channels are joined.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Apr 2013 10:17:14 +0000 (12:17 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Apr 2013 10:17:14 +0000 (12:17 +0200)
src/main/java/net/pterodactylus/xdcc/core/Core.java

index a395537..1f15af0 100644 (file)
@@ -27,6 +27,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -71,7 +72,7 @@ import com.google.common.collect.Table;
 import com.google.common.eventbus.EventBus;
 import com.google.common.eventbus.Subscribe;
 import com.google.common.io.Closeables;
-import com.google.common.util.concurrent.AbstractIdleService;
+import com.google.common.util.concurrent.AbstractExecutionThreadService;
 import com.google.inject.Inject;
 
 /**
@@ -79,7 +80,7 @@ import com.google.inject.Inject;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class Core extends AbstractIdleService {
+public class Core extends AbstractExecutionThreadService {
 
        /** The logger. */
        private static final Logger logger = Logger.getLogger(Core.class.getName());
@@ -235,6 +236,31 @@ public class Core extends AbstractIdleService {
        }
 
        @Override
+       protected void run() throws Exception {
+               while (isRunning()) {
+                       try {
+                               Thread.sleep(TimeUnit.MINUTES.toMillis(1));
+                       } catch (InterruptedException ie1) {
+                               /* ignore. */
+                       }
+
+                       /* find channels that should be monitored but are not. */
+                       for (Channel channel : channels) {
+                               if (joinedChannels.contains(channel)) {
+                                       continue;
+                               }
+
+                               connectNetwork(channel.network());
+                               Connection connection = networkConnections.get(channel.network());
+                               if (connection.established()) {
+                                       eventBus.post(new GenericMessage(String.format("Trying to join %s on %s.", channel.name(), channel.network().name())));
+                                       connection.joinChannel(channel.name());
+                               }
+                       }
+               }
+       }
+
+       @Override
        protected void shutDown() {
        }