From 627013e19cfed9aaf339aca97b41f6b63a9c780a Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Mon, 2 Nov 2020 16:09:31 +0300 Subject: [PATCH] Fix bugs #4 --- src/main/java/InnaIrcBot/BotStart.java | 1 - .../java/InnaIrcBot/ProvidersConsumers/ChanConsumer.java | 2 +- .../java/InnaIrcBot/ProvidersConsumers/DataProvider.java | 6 ++++-- src/main/java/InnaIrcBot/ReconnectControl.java | 9 +++++++-- .../java/InnaIrcBot/linkstitles/LinksTitleManager.java | 4 ++++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/InnaIrcBot/BotStart.java b/src/main/java/InnaIrcBot/BotStart.java index 16c5b91..02febc5 100644 --- a/src/main/java/InnaIrcBot/BotStart.java +++ b/src/main/java/InnaIrcBot/BotStart.java @@ -17,7 +17,6 @@ public class BotStart { } if (cli.hasOption("c") || cli.hasOption("configuration")){ final String[] arguments = cli.getOptionValues("configuration"); - for (String a: arguments) ConnectionsBuilder.buildConnections(arguments); return; } diff --git a/src/main/java/InnaIrcBot/ProvidersConsumers/ChanConsumer.java b/src/main/java/InnaIrcBot/ProvidersConsumers/ChanConsumer.java index d61bf5b..21c51d6 100644 --- a/src/main/java/InnaIrcBot/ProvidersConsumers/ChanConsumer.java +++ b/src/main/java/InnaIrcBot/ProvidersConsumers/ChanConsumer.java @@ -70,7 +70,7 @@ public class ChanConsumer implements Runnable { parse(); } } catch (InterruptedException e){ - System.out.println("ChanConsumer "+serverName+"/"+channelName+"Interrupted "+e.getMessage()); + System.out.println("ChanConsumer "+serverName+"/"+channelName+" Interrupted "); } } diff --git a/src/main/java/InnaIrcBot/ProvidersConsumers/DataProvider.java b/src/main/java/InnaIrcBot/ProvidersConsumers/DataProvider.java index 5005dbe..653faf5 100644 --- a/src/main/java/InnaIrcBot/ProvidersConsumers/DataProvider.java +++ b/src/main/java/InnaIrcBot/ProvidersConsumers/DataProvider.java @@ -117,8 +117,10 @@ public class DataProvider implements Runnable { private void close(){ try { - systemConsumerThread.interrupt(); - systemConsumerThread.join(); + if (systemConsumerThread != null) { + systemConsumerThread.interrupt(); + systemConsumerThread.join(); + } StreamProvider.delStream(server); ReconnectControl.notify(server); } diff --git a/src/main/java/InnaIrcBot/ReconnectControl.java b/src/main/java/InnaIrcBot/ReconnectControl.java index 8a67c37..35dd9fa 100644 --- a/src/main/java/InnaIrcBot/ReconnectControl.java +++ b/src/main/java/InnaIrcBot/ReconnectControl.java @@ -1,5 +1,7 @@ package InnaIrcBot; +import InnaIrcBot.linkstitles.LinksTitleManager; + import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -17,19 +19,22 @@ public class ReconnectControl { } public static synchronized void notify(String server){ - if (! serversList.getOrDefault(server, false)) + if (! serversList.getOrDefault(server, false)) { + LinksTitleManager.interrupt(); return; + } int count = serversReconnects.get(server); if (count > 5) { serversList.replace(server, false); + LinksTitleManager.interrupt(); return; } count++; serversReconnects.put(server, count); - System.out.println("Main thread \"" + server + "\" removed from observable list after unexpected finish.\n"); + System.out.println("Main thread \"" + server + "\" removed from observable list after unexpected finish ("+count+").\n"); ConnectionsBuilder.getConnections().startNewConnection(server); } } diff --git a/src/main/java/InnaIrcBot/linkstitles/LinksTitleManager.java b/src/main/java/InnaIrcBot/linkstitles/LinksTitleManager.java index c317b99..6c751c4 100644 --- a/src/main/java/InnaIrcBot/linkstitles/LinksTitleManager.java +++ b/src/main/java/InnaIrcBot/linkstitles/LinksTitleManager.java @@ -15,4 +15,8 @@ public class LinksTitleManager { } return queue; } + + public static void interrupt(){ + thread.interrupt(); + } }