Browse Source

Make handling of lifecyclecomponents more generic.

Change-Id: If5f4b2c140a40b768f0acb616b6c7ec15165dc1e
Reviewed-on: http://gerrit.dmdirc.com/3526
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 10 years ago
parent
commit
7f69a44212
2 changed files with 21 additions and 7 deletions
  1. 14
    7
      src/com/dmdirc/Main.java
  2. 7
    0
      src/com/dmdirc/commandparser/aliases/AliasesModule.java

+ 14
- 7
src/com/dmdirc/Main.java View File

@@ -27,12 +27,12 @@ import com.dmdirc.actions.ActionManager;
27 27
 import com.dmdirc.actions.ColourActionComparison;
28 28
 import com.dmdirc.commandline.CommandLineParser;
29 29
 import com.dmdirc.commandparser.CommandManager;
30
-import com.dmdirc.commandparser.aliases.AliasLifecycleManager;
31 30
 import com.dmdirc.events.ClientClosedEvent;
32 31
 import com.dmdirc.events.ClientOpenedEvent;
33 32
 import com.dmdirc.events.FeedbackNagEvent;
34 33
 import com.dmdirc.events.FirstRunEvent;
35 34
 import com.dmdirc.interfaces.CommandController.CommandDetails;
35
+import com.dmdirc.interfaces.SystemLifecycleComponent;
36 36
 import com.dmdirc.interfaces.config.IdentityController;
37 37
 import com.dmdirc.interfaces.ui.UIController;
38 38
 import com.dmdirc.logger.DMDircExceptionHandler;
@@ -84,7 +84,8 @@ public class Main {
84 84
     private final GlobalWindowManager globalWindowManager;
85 85
     /** The colour-based action comparisons. */
86 86
     private final ColourActionComparison colourActionComparison;
87
-    private final AliasLifecycleManager aliasLifecycleManager;
87
+    /** The set of known lifecycle components. */
88
+    private final Set<SystemLifecycleComponent> lifecycleComponents;
88 89
     /** The event bus to dispatch events on. */
89 90
     private final EventBus eventBus;
90 91
     /** The commands to load into the command manager. */
@@ -102,7 +103,7 @@ public class Main {
102 103
      * @param corePluginExtractor    Extractor to use for core plugins.
103 104
      * @param globalWindowManager    Global window manager to use.
104 105
      * @param colourActionComparison The colour-based action comparisons.
105
-     * @param aliasLifecycleManager  The alias lifecycle manager.
106
+     * @param lifecycleComponents    The set of known lifecycle components.
106 107
      * @param eventBus               The event bus to dispatch events on.
107 108
      * @param commands               The commands to be loaded into the command manager.
108 109
      */
@@ -117,7 +118,7 @@ public class Main {
117 118
             final CorePluginExtractor corePluginExtractor,
118 119
             final GlobalWindowManager globalWindowManager,
119 120
             final ColourActionComparison colourActionComparison,
120
-            final AliasLifecycleManager aliasLifecycleManager,
121
+            final Set<SystemLifecycleComponent> lifecycleComponents,
121 122
             final EventBus eventBus,
122 123
             final Set<CommandDetails> commands) {
123 124
         this.identityManager = identityManager;
@@ -129,7 +130,7 @@ public class Main {
129 130
         this.commandManager = commandManager;
130 131
         this.globalWindowManager = globalWindowManager;
131 132
         this.colourActionComparison = colourActionComparison;
132
-        this.aliasLifecycleManager = aliasLifecycleManager;
133
+        this.lifecycleComponents = lifecycleComponents;
133 134
         this.eventBus = eventBus;
134 135
         this.commands = commands;
135 136
     }
@@ -176,13 +177,19 @@ public class Main {
176 177
         commandLineParser.processArguments(serverManager);
177 178
 
178 179
         globalWindowManager.init();
179
-        aliasLifecycleManager.startUp();
180
+
181
+        for (SystemLifecycleComponent component : lifecycleComponents) {
182
+            component.startUp();
183
+        }
180 184
 
181 185
         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
182 186
 
183 187
             @Override
184 188
             public void run() {
185
-                aliasLifecycleManager.shutDown();
189
+                for (SystemLifecycleComponent component : lifecycleComponents) {
190
+                    component.shutDown();
191
+                }
192
+
186 193
                 eventBus.post(new ClientClosedEvent());
187 194
                 serverManager.disconnectAll("Unexpected shutdown");
188 195
                 identityManager.saveAll();

+ 7
- 0
src/com/dmdirc/commandparser/aliases/AliasesModule.java View File

@@ -22,6 +22,8 @@
22 22
 
23 23
 package com.dmdirc.commandparser.aliases;
24 24
 
25
+import com.dmdirc.interfaces.SystemLifecycleComponent;
26
+
25 27
 import javax.inject.Singleton;
26 28
 
27 29
 import dagger.Module;
@@ -39,4 +41,9 @@ public class AliasesModule {
39 41
         return store;
40 42
     }
41 43
 
44
+    @Provides(type = Provides.Type.SET)
45
+    public SystemLifecycleComponent getLifeycleComponent(final AliasLifecycleManager manager) {
46
+        return manager;
47
+    }
48
+
42 49
 }

Loading…
Cancel
Save