Browse Source

Decouple Server from ServerManager.

SM now listens to frame closing events, so Server doesn't need
to hold on to a reference and inform it that it's closing.
pull/330/head
Chris Smith 9 years ago
parent
commit
e5a55f58ad

+ 1
- 7
src/com/dmdirc/Server.java View File

@@ -162,11 +162,9 @@ public class Server extends FrameContainer implements Connection {
162 162
     private StringConverter converter = new DefaultStringConverter();
163 163
     /** ParserFactory we use for creating parsers. */
164 164
     private final ParserFactory parserFactory;
165
-    /** ServerManager that created us. */
166
-    private final ServerManager manager;
167 165
     /** Factory to use to create new identities. */
168 166
     private final IdentityFactory identityFactory;
169
-    /** Window manager to pas to children. */
167
+    /** Window manager to pass to children. */
170 168
     private final WindowManager windowManager;
171 169
     /** The migrator to use to change our config provider. */
172 170
     private final ConfigProviderMigrator configMigrator;
@@ -193,7 +191,6 @@ public class Server extends FrameContainer implements Connection {
193 191
      * Creates a new server which will connect to the specified URL with the specified profile.
194 192
      */
195 193
     public Server(
196
-            final ServerManager manager,
197 194
             final ConfigProviderMigrator configMigrator,
198 195
             final CommandParser commandParser,
199 196
             final ParserFactory parserFactory,
@@ -228,7 +225,6 @@ public class Server extends FrameContainer implements Connection {
228 225
                         WindowComponent.INPUTFIELD.getIdentifier(),
229 226
                         WindowComponent.CERTIFICATE_VIEWER.getIdentifier()));
230 227
 
231
-        this.manager = manager;
232 228
         this.parserFactory = parserFactory;
233 229
         this.identityFactory = identityFactory;
234 230
         this.windowManager = windowManager;
@@ -885,8 +881,6 @@ public class Server extends FrameContainer implements Connection {
885 881
         closeQueries();
886 882
         removeInvites();
887 883
 
888
-        manager.unregisterServer(this);
889
-
890 884
         super.close();
891 885
     }
892 886
 

+ 1
- 4
src/com/dmdirc/ServerFactoryImpl.java View File

@@ -46,7 +46,6 @@ import javax.inject.Singleton;
46 46
 @Singleton
47 47
 public class ServerFactoryImpl {
48 48
 
49
-    private final Provider<ServerManager> manager;
50 49
     private final ParserFactory parserFactory;
51 50
     private final TabCompleterFactory tabCompleterFactory;
52 51
     private final IdentityFactory identityFactory;
@@ -63,7 +62,6 @@ public class ServerFactoryImpl {
63 62
 
64 63
     @Inject
65 64
     public ServerFactoryImpl(
66
-            final Provider<ServerManager> manager,
67 65
             final ParserFactory parserFactory,
68 66
             final TabCompleterFactory tabCompleterFactory,
69 67
             final IdentityFactory identityFactory,
@@ -77,7 +75,6 @@ public class ServerFactoryImpl {
77 75
             @ClientModule.UserConfig final ConfigProvider userSettings,
78 76
             final BackBufferFactory backBufferFactory,
79 77
             final UserManager userManager) {
80
-        this.manager = manager;
81 78
         this.parserFactory = parserFactory;
82 79
         this.tabCompleterFactory = tabCompleterFactory;
83 80
         this.identityFactory = identityFactory;
@@ -99,7 +96,7 @@ public class ServerFactoryImpl {
99 96
             final ScheduledExecutorService executorService,
100 97
             final URI uri,
101 98
             final Profile profile) {
102
-        return new Server(manager.get(), configMigrator, commandParser, parserFactory,
99
+        return new Server(configMigrator, commandParser, parserFactory,
103 100
                 tabCompleterFactory, identityFactory, messageSinkManager, windowManager,
104 101
                 channelFactory.get(), queryFactory.get(), urlBuilder, eventBus,
105 102
                 messageEncoderFactory, userSettings, executorService, uri, profile,

+ 13
- 2
src/com/dmdirc/ServerManager.java View File

@@ -25,6 +25,7 @@ package com.dmdirc;
25 25
 import com.dmdirc.commandparser.parsers.ServerCommandParser;
26 26
 import com.dmdirc.config.profiles.Profile;
27 27
 import com.dmdirc.config.profiles.ProfileManager;
28
+import com.dmdirc.events.FrameClosingEvent;
28 29
 import com.dmdirc.events.UserErrorEvent;
29 30
 import com.dmdirc.interfaces.CommandController;
30 31
 import com.dmdirc.interfaces.Connection;
@@ -51,6 +52,8 @@ import javax.inject.Inject;
51 52
 import javax.inject.Provider;
52 53
 import javax.inject.Singleton;
53 54
 
55
+import net.engio.mbassy.listener.Handler;
56
+
54 57
 /**
55 58
  * The ServerManager maintains a list of all servers, and provides methods to search or iterate over
56 59
  * them.
@@ -97,6 +100,7 @@ public class ServerManager implements ConnectionManager {
97 100
         this.windowManager = windowManager;
98 101
         this.serverFactoryImpl = serverFactory;
99 102
         this.eventBus = eventBus;
103
+        this.eventBus.subscribe(this);
100 104
     }
101 105
 
102 106
     @Override
@@ -122,7 +126,7 @@ public class ServerManager implements ConnectionManager {
122 126
      *
123 127
      * @param server The server to be registered
124 128
      */
125
-    public void registerServer(final Server server) {
129
+    void registerServer(final Server server) {
126 130
         servers.add(server);
127 131
     }
128 132
 
@@ -132,7 +136,7 @@ public class ServerManager implements ConnectionManager {
132 136
      *
133 137
      * @param server The server to be unregistered
134 138
      */
135
-    public void unregisterServer(final Server server) {
139
+    void unregisterServer(final Server server) {
136 140
         servers.remove(server);
137 141
     }
138 142
 
@@ -219,4 +223,11 @@ public class ServerManager implements ConnectionManager {
219 223
         }
220 224
     }
221 225
 
226
+    @Handler
227
+    void handleWindowClosing(final FrameClosingEvent event) {
228
+        if (event.getContainer() instanceof Server) {
229
+            unregisterServer((Server) event.getContainer());
230
+        }
231
+    }
232
+
222 233
 }

+ 0
- 2
test/com/dmdirc/ServerTest.java View File

@@ -54,7 +54,6 @@ import static org.mockito.Mockito.when;
54 54
 
55 55
 public class ServerTest {
56 56
 
57
-    @Mock private ServerManager serverManager;
58 57
     @Mock private Profile profile;
59 58
     @Mock private AggregateConfigProvider configManager;
60 59
     @Mock private ConfigBinder configBinder;
@@ -89,7 +88,6 @@ public class ServerTest {
89 88
                 Matchers.<CommandType>anyVararg())).thenReturn(tabCompleter);
90 89
 
91 90
         server = new Server(
92
-                serverManager,
93 91
                 configMigrator,
94 92
                 commandParser,
95 93
                 parserFactory,

Loading…
Cancel
Save