瀏覽代碼

AutoCommand fixes.

Don't use a sorted map, as the commands aren't sortable.
Unsubscribe when stopping, instead of subscribing a second time...

Change-Id: Ib0301c9089de950dc4341c44169d94cb8dc2b2b4
Reviewed-on: http://gerrit.dmdirc.com/3915
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
pull/1/head
Chris Smith 9 年之前
父節點
當前提交
2105ee7eb5
共有 1 個文件被更改,包括 7 次插入5 次删除
  1. 7
    5
      src/com/dmdirc/commandparser/auto/AutoCommandManager.java

+ 7
- 5
src/com/dmdirc/commandparser/auto/AutoCommandManager.java 查看文件

@@ -27,7 +27,7 @@ import com.dmdirc.DMDircMBassador;
27 27
 import java.util.Collections;
28 28
 import java.util.Map;
29 29
 import java.util.Set;
30
-import java.util.concurrent.ConcurrentSkipListMap;
30
+import java.util.concurrent.ConcurrentHashMap;
31 31
 
32 32
 import javax.inject.Inject;
33 33
 import javax.inject.Singleton;
@@ -45,7 +45,7 @@ public class AutoCommandManager {
45 45
     /** The factory to use to create handlers. */
46 46
     private final AutoCommandHandlerFactory factory;
47 47
     /** Known auto commands, mapped on to their handlers. */
48
-    private final Map<AutoCommand, AutoCommandHandler> autoCommands = new ConcurrentSkipListMap<>();
48
+    private final Map<AutoCommand, AutoCommandHandler> autoCommands = new ConcurrentHashMap<>();
49 49
     /** Whether the manager has been started or not. */
50 50
     private boolean started;
51 51
 
@@ -56,7 +56,9 @@ public class AutoCommandManager {
56 56
      * @param factory  The factory to use to create handlers.
57 57
      */
58 58
     @Inject
59
-    public AutoCommandManager(final DMDircMBassador eventBus, final AutoCommandHandlerFactory factory) {
59
+    public AutoCommandManager(
60
+            final DMDircMBassador eventBus,
61
+            final AutoCommandHandlerFactory factory) {
60 62
         this.eventBus = eventBus;
61 63
         this.factory = factory;
62 64
     }
@@ -77,7 +79,7 @@ public class AutoCommandManager {
77 79
     public void stop() {
78 80
         started = false;
79 81
         for (AutoCommandHandler handler : autoCommands.values()) {
80
-            eventBus.subscribe(handler);
82
+            eventBus.unsubscribe(handler);
81 83
         }
82 84
     }
83 85
 
@@ -107,7 +109,7 @@ public class AutoCommandManager {
107 109
         final AutoCommandHandler handler = autoCommands.remove(autoCommand);
108 110
 
109 111
         if (started) {
110
-            eventBus.subscribe(handler);
112
+            eventBus.unsubscribe(handler);
111 113
         }
112 114
     }
113 115
 

Loading…
取消
儲存