From ff99325d519095f49576105b7cd4b330b3bc8902 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 14 Apr 2013 12:17:14 +0200 Subject: [PATCH] Let the core verify each minute that all configured channels are joined. --- .../java/net/pterodactylus/xdcc/core/Core.java | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/xdcc/core/Core.java b/src/main/java/net/pterodactylus/xdcc/core/Core.java index a395537..1f15af0 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -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 David ‘Bombe’ Roden */ -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() { } -- 2.7.4