|
@@ -23,28 +23,48 @@
|
23
|
23
|
package com.dmdirc;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.ClientModule.GlobalConfig;
|
|
26
|
+import com.dmdirc.events.ClientClosedEvent;
|
26
|
27
|
import com.dmdirc.interfaces.ConnectionManager;
|
27
|
28
|
import com.dmdirc.interfaces.LifecycleController;
|
|
29
|
+import com.dmdirc.interfaces.SystemLifecycleComponent;
|
28
|
30
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
|
31
|
+import com.dmdirc.interfaces.config.IdentityController;
|
|
32
|
+
|
|
33
|
+import java.util.HashSet;
|
|
34
|
+import java.util.Set;
|
29
|
35
|
|
30
|
36
|
import javax.inject.Inject;
|
|
37
|
+import javax.inject.Singleton;
|
31
|
38
|
|
32
|
39
|
/**
|
33
|
40
|
* Simple {@link LifecycleController} implementation that calls {@link System#exit(int)}.
|
34
|
41
|
*/
|
|
42
|
+@Singleton
|
35
|
43
|
public class SystemLifecycleController implements LifecycleController {
|
36
|
44
|
|
37
|
45
|
/** Controller to retrieve settings from. */
|
38
|
46
|
private final AggregateConfigProvider configProvider;
|
|
47
|
+ /** Components to shut down when the client quits. */
|
|
48
|
+ private final Set<SystemLifecycleComponent> lifecycleComponents;
|
39
|
49
|
/** Manager to use to disconnect servers. */
|
40
|
50
|
private final ConnectionManager connectionManager;
|
|
51
|
+ /** The event bus to raise client closed events on. */
|
|
52
|
+ private final DMDircMBassador eventBus;
|
|
53
|
+ /** The identity controller to save when quitting. */
|
|
54
|
+ private final IdentityController identityController;
|
41
|
55
|
|
42
|
56
|
@Inject
|
43
|
57
|
public SystemLifecycleController(
|
44
|
58
|
@GlobalConfig final AggregateConfigProvider configProvider,
|
45
|
|
- final ConnectionManager connectionManager) {
|
|
59
|
+ final Set<SystemLifecycleComponent> lifecycleComponents,
|
|
60
|
+ final ConnectionManager connectionManager,
|
|
61
|
+ final DMDircMBassador eventBus,
|
|
62
|
+ final IdentityController identityController) {
|
46
|
63
|
this.configProvider = configProvider;
|
|
64
|
+ this.lifecycleComponents = new HashSet<>(lifecycleComponents);
|
47
|
65
|
this.connectionManager = connectionManager;
|
|
66
|
+ this.eventBus = eventBus;
|
|
67
|
+ this.identityController = identityController;
|
48
|
68
|
}
|
49
|
69
|
|
50
|
70
|
@Override
|
|
@@ -64,6 +84,11 @@ public class SystemLifecycleController implements LifecycleController {
|
64
|
84
|
|
65
|
85
|
@Override
|
66
|
86
|
public void quit(final String reason, final int exitCode) {
|
|
87
|
+ lifecycleComponents.forEach(SystemLifecycleComponent::shutDown);
|
|
88
|
+
|
|
89
|
+ // TODO: Make all of these into lifecycle components
|
|
90
|
+ eventBus.publish(new ClientClosedEvent());
|
|
91
|
+ identityController.saveAll();
|
67
|
92
|
connectionManager.disconnectAll(reason);
|
68
|
93
|
|
69
|
94
|
System.exit(exitCode);
|