Browse Source

Merge pull request #152 from ShaneMcC/parserShutdown

Add shutdown infra to parser.
pull/154/head
Shane Mc Cormack 7 years ago
parent
commit
06cbbaee16

+ 5
- 0
common/src/main/java/com/dmdirc/parser/common/BaseParser.java View File

@@ -105,6 +105,11 @@ public abstract class BaseParser extends ThreadedParser {
105 105
         }
106 106
     }
107 107
 
108
+    @Override
109
+    public void shutdown() {
110
+        callbackManager.shutdown();
111
+    }
112
+
108 113
     @Override
109 114
     public void quit(final String reason) {
110 115
         disconnect(reason);

+ 11
- 0
common/src/main/java/com/dmdirc/parser/common/BaseSocketAwareParser.java View File

@@ -69,6 +69,17 @@ public abstract class BaseSocketAwareParser extends BaseParser {
69 69
         return localPort;
70 70
     }
71 71
 
72
+    @Override
73
+    public void shutdown() {
74
+        try {
75
+            if (socket != null) {
76
+                socket.close();
77
+            }
78
+        } catch (IOException e) {
79
+        }
80
+        super.shutdown();
81
+    }
82
+
72 83
     /**
73 84
      * Gets the current connection timeout.
74 85
      *

+ 7
- 0
common/src/main/java/com/dmdirc/parser/interfaces/Parser.java View File

@@ -54,6 +54,13 @@ public interface Parser {
54 54
      */
55 55
     void disconnect(String message);
56 56
 
57
+    /**
58
+     * Called when we are finished with this parser and no longer need it anymore.
59
+     *
60
+     * This allows the parser to cleanup after itself.
61
+     */
62
+    void shutdown();
63
+
57 64
     /**
58 65
      *
59 66
      * Disconnect from server.  This method will wait for the server to

+ 4
- 3
irc/src/main/java/com/dmdirc/parser/irc/IRCParser.java View File

@@ -885,18 +885,19 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
885 885
         callDebugInfo(DEBUG_INFO, "End Thread Execution");
886 886
     }
887 887
 
888
-    /** Close socket on destroy. */
889 888
     @Override
890
-    protected void finalize() throws Throwable {
889
+    public void shutdown() {
891 890
         try {
892 891
             // See note at disconnect() method for why we close rawSocket.
893 892
             if (rawSocket != null) {
894 893
                 rawSocket.close();
894
+                socket = null;
895
+                rawSocket = null;
895 896
             }
896 897
         } catch (IOException e) {
897 898
             callDebugInfo(DEBUG_SOCKET, "Could not close socket");
898 899
         }
899
-        super.finalize();
900
+        super.shutdown();
900 901
     }
901 902
 
902 903
     /**

Loading…
Cancel
Save