Просмотр исходного кода

Merge pull request #152 from ShaneMcC/parserShutdown

Add shutdown infra to parser.
pull/154/head
Shane Mc Cormack 7 лет назад
Родитель
Сommit
06cbbaee16

+ 5
- 0
common/src/main/java/com/dmdirc/parser/common/BaseParser.java Просмотреть файл

105
         }
105
         }
106
     }
106
     }
107
 
107
 
108
+    @Override
109
+    public void shutdown() {
110
+        callbackManager.shutdown();
111
+    }
112
+
108
     @Override
113
     @Override
109
     public void quit(final String reason) {
114
     public void quit(final String reason) {
110
         disconnect(reason);
115
         disconnect(reason);

+ 11
- 0
common/src/main/java/com/dmdirc/parser/common/BaseSocketAwareParser.java Просмотреть файл

69
         return localPort;
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
      * Gets the current connection timeout.
84
      * Gets the current connection timeout.
74
      *
85
      *

+ 7
- 0
common/src/main/java/com/dmdirc/parser/interfaces/Parser.java Просмотреть файл

54
      */
54
      */
55
     void disconnect(String message);
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
      * Disconnect from server.  This method will wait for the server to
66
      * Disconnect from server.  This method will wait for the server to

+ 4
- 3
irc/src/main/java/com/dmdirc/parser/irc/IRCParser.java Просмотреть файл

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

Загрузка…
Отмена
Сохранить