Sfoglia il codice sorgente

Introduce a ConnectionManager.

Remove most references to Server.

Change-Id: I8888522d58ff4d332c4a477702442c29a82d12ff
Depends-On: Ic0e6e5f95adc30e773945c95e73d321d589503d2
Reviewed-on: http://gerrit.dmdirc.com/3872
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 9 anni fa
parent
commit
7f222c800f

+ 11
- 5
src/com/dmdirc/ClientModule.java Vedi File

@@ -38,8 +38,9 @@ import com.dmdirc.config.IdentityManager;
38 38
 import com.dmdirc.config.InvalidIdentityFileException;
39 39
 import com.dmdirc.interfaces.ActionController;
40 40
 import com.dmdirc.interfaces.CommandController;
41
+import com.dmdirc.interfaces.ConnectionManager;
41 42
 import com.dmdirc.interfaces.LifecycleController;
42
-import com.dmdirc.interfaces.ServerFactory;
43
+import com.dmdirc.interfaces.ConnectionFactory;
43 44
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
44 45
 import com.dmdirc.interfaces.config.ConfigProvider;
45 46
 import com.dmdirc.interfaces.config.IdentityController;
@@ -113,6 +114,11 @@ public class ClientModule {
113 114
     /** The object graph to inject where necessary. */
114 115
     private ObjectGraph objectGraph;
115 116
 
117
+    @Provides
118
+    public ConnectionManager getConnectionManager(final ServerManager serverManager) {
119
+        return serverManager;
120
+    }
121
+
116 122
     @Provides
117 123
     @Singleton
118 124
     public DMDircMBassador getMBassador() {
@@ -206,9 +212,9 @@ public class ClientModule {
206 212
     @Provides
207 213
     @Singleton
208 214
     public CommandManager getCommandManager(
209
-            final ServerManager serverManager,
215
+            final ConnectionManager connectionManager,
210 216
             @GlobalConfig final AggregateConfigProvider globalConfig) {
211
-        final CommandManager manager = new CommandManager(serverManager);
217
+        final CommandManager manager = new CommandManager(connectionManager);
212 218
         manager.initialise(globalConfig);
213 219
         return manager;
214 220
     }
@@ -275,8 +281,8 @@ public class ClientModule {
275 281
     }
276 282
 
277 283
     @Provides
278
-    public ServerFactory getServerFactory(final ServerManager serverManager) {
279
-        return serverManager;
284
+    public ConnectionFactory getServerFactory(final ConnectionManager connectionManager) {
285
+        return connectionManager;
280 286
     }
281 287
 
282 288
     @Provides

+ 7
- 6
src/com/dmdirc/Main.java Vedi File

@@ -32,6 +32,7 @@ import com.dmdirc.events.ClientOpenedEvent;
32 32
 import com.dmdirc.events.FeedbackNagEvent;
33 33
 import com.dmdirc.events.FirstRunEvent;
34 34
 import com.dmdirc.interfaces.CommandController.CommandDetails;
35
+import com.dmdirc.interfaces.ConnectionManager;
35 36
 import com.dmdirc.interfaces.Migrator;
36 37
 import com.dmdirc.interfaces.SystemLifecycleComponent;
37 38
 import com.dmdirc.interfaces.config.IdentityController;
@@ -70,7 +71,7 @@ public class Main {
70 71
     /** The identity manager the client will use. */
71 72
     private final IdentityController identityManager;
72 73
     /** The server manager the client will use. */
73
-    private final ServerManager serverManager;
74
+    private final ConnectionManager connectionManager;
74 75
     /** The action manager the client will use. */
75 76
     private final ActionManager actionManager;
76 77
     /** The command-line parser used for this instance. */
@@ -98,7 +99,7 @@ public class Main {
98 99
      * Creates a new instance of {@link Main}.
99 100
      *
100 101
      * @param identityManager        The identity manager the client will use.
101
-     * @param serverManager          The server manager the client will use.
102
+     * @param connectionManager          The server manager the client will use.
102 103
      * @param actionManager          The action manager the client will use.
103 104
      * @param commandLineParser      The command-line parser used for this instance.
104 105
      * @param pluginManager          The plugin manager the client will use.
@@ -114,7 +115,7 @@ public class Main {
114 115
     @Inject
115 116
     public Main(
116 117
             final IdentityController identityManager,
117
-            final ServerManager serverManager,
118
+            final ConnectionManager connectionManager,
118 119
             final ActionManager actionManager,
119 120
             final CommandLineParser commandLineParser,
120 121
             final PluginManager pluginManager,
@@ -127,7 +128,7 @@ public class Main {
127 128
             final DMDircMBassador eventBus,
128 129
             final Set<CommandDetails> commands) {
129 130
         this.identityManager = identityManager;
130
-        this.serverManager = serverManager;
131
+        this.connectionManager = connectionManager;
131 132
         this.actionManager = actionManager;
132 133
         this.commandLineParser = commandLineParser;
133 134
         this.pluginManager = pluginManager;
@@ -197,7 +198,7 @@ public class Main {
197 198
         actionManager.loadUserActions();
198 199
         eventBus.publishAsync(new ClientOpenedEvent());
199 200
 
200
-        commandLineParser.processArguments(serverManager);
201
+        commandLineParser.processArguments(connectionManager);
201 202
 
202 203
         globalWindowManager.init();
203 204
 
@@ -210,7 +211,7 @@ public class Main {
210 211
                 }
211 212
 
212 213
                 eventBus.publishAsync(new ClientClosedEvent());
213
-                serverManager.disconnectAll("Unexpected shutdown");
214
+                connectionManager.disconnectAll("Unexpected shutdown");
214 215
                 identityManager.saveAll();
215 216
             }
216 217
         }, "Shutdown thread"));

+ 16
- 57
src/com/dmdirc/ServerManager.java Vedi File

@@ -26,7 +26,7 @@ import com.dmdirc.commandparser.parsers.ServerCommandParser;
26 26
 import com.dmdirc.events.UserErrorEvent;
27 27
 import com.dmdirc.interfaces.CommandController;
28 28
 import com.dmdirc.interfaces.Connection;
29
-import com.dmdirc.interfaces.ServerFactory;
29
+import com.dmdirc.interfaces.ConnectionManager;
30 30
 import com.dmdirc.interfaces.config.ConfigProvider;
31 31
 import com.dmdirc.interfaces.config.ConfigProviderMigrator;
32 32
 import com.dmdirc.interfaces.config.IdentityController;
@@ -57,7 +57,7 @@ import static com.google.common.base.Preconditions.checkArgument;
57 57
  * them.
58 58
  */
59 59
 @Singleton
60
-public class ServerManager implements ServerFactory {
60
+public class ServerManager implements ConnectionManager {
61 61
 
62 62
     /** All servers that currently exist. */
63 63
     private final Set<Server> servers = new CopyOnWriteArraySet<>();
@@ -142,31 +142,19 @@ public class ServerManager implements ServerFactory {
142 142
         servers.remove(server);
143 143
     }
144 144
 
145
-    /**
146
-     * Returns a list of all servers.
147
-     *
148
-     * @return A list of all servers
149
-     */
150
-    public List<Connection> getServers() {
145
+    @Override
146
+    public List<Connection> getConnections() {
151 147
         return new ArrayList<Connection>(servers);
152 148
     }
153 149
 
154
-    /**
155
-     * Makes all servers disconnected with the specified quit message.
156
-     *
157
-     * @param message The quit message to send to the IRC servers
158
-     */
150
+    @Override
159 151
     public void disconnectAll(final String message) {
160 152
         for (Server server : servers) {
161 153
             server.disconnect(message);
162 154
         }
163 155
     }
164 156
 
165
-    /**
166
-     * Closes all servers with the specified quit message.
167
-     *
168
-     * @param message The quit message to send to the IRC servers
169
-     */
157
+    @Override
170 158
     public void closeAll(final String message) {
171 159
         for (Server server : servers) {
172 160
             server.disconnect(message);
@@ -174,23 +162,13 @@ public class ServerManager implements ServerFactory {
174 162
         }
175 163
     }
176 164
 
177
-    /**
178
-     * Returns the number of servers that are registered with the manager.
179
-     *
180
-     * @return number of registered servers
181
-     */
182
-    public int numServers() {
165
+    @Override
166
+    public int getConnectionCount() {
183 167
         return servers.size();
184 168
     }
185 169
 
186
-    /**
187
-     * Retrieves a list of servers connected to the specified network.
188
-     *
189
-     * @param network The network to search for
190
-     *
191
-     * @return A list of servers connected to the network
192
-     */
193
-    public List<Connection> getServersByNetwork(final String network) {
170
+    @Override
171
+    public List<Connection> getConnectionsByNetwork(final String network) {
194 172
         final List<Connection> res = new ArrayList<>();
195 173
 
196 174
         for (Server server : servers) {
@@ -202,33 +180,16 @@ public class ServerManager implements ServerFactory {
202 180
         return res;
203 181
     }
204 182
 
205
-    /**
206
-     * Creates a new server which will connect to the specified URI with the default profile.
207
-     *
208
-     * @param uri The URI to connect to
209
-     *
210
-     * @return The server which will be connecting
211
-     *
212
-     * @since 0.6.3
213
-     */
183
+    @Override
214 184
     public Connection connectToAddress(final URI uri) {
215 185
         return connectToAddress(uri,
216 186
                 identityController.getProvidersByType("profile").get(0));
217 187
     }
218 188
 
219
-    /**
220
-     * Creates a new server which will connect to the specified URI with the specified profile.
221
-     *
222
-     * @param uri     The URI to connect to
223
-     * @param profile The profile to use
224
-     *
225
-     * @return The server which will be connecting
226
-     *
227
-     * @since 0.6.3
228
-     */
229
-    public Server connectToAddress(final URI uri, final ConfigProvider profile) {
189
+    @Override
190
+    public Connection connectToAddress(final URI uri, final ConfigProvider profile) {
230 191
         checkArgument(profile.isProfile());
231
-        Server server = null;
192
+        Connection server = null;
232 193
 
233 194
         for (Server loopServer : servers) {
234 195
             if (loopServer.compareURI(uri)) {
@@ -254,11 +215,9 @@ public class ServerManager implements ServerFactory {
254 215
         return server;
255 216
     }
256 217
 
257
-    /**
258
-     * Connects the user to Quakenet if necessary and joins #DMDirc.
259
-     */
218
+    @Override
260 219
     public void joinDevChat() {
261
-        final List<Connection> qnetServers = getServersByNetwork("Quakenet");
220
+        final List<Connection> qnetServers = getConnectionsByNetwork("Quakenet");
262 221
 
263 222
         Connection connectedServer = null;
264 223
 

+ 5
- 4
src/com/dmdirc/SystemLifecycleController.java Vedi File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26
+import com.dmdirc.interfaces.ConnectionManager;
26 27
 import com.dmdirc.interfaces.LifecycleController;
27 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
28 29
 
@@ -36,14 +37,14 @@ public class SystemLifecycleController implements LifecycleController {
36 37
     /** Controller to retrieve settings from. */
37 38
     private final AggregateConfigProvider configProvider;
38 39
     /** Manager to use to disconnect servers. */
39
-    private final ServerManager serverManager;
40
+    private final ConnectionManager connectionManager;
40 41
 
41 42
     @Inject
42 43
     public SystemLifecycleController(
43 44
             @GlobalConfig final AggregateConfigProvider configProvider,
44
-            final ServerManager serverManager) {
45
+            final ConnectionManager connectionManager) {
45 46
         this.configProvider = configProvider;
46
-        this.serverManager = serverManager;
47
+        this.connectionManager = connectionManager;
47 48
     }
48 49
 
49 50
     @Override
@@ -63,7 +64,7 @@ public class SystemLifecycleController implements LifecycleController {
63 64
 
64 65
     @Override
65 66
     public void quit(final String reason, final int exitCode) {
66
-        serverManager.disconnectAll(reason);
67
+        connectionManager.disconnectAll(reason);
67 68
 
68 69
         System.exit(exitCode);
69 70
     }

+ 6
- 6
src/com/dmdirc/commandline/CommandLineParser.java Vedi File

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.commandline;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.ServerManager;
26
+import com.dmdirc.interfaces.ConnectionManager;
27 27
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
28 28
 import com.dmdirc.logger.ErrorLevel;
29 29
 import com.dmdirc.logger.Logger;
@@ -66,7 +66,7 @@ public class CommandLineParser {
66 66
     /** A list of addresses to autoconnect to. */
67 67
     private final List<URI> addresses = new ArrayList<>();
68 68
     /** Provider to use to get server managers. */
69
-    @Nullable private final Provider<ServerManager> serverManagerProvider;
69
+    @Nullable private final Provider<ConnectionManager> serverManagerProvider;
70 70
     /** Provider to use to get the global config. */
71 71
     @Nullable private final Provider<AggregateConfigProvider> globalConfigProvider;
72 72
     /** The parser to use for URIs. */
@@ -89,7 +89,7 @@ public class CommandLineParser {
89 89
      */
90 90
     @Inject
91 91
     public CommandLineParser(
92
-            @Nullable final Provider<ServerManager> serverManagerProvider,
92
+            @Nullable final Provider<ConnectionManager> serverManagerProvider,
93 93
             @Nullable @GlobalConfig final Provider<AggregateConfigProvider> globalConfigProvider,
94 94
             @Nullable final URIParser uriParser) {
95 95
         this.serverManagerProvider = serverManagerProvider;
@@ -417,11 +417,11 @@ public class CommandLineParser {
417 417
      * Processes arguments once the client has been loaded properly. This allows us to auto-connect
418 418
      * to servers, etc.
419 419
      *
420
-     * @param serverManager The server manager to use to connect servers.
420
+     * @param connectionManager The server manager to use to connect servers.
421 421
      */
422
-    public void processArguments(final ServerManager serverManager) {
422
+    public void processArguments(final ConnectionManager connectionManager) {
423 423
         for (URI address : addresses) {
424
-            serverManager.connectToAddress(address);
424
+            connectionManager.connectToAddress(address);
425 425
         }
426 426
     }
427 427
 

+ 3
- 3
src/com/dmdirc/commandline/RemoteServer.java Vedi File

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.commandline;
24 24
 
25
-import com.dmdirc.ServerManager;
25
+import com.dmdirc.interfaces.ConnectionManager;
26 26
 import com.dmdirc.logger.ErrorLevel;
27 27
 import com.dmdirc.logger.Logger;
28 28
 
@@ -46,14 +46,14 @@ public class RemoteServer implements RemoteInterface {
46 46
     /** The maximum port to use for RMI binding. */
47 47
     private static final int MAXPORT = MINPORT + 5;
48 48
     /** Provider for the server manager to use to connect. */
49
-    private final Provider<ServerManager> serverManager;
49
+    private final Provider<ConnectionManager> serverManager;
50 50
 
51 51
     /**
52 52
      * Crate a new RemoteServer.
53 53
      *
54 54
      * @param serverManager Provider of a server manager to use to connect.
55 55
      */
56
-    public RemoteServer(final Provider<ServerManager> serverManager) {
56
+    public RemoteServer(final Provider<ConnectionManager> serverManager) {
57 57
         this.serverManager = serverManager;
58 58
     }
59 59
 

+ 6
- 6
src/com/dmdirc/commandparser/CommandManager.java Vedi File

@@ -23,12 +23,12 @@
23 23
 package com.dmdirc.commandparser;
24 24
 
25 25
 import com.dmdirc.Query;
26
-import com.dmdirc.ServerManager;
27 26
 import com.dmdirc.commandparser.commands.Command;
28 27
 import com.dmdirc.commandparser.parsers.CommandParser;
29 28
 import com.dmdirc.config.ConfigBinding;
30 29
 import com.dmdirc.interfaces.CommandController;
31 30
 import com.dmdirc.interfaces.Connection;
31
+import com.dmdirc.interfaces.ConnectionManager;
32 32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
33 33
 import com.dmdirc.ui.input.TabCompleter;
34 34
 import com.dmdirc.ui.input.TabCompletionType;
@@ -50,7 +50,7 @@ public class CommandManager implements CommandController {
50 50
     /** A list of command parsers that have been instantiated. */
51 51
     private final MapList<CommandType, CommandParser> parsers = new MapList<>();
52 52
     /** The manager to use to iterate servers. */
53
-    private final ServerManager serverManager;
53
+    private final ConnectionManager connectionManager;
54 54
     /** The command char we're using. */
55 55
     @ConfigBinding(domain = "general", key = "commandchar")
56 56
     private char commandChar;
@@ -61,10 +61,10 @@ public class CommandManager implements CommandController {
61 61
     /**
62 62
      * Creates a new instance of the Command Manager.
63 63
      *
64
-     * @param serverManager the manager to use to iterate servers.
64
+     * @param connectionManager the manager to use to iterate servers.
65 65
      */
66
-    public CommandManager(final ServerManager serverManager) {
67
-        this.serverManager = serverManager;
66
+    public CommandManager(final ConnectionManager connectionManager) {
67
+        this.connectionManager = connectionManager;
68 68
     }
69 69
 
70 70
     @Override
@@ -155,7 +155,7 @@ public class CommandManager implements CommandController {
155 155
         final String commandName = getCommandChar() + command.getName();
156 156
 
157 157
         // TODO: This logic is probably in two places. Abstract it.
158
-        for (Connection server : serverManager.getServers()) {
158
+        for (Connection server : connectionManager.getConnections()) {
159 159
             if (command.getType() == CommandType.TYPE_SERVER
160 160
                     || command.getType() == CommandType.TYPE_GLOBAL) {
161 161
                 registerCommandName(server.getWindowModel().getTabCompleter(),

+ 6
- 6
src/com/dmdirc/commandparser/commands/global/AllServers.java Vedi File

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.commandparser.commands.global;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.ServerManager;
27 26
 import com.dmdirc.commandparser.BaseCommandInfo;
28 27
 import com.dmdirc.commandparser.CommandArguments;
29 28
 import com.dmdirc.commandparser.CommandInfo;
@@ -33,6 +32,7 @@ import com.dmdirc.commandparser.commands.IntelligentCommand;
33 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
34 33
 import com.dmdirc.interfaces.CommandController;
35 34
 import com.dmdirc.interfaces.Connection;
35
+import com.dmdirc.interfaces.ConnectionManager;
36 36
 import com.dmdirc.ui.input.AdditionalTabTargets;
37 37
 import com.dmdirc.ui.input.TabCompleterUtils;
38 38
 
@@ -49,18 +49,18 @@ public class AllServers extends Command implements IntelligentCommand {
49 49
             "allservers <command> - executes the command as though it had"
50 50
             + " been entered on all servers", CommandType.TYPE_GLOBAL);
51 51
     /** Server manager to use to iterate servers. */
52
-    private final ServerManager serverManager;
52
+    private final ConnectionManager connectionManager;
53 53
 
54 54
     /**
55 55
      * Creates a new instance of the {@link AllServers} command.
56 56
      *
57 57
      * @param controller    The controller that owns this command.
58
-     * @param serverManager The server manager to use to iterate servers.
58
+     * @param connectionManager The server manager to use to iterate servers.
59 59
      */
60 60
     @Inject
61
-    public AllServers(final CommandController controller, final ServerManager serverManager) {
61
+    public AllServers(final CommandController controller, final ConnectionManager connectionManager) {
62 62
         super(controller);
63
-        this.serverManager = serverManager;
63
+        this.connectionManager = connectionManager;
64 64
     }
65 65
 
66 66
     @Override
@@ -68,7 +68,7 @@ public class AllServers extends Command implements IntelligentCommand {
68 68
             final CommandArguments args, final CommandContext context) {
69 69
         final String command = args.getArgumentsAsString();
70 70
 
71
-        for (Connection target : serverManager.getServers()) {
71
+        for (Connection target : connectionManager.getConnections()) {
72 72
             target.getWindowModel().getCommandParser()
73 73
                     .parseCommand(target.getWindowModel(), command);
74 74
         }

+ 9
- 15
src/com/dmdirc/commandparser/commands/global/NewServer.java Vedi File

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.commandparser.commands.global;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.Server;
27 26
 import com.dmdirc.commandparser.BaseCommandInfo;
28 27
 import com.dmdirc.commandparser.CommandArguments;
29 28
 import com.dmdirc.commandparser.CommandInfo;
@@ -32,10 +31,9 @@ import com.dmdirc.commandparser.commands.Command;
32 31
 import com.dmdirc.commandparser.commands.IntelligentCommand;
33 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
34 33
 import com.dmdirc.interfaces.CommandController;
35
-import com.dmdirc.interfaces.ServerFactory;
34
+import com.dmdirc.interfaces.Connection;
35
+import com.dmdirc.interfaces.ConnectionFactory;
36 36
 import com.dmdirc.interfaces.config.IdentityController;
37
-import com.dmdirc.logger.ErrorLevel;
38
-import com.dmdirc.logger.Logger;
39 37
 import com.dmdirc.plugins.PluginManager;
40 38
 import com.dmdirc.plugins.Service;
41 39
 import com.dmdirc.ui.input.AdditionalTabTargets;
@@ -57,7 +55,7 @@ public class NewServer extends Command implements IntelligentCommand {
57 55
             "newserver <host[:[+]port]> [password] - connect to a new server",
58 56
             CommandType.TYPE_GLOBAL);
59 57
     /** The factory to use to construct servers. */
60
-    private final ServerFactory serverFactory;
58
+    private final ConnectionFactory connectionFactory;
61 59
     /** Plugin manager to query for available services. */
62 60
     private final PluginManager pluginManager;
63 61
     /** Identity controller to use to find profiles. */
@@ -69,7 +67,7 @@ public class NewServer extends Command implements IntelligentCommand {
69 67
      * Creates a new newserver command which will use the specified factory to construct servers.
70 68
      *
71 69
      * @param controller         The controller to use for command information.
72
-     * @param serverFactory      The factory to use to construct servers.
70
+     * @param connectionFactory      The factory to use to construct servers.
73 71
      * @param pluginManager      The plugin manager to use to query available services.
74 72
      * @param identityController Identity controller to use to find profiles.
75 73
      * @param uriParser          The parser to use for user input.
@@ -77,12 +75,12 @@ public class NewServer extends Command implements IntelligentCommand {
77 75
     @Inject
78 76
     public NewServer(
79 77
             final CommandController controller,
80
-            final ServerFactory serverFactory,
78
+            final ConnectionFactory connectionFactory,
81 79
             final PluginManager pluginManager,
82 80
             final IdentityController identityController,
83 81
             final URIParser uriParser) {
84 82
         super(controller);
85
-        this.serverFactory = serverFactory;
83
+        this.connectionFactory = connectionFactory;
86 84
         this.pluginManager = pluginManager;
87 85
         this.identityController = identityController;
88 86
         this.uriParser = uriParser;
@@ -98,16 +96,12 @@ public class NewServer extends Command implements IntelligentCommand {
98 96
 
99 97
         try {
100 98
             final URI address = uriParser.parseFromText(args.getArgumentsAsString());
101
-            final Server server = serverFactory.createServer(address,
99
+            final Connection server = connectionFactory.createServer(address,
102 100
                     identityController.getProvidersByType("profile").get(0));
103 101
             server.connect();
104 102
         } catch (InvalidURIException ex) {
105
-            if (origin == null) {
106
-                Logger.userError(ErrorLevel.LOW, "Invalid URI given to /newserver", ex);
107
-            } else {
108
-                origin.addLine(FORMAT_ERROR, "Invalid URI: " + ex.getMessage()
109
-                        + (ex.getCause() == null ? "" : ": " + ex.getCause().getMessage()));
110
-            }
103
+            origin.addLine(FORMAT_ERROR, "Invalid URI: " + ex.getMessage()
104
+                    + (ex.getCause() == null ? "" : ": " + ex.getCause().getMessage()));
111 105
         }
112 106
     }
113 107
 

src/com/dmdirc/interfaces/ServerFactory.java → src/com/dmdirc/interfaces/ConnectionFactory.java Vedi File

@@ -22,24 +22,23 @@
22 22
 
23 23
 package com.dmdirc.interfaces;
24 24
 
25
-import com.dmdirc.Server;
26 25
 import com.dmdirc.interfaces.config.ConfigProvider;
27 26
 
28 27
 import java.net.URI;
29 28
 
30 29
 /**
31
- * Interface for factories which create new {@link Server}s.
30
+ * Interface for factories which create new {@link Connection}s.
32 31
  */
33
-public interface ServerFactory {
32
+public interface ConnectionFactory {
34 33
 
35 34
     /**
36
-     * Creates a new server which will connect to the specified URL with the specified profile.
35
+     * Creates a new connection which will connect to the specified URL with the specified profile.
37 36
      *
38 37
      * @param uri     The address of the server to connect to
39 38
      * @param profile The profile to use
40 39
      *
41
-     * @return A new {@link Server} instance with the appropriate configuration
40
+     * @return A new {@link Connection} instance with the appropriate configuration
42 41
      */
43
-    Server createServer(final URI uri, final ConfigProvider profile);
42
+    Connection createServer(final URI uri, final ConfigProvider profile);
44 43
 
45 44
 }

+ 99
- 0
src/com/dmdirc/interfaces/ConnectionManager.java Vedi File

@@ -0,0 +1,99 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.interfaces;
24
+
25
+import com.dmdirc.interfaces.config.ConfigProvider;
26
+
27
+import java.net.URI;
28
+import java.util.List;
29
+
30
+/**
31
+ * Manager of {@link Connection}s.
32
+ */
33
+public interface ConnectionManager extends ConnectionFactory {
34
+
35
+    /**
36
+     * Returns a list of all connections.
37
+     *
38
+     * @return A list of all connections
39
+     */
40
+    List<Connection> getConnections();
41
+
42
+    /**
43
+     * Makes all connections disconnect with the specified quit message.
44
+     *
45
+     * @param message The quit message to send to the connections
46
+     */
47
+    void disconnectAll(String message);
48
+
49
+    /**
50
+     * Closes all connections with the specified quit message.
51
+     *
52
+     * @param message The quit message to send to the IRC servers
53
+     */
54
+    void closeAll(String message);
55
+
56
+    /**
57
+     * Returns the number of connections that are registered with the manager.
58
+     *
59
+     * @return number of registered connections
60
+     */
61
+    int getConnectionCount();
62
+
63
+    /**
64
+     * Retrieves a list of connections connected to the specified network.
65
+     *
66
+     * @param network The network to search for
67
+     *
68
+     * @return A list of servers connected to the network
69
+     */
70
+    List<Connection> getConnectionsByNetwork(String network);
71
+
72
+    /**
73
+     * Creates a new connection which will connect to the specified URI with the default profile.
74
+     *
75
+     * @param uri The URI to connect to
76
+     *
77
+     * @return The new connection.
78
+     *
79
+     * @since 0.6.3
80
+     */
81
+    Connection connectToAddress(URI uri);
82
+
83
+    /**
84
+     * Creates a new connection which will connect to the specified URI with the specified profile.
85
+     *
86
+     * @param uri     The URI to connect to
87
+     * @param profile The profile to use
88
+     *
89
+     * @return The server which will be connecting
90
+     *
91
+     * @since 0.6.3
92
+     */
93
+    Connection connectToAddress(URI uri, ConfigProvider profile);
94
+
95
+    /**
96
+     * Connects the user to Quakenet if necessary and joins #DMDirc.
97
+     */
98
+    void joinDevChat();
99
+}

+ 5
- 5
src/com/dmdirc/plugins/PluginInjectorInitialiser.java Vedi File

@@ -24,13 +24,13 @@ package com.dmdirc.plugins;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.DMDircMBassador;
27
-import com.dmdirc.ServerManager;
28 27
 import com.dmdirc.actions.ActionFactory;
29 28
 import com.dmdirc.actions.ActionManager;
30 29
 import com.dmdirc.actions.ActionSubstitutorFactory;
31 30
 import com.dmdirc.actions.wrappers.PerformWrapper;
32 31
 import com.dmdirc.commandparser.CommandManager;
33 32
 import com.dmdirc.config.prefs.PreferencesManager;
33
+import com.dmdirc.interfaces.ConnectionManager;
34 34
 import com.dmdirc.interfaces.LifecycleController;
35 35
 import com.dmdirc.interfaces.config.IdentityController;
36 36
 import com.dmdirc.messages.MessageSinkManager;
@@ -55,7 +55,7 @@ public class PluginInjectorInitialiser {
55 55
     private final ActionFactory actionFactory;
56 56
     private final PluginManager pluginManager;
57 57
     private final IdentityController identityController;
58
-    private final ServerManager serverManager;
58
+    private final ConnectionManager connectionManager;
59 59
     private final ThemeManager themeManager;
60 60
     private final CommandManager commandManager;
61 61
     private final MessageSinkManager messageSinkManager;
@@ -76,7 +76,7 @@ public class PluginInjectorInitialiser {
76 76
             final ActionFactory actionFactory,
77 77
             final PluginManager pluginManager,
78 78
             final IdentityController identityController,
79
-            final ServerManager serverManager,
79
+            final ConnectionManager connectionManager,
80 80
             final ThemeManager themeManager,
81 81
             final CommandManager commandManager,
82 82
             final MessageSinkManager messageSinkManager,
@@ -95,7 +95,7 @@ public class PluginInjectorInitialiser {
95 95
         this.actionFactory = actionFactory;
96 96
         this.pluginManager = pluginManager;
97 97
         this.identityController = identityController;
98
-        this.serverManager = serverManager;
98
+        this.connectionManager = connectionManager;
99 99
         this.themeManager = themeManager;
100 100
         this.commandManager = commandManager;
101 101
         this.messageSinkManager = messageSinkManager;
@@ -121,7 +121,7 @@ public class PluginInjectorInitialiser {
121 121
         injector.addParameter(actionManager);
122 122
         injector.addParameter(PluginManager.class, pluginManager);
123 123
         injector.addParameter(identityController);
124
-        injector.addParameter(ServerManager.class, serverManager);
124
+        injector.addParameter(ConnectionManager.class, connectionManager);
125 125
         injector.addParameter(commandManager);
126 126
         injector.addParameter(MessageSinkManager.class, messageSinkManager);
127 127
         injector.addParameter(WindowManager.class, windowManager);

+ 5
- 5
src/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModel.java Vedi File

@@ -23,10 +23,10 @@
23 23
 package com.dmdirc.ui.core.feedback;
24 24
 
25 25
 import com.dmdirc.ClientModule;
26
-import com.dmdirc.ServerManager;
27 26
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
28 27
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
29 28
 import com.dmdirc.interfaces.Connection;
29
+import com.dmdirc.interfaces.ConnectionManager;
30 30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
31 31
 import com.dmdirc.interfaces.ui.FeedbackDialogModel;
32 32
 import com.dmdirc.interfaces.ui.FeedbackDialogModelListener;
@@ -49,7 +49,7 @@ public class CoreFeedbackDialogModel implements FeedbackDialogModel {
49 49
     private final FeedbackSenderFactory feedbackSenderFactory;
50 50
     private final ListenerList listeners;
51 51
     private final AggregateConfigProvider config;
52
-    private final ServerManager serverManager;
52
+    private final ConnectionManager connectionManager;
53 53
     private final String configDirectory;
54 54
     private Optional<String> name;
55 55
     private Optional<String> email;
@@ -59,9 +59,9 @@ public class CoreFeedbackDialogModel implements FeedbackDialogModel {
59 59
 
60 60
     @Inject
61 61
     public CoreFeedbackDialogModel(@ClientModule.GlobalConfig final AggregateConfigProvider config,
62
-            final ServerManager serverManager, final FeedbackSenderFactory feedbackSenderFactory,
62
+            final ConnectionManager connectionManager, final FeedbackSenderFactory feedbackSenderFactory,
63 63
             @Directory(DirectoryType.BASE) final String configDirectory) {
64
-        this.serverManager = serverManager;
64
+        this.connectionManager = connectionManager;
65 65
         this.configDirectory = configDirectory;
66 66
         this.feedbackSenderFactory = feedbackSenderFactory;
67 67
         this.config = config;
@@ -170,7 +170,7 @@ public class CoreFeedbackDialogModel implements FeedbackDialogModel {
170 170
         final StringBuilder serverInfo = new StringBuilder(255);
171 171
         final StringBuilder dmdircInfo = new StringBuilder(255);
172 172
         if (getIncludeServerInfo()) {
173
-            for (Connection connection : serverManager.getServers()) {
173
+            for (Connection connection : connectionManager.getConnections()) {
174 174
                 if (connection.getState().isDisconnected()) {
175 175
                     continue;
176 176
                 }

+ 6
- 6
src/com/dmdirc/ui/core/newserver/CoreNewServerDialogModel.java Vedi File

@@ -24,7 +24,7 @@ package com.dmdirc.ui.core.newserver;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.ClientModule.UserConfig;
27
-import com.dmdirc.ServerManager;
27
+import com.dmdirc.interfaces.ConnectionManager;
28 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
29 29
 import com.dmdirc.interfaces.config.ConfigProvider;
30 30
 import com.dmdirc.interfaces.config.ConfigProviderListener;
@@ -58,7 +58,7 @@ public class CoreNewServerDialogModel implements NewServerDialogModel, ConfigPro
58 58
     private final ListenerList listeners;
59 59
     private final AggregateConfigProvider globalConfig;
60 60
     private final ConfigProvider userConfig;
61
-    private final ServerManager serverManager;
61
+    private final ConnectionManager connectionManager;
62 62
     private final IdentityController controller;
63 63
     private final List<ConfigProvider> profiles;
64 64
     private Optional<ConfigProvider> selectedProfile;
@@ -73,11 +73,11 @@ public class CoreNewServerDialogModel implements NewServerDialogModel, ConfigPro
73 73
             @GlobalConfig final AggregateConfigProvider globalConfig,
74 74
             @UserConfig final ConfigProvider userConfig,
75 75
             final IdentityController identityController,
76
-            final ServerManager serverManager) {
76
+            final ConnectionManager connectionManager) {
77 77
         this.globalConfig = globalConfig;
78 78
         this.userConfig = userConfig;
79 79
         this.controller = identityController;
80
-        this.serverManager = serverManager;
80
+        this.connectionManager = connectionManager;
81 81
         listeners = new ListenerList();
82 82
         profiles = new ArrayList<>(5);
83 83
         selectedProfile = Optional.absent();
@@ -239,9 +239,9 @@ public class CoreNewServerDialogModel implements NewServerDialogModel, ConfigPro
239 239
         }
240 240
         try {
241 241
             if (selectedProfile.isPresent()) {
242
-                serverManager.connectToAddress(getServerURI(), selectedProfile.get());
242
+                connectionManager.connectToAddress(getServerURI(), selectedProfile.get());
243 243
             } else {
244
-                serverManager.connectToAddress(getServerURI());
244
+                connectionManager.connectToAddress(getServerURI());
245 245
             }
246 246
         } catch (URISyntaxException ex) {
247 247
             //This is tested in isSaveAllowed, shouldn't happen here.

+ 6
- 6
src/com/dmdirc/ui/core/util/URLHandler.java Vedi File

@@ -23,9 +23,9 @@
23 23
 package com.dmdirc.ui.core.util;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.ServerManager;
27 26
 import com.dmdirc.events.UnknownURLEvent;
28 27
 import com.dmdirc.events.UserErrorEvent;
28
+import com.dmdirc.interfaces.ConnectionManager;
29 29
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 30
 import com.dmdirc.logger.ErrorLevel;
31 31
 import com.dmdirc.ui.StatusMessage;
@@ -51,7 +51,7 @@ public class URLHandler {
51 51
     /** Config manager. */
52 52
     private final AggregateConfigProvider config;
53 53
     /** Server manager to use to connect to servers. */
54
-    private final ServerManager serverManager;
54
+    private final ConnectionManager connectionManager;
55 55
     /** Status bar manager to use to show messages. */
56 56
     private final StatusBarManager statusBarManager;
57 57
     /** Desktop handler. */
@@ -62,18 +62,18 @@ public class URLHandler {
62 62
      *
63 63
      * @param eventBus         Event bus to fire unknown protocol errors on.
64 64
      * @param globalConfig     Config to retrieve settings from
65
-     * @param serverManager    Server manager to connect to servers
65
+     * @param connectionManager    Server manager to connect to servers
66 66
      * @param statusBarManager Status bar manager used to show messages
67 67
      */
68 68
     @Inject
69 69
     public URLHandler(
70 70
             final DMDircMBassador eventBus,
71 71
             final AggregateConfigProvider globalConfig,
72
-            final ServerManager serverManager,
72
+            final ConnectionManager connectionManager,
73 73
             final StatusBarManager statusBarManager) {
74 74
         this.eventBus = eventBus;
75 75
         this.config = globalConfig;
76
-        this.serverManager = serverManager;
76
+        this.connectionManager = connectionManager;
77 77
         this.statusBarManager = statusBarManager;
78 78
         this.desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
79 79
     }
@@ -175,7 +175,7 @@ public class URLHandler {
175 175
                 statusBarManager.setMessage(
176 176
                         new StatusMessage("Connecting to: " + uri.toString(),
177 177
                                 config));
178
-                serverManager.connectToAddress(uri);
178
+                connectionManager.connectToAddress(uri);
179 179
                 break;
180 180
             case "BROWSER":
181 181
                 statusBarManager.setMessage(

+ 12
- 12
test/com/dmdirc/ServerManagerTest.java Vedi File

@@ -95,23 +95,23 @@ public class ServerManagerTest {
95 95
     @Test
96 96
     public void testRegisterServer() {
97 97
         serverManager.registerServer(server);
98
-        assertEquals(1, serverManager.numServers());
98
+        assertEquals(1, serverManager.getConnectionCount());
99 99
     }
100 100
 
101 101
     @Test
102 102
     public void testUnregisterServer() {
103 103
         serverManager.registerServer(server);
104 104
         serverManager.unregisterServer(server);
105
-        assertEquals(0, serverManager.numServers());
105
+        assertEquals(0, serverManager.getConnectionCount());
106 106
     }
107 107
 
108 108
     @Test
109 109
     public void testNumServers() {
110
-        assertEquals(serverManager.getServers().size(), serverManager.numServers());
110
+        assertEquals(serverManager.getConnections().size(), serverManager.getConnectionCount());
111 111
         serverManager.registerServer(server);
112
-        assertEquals(serverManager.getServers().size(), serverManager.numServers());
112
+        assertEquals(serverManager.getConnections().size(), serverManager.getConnectionCount());
113 113
         serverManager.unregisterServer(server);
114
-        assertEquals(serverManager.getServers().size(), serverManager.numServers());
114
+        assertEquals(serverManager.getConnections().size(), serverManager.getConnectionCount());
115 115
     }
116 116
 
117 117
     @Test
@@ -128,14 +128,14 @@ public class ServerManagerTest {
128 128
         serverManager.registerServer(serverB);
129 129
         serverManager.registerServer(serverC);
130 130
 
131
-        assertEquals(1, serverManager.getServersByNetwork("Net1").size());
132
-        assertEquals(serverA, serverManager.getServersByNetwork("Net1").get(0));
131
+        assertEquals(1, serverManager.getConnectionsByNetwork("Net1").size());
132
+        assertEquals(serverA, serverManager.getConnectionsByNetwork("Net1").get(0));
133 133
 
134
-        assertEquals(2, serverManager.getServersByNetwork("Net2").size());
135
-        assertEquals(serverB, serverManager.getServersByNetwork("Net2").get(0));
136
-        assertEquals(serverC, serverManager.getServersByNetwork("Net2").get(1));
134
+        assertEquals(2, serverManager.getConnectionsByNetwork("Net2").size());
135
+        assertEquals(serverB, serverManager.getConnectionsByNetwork("Net2").get(0));
136
+        assertEquals(serverC, serverManager.getConnectionsByNetwork("Net2").get(1));
137 137
 
138
-        assertEquals(0, serverManager.getServersByNetwork("Net3").size());
138
+        assertEquals(0, serverManager.getConnectionsByNetwork("Net3").size());
139 139
     }
140 140
 
141 141
     @Test
@@ -196,7 +196,7 @@ public class ServerManagerTest {
196 196
 
197 197
         serverManager.joinDevChat();
198 198
 
199
-        assertEquals(3, serverManager.numServers());
199
+        assertEquals(3, serverManager.getConnectionCount());
200 200
 
201 201
         URI serverUri = uriCaptor.getValue();
202 202
         assertEquals("irc", serverUri.getScheme());

+ 3
- 2
test/com/dmdirc/WritableFrameContainerTest.java Vedi File

@@ -25,6 +25,7 @@ package com.dmdirc;
25 25
 import com.dmdirc.commandparser.CommandManager;
26 26
 import com.dmdirc.config.ConfigBinder;
27 27
 import com.dmdirc.harness.TestWritableFrameContainer;
28
+import com.dmdirc.interfaces.ConnectionManager;
28 29
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
29 30
 import com.dmdirc.messages.MessageSinkManager;
30 31
 import com.dmdirc.util.URLBuilder;
@@ -43,7 +44,7 @@ import static org.mockito.Mockito.when;
43 44
 public class WritableFrameContainerTest {
44 45
 
45 46
     @Mock private AggregateConfigProvider acp;
46
-    @Mock private ServerManager serverManager;
47
+    @Mock private ConnectionManager connectionManager;
47 48
     @Mock private MessageSinkManager messageSinkManager;
48 49
     @Mock private URLBuilder urlBuilder;
49 50
     @Mock private DMDircMBassador eventBus;
@@ -56,7 +57,7 @@ public class WritableFrameContainerTest {
56 57
         when(acp.getOption("general", "commandchar")).thenReturn("/");
57 58
         final ConfigBinder binder = new ConfigBinder(acp);
58 59
         when(acp.getBinder()).thenReturn(binder);
59
-        commands = new CommandManager(serverManager);
60
+        commands = new CommandManager(connectionManager);
60 61
         commands.initialise(acp);
61 62
     }
62 63
 

+ 2
- 2
test/com/dmdirc/commandparser/commands/global/NewServerTest.java Vedi File

@@ -26,7 +26,7 @@ import com.dmdirc.Server;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.commands.context.CommandContext;
28 28
 import com.dmdirc.interfaces.CommandController;
29
-import com.dmdirc.interfaces.ServerFactory;
29
+import com.dmdirc.interfaces.ConnectionFactory;
30 30
 import com.dmdirc.interfaces.config.ConfigProvider;
31 31
 import com.dmdirc.interfaces.config.IdentityController;
32 32
 import com.dmdirc.plugins.PluginManager;
@@ -57,7 +57,7 @@ public class NewServerTest {
57 57
     @Mock private ConfigProvider identity;
58 58
     @Mock private FrameContainer container;
59 59
     @Mock private PluginManager pluginManager;
60
-    @Mock private ServerFactory factory;
60
+    @Mock private ConnectionFactory factory;
61 61
     @Mock private Server server;
62 62
     private NewServer command;
63 63
 

+ 22
- 12
test/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModelTest.java Vedi File

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.ui.core.feedback;
24 24
 
25
-import com.dmdirc.ServerManager;
25
+import com.dmdirc.interfaces.ConnectionManager;
26 26
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 27
 import com.dmdirc.interfaces.ui.FeedbackDialogModelListener;
28 28
 
@@ -40,7 +40,7 @@ import static org.mockito.Mockito.verify;
40 40
 public class CoreFeedbackDialogModelTest {
41 41
 
42 42
     @Mock private AggregateConfigProvider config;
43
-    @Mock private ServerManager serverManager;
43
+    @Mock private ConnectionManager connectionManager;
44 44
     @Mock private FeedbackSenderFactory feedbackSenderFactory;
45 45
     @Mock private FeedbackDialogModelListener listener;
46 46
     private final String name = "Bob Dole";
@@ -49,7 +49,8 @@ public class CoreFeedbackDialogModelTest {
49 49
 
50 50
     @Test
51 51
     public void testName() {
52
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
52
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
53
+                connectionManager,
53 54
                 feedbackSenderFactory, "configDirectory");
54 55
         assertEquals("testName", Optional.absent(), instance.getName());
55 56
         instance.setName(Optional.fromNullable(name));
@@ -58,7 +59,8 @@ public class CoreFeedbackDialogModelTest {
58 59
 
59 60
     @Test
60 61
     public void testEmail() {
61
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
62
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
63
+                connectionManager,
62 64
                 feedbackSenderFactory, "configDirectory");
63 65
         assertEquals("testEmail", Optional.absent(), instance.getEmail());
64 66
         instance.setEmail(Optional.fromNullable(email));
@@ -67,7 +69,8 @@ public class CoreFeedbackDialogModelTest {
67 69
 
68 70
     @Test
69 71
     public void testFeedback() {
70
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
72
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
73
+                connectionManager,
71 74
                 feedbackSenderFactory, "configDirectory");
72 75
         assertEquals("testFeedback", Optional.absent(), instance.getFeedback());
73 76
         instance.setFeedback(Optional.fromNullable(feedback));
@@ -76,7 +79,8 @@ public class CoreFeedbackDialogModelTest {
76 79
 
77 80
     @Test
78 81
     public void testServerInfo() {
79
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
82
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
83
+                connectionManager,
80 84
                 feedbackSenderFactory, "configDirectory");
81 85
         assertEquals("testServerInfo", false, instance.getIncludeServerInfo());
82 86
         instance.setIncludeServerInfo(true);
@@ -85,7 +89,8 @@ public class CoreFeedbackDialogModelTest {
85 89
 
86 90
     @Test
87 91
     public void testDMDircInfo() {
88
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
92
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
93
+                connectionManager,
89 94
                 feedbackSenderFactory, "configDirectory");
90 95
         assertEquals("testDMDircInfo", false, instance.getIncludeDMDircInfo());
91 96
         instance.setIncludeDMDircInfo(true);
@@ -99,7 +104,8 @@ public class CoreFeedbackDialogModelTest {
99 104
 
100 105
     @Test
101 106
     public void testNameListener() {
102
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
107
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
108
+                connectionManager,
103 109
                 feedbackSenderFactory, "configDirectory");
104 110
         instance.addListener(listener);
105 111
         instance.setName(Optional.fromNullable("Bob Dole"));
@@ -108,7 +114,8 @@ public class CoreFeedbackDialogModelTest {
108 114
 
109 115
     @Test
110 116
     public void testEmailListener() {
111
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
117
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
118
+                connectionManager,
112 119
                 feedbackSenderFactory, "configDirectory");
113 120
         instance.addListener(listener);
114 121
         instance.setEmail(Optional.fromNullable("bob@dole.com"));
@@ -117,7 +124,8 @@ public class CoreFeedbackDialogModelTest {
117 124
 
118 125
     @Test
119 126
     public void testFeedbackListener() {
120
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
127
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
128
+                connectionManager,
121 129
                 feedbackSenderFactory, "configDirectory");
122 130
         instance.addListener(listener);
123 131
         instance.setFeedback(Optional.fromNullable("DMDirc Rocks."));
@@ -126,7 +134,8 @@ public class CoreFeedbackDialogModelTest {
126 134
 
127 135
     @Test
128 136
     public void testServerInfoListener() {
129
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
137
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
138
+                connectionManager,
130 139
                 feedbackSenderFactory, "configDirectory");
131 140
         instance.addListener(listener);
132 141
         instance.setIncludeServerInfo(true);
@@ -135,7 +144,8 @@ public class CoreFeedbackDialogModelTest {
135 144
 
136 145
     @Test
137 146
     public void testDMDircInfoListener() {
138
-        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config, serverManager,
147
+        final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
148
+                connectionManager,
139 149
                 feedbackSenderFactory, "configDirectory");
140 150
         instance.addListener(listener);
141 151
         instance.setIncludeDMDircInfo(true);

+ 41
- 41
test/com/dmdirc/ui/core/newserver/CoreNewServerDialogModelTest.java Vedi File

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.ui.core.newserver;
24 24
 
25
-import com.dmdirc.ServerManager;
25
+import com.dmdirc.interfaces.ConnectionManager;
26 26
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 27
 import com.dmdirc.interfaces.config.ConfigProvider;
28 28
 import com.dmdirc.interfaces.config.IdentityController;
@@ -54,7 +54,7 @@ public class CoreNewServerDialogModelTest {
54 54
     @Mock private AggregateConfigProvider globalConfig;
55 55
     @Mock private ConfigProvider userConfig;
56 56
     @Mock private IdentityController controller;
57
-    @Mock private ServerManager serverManager;
57
+    @Mock private ConnectionManager connectionManager;
58 58
     @Mock private ConfigProvider profile1;
59 59
     @Mock private ConfigProvider profile2;
60 60
     @Mock private NewServerDialogModelListener listener;
@@ -72,7 +72,7 @@ public class CoreNewServerDialogModelTest {
72 72
     @Test
73 73
     public void testGetProfiles() {
74 74
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
75
-                controller, serverManager);
75
+                controller, connectionManager);
76 76
         instance.loadModel();
77 77
         assertEquals("loadModel: ", Lists.newArrayList(profile1, profile2), instance.
78 78
                 getProfileList());
@@ -81,7 +81,7 @@ public class CoreNewServerDialogModelTest {
81 81
     @Test
82 82
     public void testSelectedProfile() {
83 83
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
84
-                controller, serverManager);
84
+                controller, connectionManager);
85 85
         instance.loadModel();
86 86
         assertEquals("testSelectedProfile: ", Optional.absent(), instance.getSelectedProfile());
87 87
         instance.setSelectedProfile(Optional.fromNullable(profile1));
@@ -94,7 +94,7 @@ public class CoreNewServerDialogModelTest {
94 94
         when(controller.getProvidersByType("profile")).thenReturn(
95 95
                 Lists.<ConfigProvider>newArrayList());
96 96
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
97
-                controller, serverManager);
97
+                controller, connectionManager);
98 98
         instance.loadModel();
99 99
         assertFalse("testProfileValidatorEmpty: ", instance.isProfileListValid());
100 100
     }
@@ -104,7 +104,7 @@ public class CoreNewServerDialogModelTest {
104 104
         when(controller.getProvidersByType("profile")).thenReturn(
105 105
                 Lists.newArrayList(profile1, profile2));
106 106
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
107
-                controller, serverManager);
107
+                controller, connectionManager);
108 108
         instance.loadModel();
109 109
         assertTrue("testProfileValidatorNotEmpty: ", instance.isProfileListValid());
110 110
     }
@@ -112,7 +112,7 @@ public class CoreNewServerDialogModelTest {
112 112
     @Test
113 113
     public void testHostname() {
114 114
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
115
-                controller, serverManager);
115
+                controller, connectionManager);
116 116
         instance.loadModel();
117 117
         assertEquals("testHostname: ", Optional.fromNullable("hostname"), instance.getHostname());
118 118
         instance.setHostname(Optional.fromNullable("test"));
@@ -123,7 +123,7 @@ public class CoreNewServerDialogModelTest {
123 123
     public void testHostnameValidatorValid() {
124 124
         when(globalConfig.getOption("newserver", "hostname")).thenReturn("hostname");
125 125
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
126
-                controller, serverManager);
126
+                controller, connectionManager);
127 127
         instance.loadModel();
128 128
         assertTrue("testHostnameValidatorValid: ", instance.isHostnameValid());
129 129
     }
@@ -132,7 +132,7 @@ public class CoreNewServerDialogModelTest {
132 132
     public void testHostnameValidatorInvalid() {
133 133
         when(globalConfig.getOption("newserver", "hostname")).thenReturn("~!£$^£$%^&");
134 134
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
135
-                controller, serverManager);
135
+                controller, connectionManager);
136 136
         instance.loadModel();
137 137
         assertFalse("testHostnameValidatorInvalid: ", instance.isHostnameValid());
138 138
     }
@@ -140,7 +140,7 @@ public class CoreNewServerDialogModelTest {
140 140
     @Test
141 141
     public void testPort() {
142 142
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
143
-                controller, serverManager);
143
+                controller, connectionManager);
144 144
         instance.loadModel();
145 145
         assertEquals("testPort: ", Optional.fromNullable(1111), instance.getPort());
146 146
         instance.setPort(Optional.fromNullable(5678));
@@ -151,7 +151,7 @@ public class CoreNewServerDialogModelTest {
151 151
     public void testPortValidatorValid() {
152 152
         when(globalConfig.getOptionInt("newserver", "port")).thenReturn(1111);
153 153
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
154
-                controller, serverManager);
154
+                controller, connectionManager);
155 155
         instance.loadModel();
156 156
         assertTrue("testPortValidatorValid: ", instance.isPortValid());
157 157
     }
@@ -160,7 +160,7 @@ public class CoreNewServerDialogModelTest {
160 160
     public void testPortValidatorTooLow() {
161 161
         when(globalConfig.getOptionInt("newserver", "port")).thenReturn(-1);
162 162
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
163
-                controller, serverManager);
163
+                controller, connectionManager);
164 164
         instance.loadModel();
165 165
         assertFalse("testPortValidatorTooLow: ", instance.isPortValid());
166 166
     }
@@ -169,7 +169,7 @@ public class CoreNewServerDialogModelTest {
169 169
     public void testPortValidatorTooHigh() {
170 170
         when(globalConfig.getOptionInt("newserver", "port")).thenReturn(65536);
171 171
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
172
-                controller, serverManager);
172
+                controller, connectionManager);
173 173
         instance.loadModel();
174 174
         assertFalse("testPortValidatorTooHigh: ", instance.isPortValid());
175 175
     }
@@ -177,7 +177,7 @@ public class CoreNewServerDialogModelTest {
177 177
     @Test
178 178
     public void testPassword() {
179 179
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
180
-                controller, serverManager);
180
+                controller, connectionManager);
181 181
         instance.loadModel();
182 182
         assertEquals("testPassword: ", Optional.fromNullable("password"), instance.getPassword());
183 183
         instance.setPassword(Optional.fromNullable("test"));
@@ -188,7 +188,7 @@ public class CoreNewServerDialogModelTest {
188 188
     public void testPasswordValidatorValid() {
189 189
         when(globalConfig.getOption("newserver", "password")).thenReturn("password");
190 190
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
191
-                controller, serverManager);
191
+                controller, connectionManager);
192 192
         instance.loadModel();
193 193
         assertTrue("testPasswordValidatorValid: ", instance.isPortValid());
194 194
     }
@@ -196,7 +196,7 @@ public class CoreNewServerDialogModelTest {
196 196
     @Test
197 197
     public void testSSL() {
198 198
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
199
-                controller, serverManager);
199
+                controller, connectionManager);
200 200
         instance.loadModel();
201 201
         assertTrue("testSSL: ", instance.getSSL());
202 202
         instance.setSSL(false);
@@ -206,7 +206,7 @@ public class CoreNewServerDialogModelTest {
206 206
     @Test
207 207
     public void testSaveAsDefault() {
208 208
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
209
-                controller, serverManager);
209
+                controller, connectionManager);
210 210
         instance.loadModel();
211 211
         assertFalse("testSaveAsDefault:", instance.getSaveAsDefault());
212 212
         instance.setSaveAsDefault(true);
@@ -217,7 +217,7 @@ public class CoreNewServerDialogModelTest {
217 217
     public void testIsSaveAllowedValid() {
218 218
         when(globalConfig.getOption("newserver", "hostname")).thenReturn("hostname");
219 219
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
220
-                controller, serverManager);
220
+                controller, connectionManager);
221 221
         instance.loadModel();
222 222
         assertTrue("testIsSaveAllowedValid: ", instance.isSaveAllowed());
223 223
     }
@@ -226,7 +226,7 @@ public class CoreNewServerDialogModelTest {
226 226
     public void testIsSaveAllowedInvalidHostname() {
227 227
         when(globalConfig.getOption("newserver", "hostname")).thenReturn("~!£$^£$%^&");
228 228
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
229
-                controller, serverManager);
229
+                controller, connectionManager);
230 230
         instance.loadModel();
231 231
         assertFalse("testIsSaveAllowedInvalidHostname: ", instance.isSaveAllowed());
232 232
     }
@@ -235,7 +235,7 @@ public class CoreNewServerDialogModelTest {
235 235
     public void testIsSaveAllowedInvalidPort() {
236 236
         when(globalConfig.getOption("newserver", "hostname")).thenReturn("-1");
237 237
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
238
-                controller, serverManager);
238
+                controller, connectionManager);
239 239
         instance.loadModel();
240 240
         assertFalse("testIsSaveAllowedInvalidPort: ", instance.isSaveAllowed());
241 241
     }
@@ -243,7 +243,7 @@ public class CoreNewServerDialogModelTest {
243 243
     @Test
244 244
     public void testSaveSaveDefaults() {
245 245
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
246
-                controller, serverManager);
246
+                controller, connectionManager);
247 247
         instance.loadModel();
248 248
         instance.setSaveAsDefault(true);
249 249
         instance.save();
@@ -256,7 +256,7 @@ public class CoreNewServerDialogModelTest {
256 256
     @Test
257 257
     public void testSaveNotDefaults() {
258 258
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
259
-                controller, serverManager);
259
+                controller, connectionManager);
260 260
         instance.loadModel();
261 261
         instance.setSaveAsDefault(false);
262 262
         instance.save();
@@ -269,29 +269,29 @@ public class CoreNewServerDialogModelTest {
269 269
     @Test
270 270
     public void testSaveConnectWithoutProfile() throws URISyntaxException {
271 271
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
272
-                controller, serverManager);
272
+                controller, connectionManager);
273 273
         instance.loadModel();
274 274
         instance.save();
275
-        verify(serverManager).connectToAddress(new URI("ircs://password@hostname:1111"));
276
-        verify(serverManager, never()).connectToAddress(any(URI.class), any(ConfigProvider.class));
275
+        verify(connectionManager).connectToAddress(new URI("ircs://password@hostname:1111"));
276
+        verify(connectionManager, never()).connectToAddress(any(URI.class), any(ConfigProvider.class));
277 277
     }
278 278
 
279 279
     @Test
280 280
     public void testSaveConnectWithProfile() throws URISyntaxException {
281 281
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
282
-                controller, serverManager);
282
+                controller, connectionManager);
283 283
         instance.loadModel();
284 284
         instance.setSelectedProfile(Optional.fromNullable(profile1));
285 285
         instance.save();
286
-        verify(serverManager, never()).connectToAddress(any(URI.class));
287
-        verify(serverManager).connectToAddress(new URI("ircs://password@hostname:1111"), profile1);
286
+        verify(connectionManager, never()).connectToAddress(any(URI.class));
287
+        verify(connectionManager).connectToAddress(new URI("ircs://password@hostname:1111"), profile1);
288 288
     }
289 289
 
290 290
     @Test
291 291
     public void testAddConfigProvider() {
292 292
         when(controller.getProvidersByType("profile")).thenReturn(Lists.newArrayList(profile1));
293 293
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
294
-                controller, serverManager);
294
+                controller, connectionManager);
295 295
         instance.loadModel();
296 296
         assertEquals("testAddConfigProvider:", Lists.newArrayList(profile1),
297 297
                 instance.getProfileList());
@@ -305,7 +305,7 @@ public class CoreNewServerDialogModelTest {
305 305
         when(controller.getProvidersByType("profile")).thenReturn(
306 306
                 Lists.newArrayList(profile1, profile2));
307 307
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
308
-                controller, serverManager);
308
+                controller, connectionManager);
309 309
         instance.loadModel();
310 310
         assertEquals("testRemoveConfigProvider:", Lists.newArrayList(profile1, profile2),
311 311
                 instance.getProfileList());
@@ -319,7 +319,7 @@ public class CoreNewServerDialogModelTest {
319 319
         when(controller.getProvidersByType("profile")).thenReturn(
320 320
                 Lists.newArrayList(profile1, profile2));
321 321
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
322
-                controller, serverManager);
322
+                controller, connectionManager);
323 323
         instance.loadModel();
324 324
         instance.setSelectedProfile(Optional.fromNullable(profile2));
325 325
         assertEquals("testRemoveConfigProviderSelectedProfile:",
@@ -337,7 +337,7 @@ public class CoreNewServerDialogModelTest {
337 337
     @Test
338 338
     public void testListenerSelectedProfileChanged() {
339 339
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
340
-                controller, serverManager);
340
+                controller, connectionManager);
341 341
         instance.loadModel();
342 342
         assertEquals("testListenerSelectedProfileChanged: ", Optional.<ConfigProvider>absent(),
343 343
                 instance.getSelectedProfile());
@@ -352,7 +352,7 @@ public class CoreNewServerDialogModelTest {
352 352
     @Test
353 353
     public void testListenerProfileListChangedRemoved() {
354 354
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
355
-                controller, serverManager);
355
+                controller, connectionManager);
356 356
         instance.loadModel();
357 357
         instance.addListener(listener);
358 358
         assertEquals("testListenerProfileListChangedRemoved: ",
@@ -368,7 +368,7 @@ public class CoreNewServerDialogModelTest {
368 368
         when(controller.getProvidersByType("profile"))
369 369
                 .thenReturn(Lists.newArrayList(profile1));
370 370
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
371
-                controller, serverManager);
371
+                controller, connectionManager);
372 372
         instance.loadModel();
373 373
         instance.addListener(listener);
374 374
         assertEquals("testListenerProfileListChangedAdded: ", Lists.newArrayList(profile1),
@@ -382,7 +382,7 @@ public class CoreNewServerDialogModelTest {
382 382
     @Test
383 383
     public void testListenerServerDetailsChangedPort() {
384 384
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
385
-                controller, serverManager);
385
+                controller, connectionManager);
386 386
         instance.loadModel();
387 387
         instance.addListener(listener);
388 388
         instance.setPort(Optional.fromNullable(9999));
@@ -393,7 +393,7 @@ public class CoreNewServerDialogModelTest {
393 393
     @Test
394 394
     public void testListenerServerDetailsChangedPassword() {
395 395
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
396
-                controller, serverManager);
396
+                controller, connectionManager);
397 397
         instance.loadModel();
398 398
         instance.addListener(listener);
399 399
         instance.setPassword(Optional.fromNullable("password-test"));
@@ -404,7 +404,7 @@ public class CoreNewServerDialogModelTest {
404 404
     @Test
405 405
     public void testListenerServerDetailsChangedSSL() {
406 406
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
407
-                controller, serverManager);
407
+                controller, connectionManager);
408 408
         instance.loadModel();
409 409
         instance.addListener(listener);
410 410
         instance.setSSL(false);
@@ -415,7 +415,7 @@ public class CoreNewServerDialogModelTest {
415 415
     @Test
416 416
     public void testListenerServerDetailsChangedSaveAsDefault() {
417 417
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
418
-                controller, serverManager);
418
+                controller, connectionManager);
419 419
         instance.loadModel();
420 420
         instance.addListener(listener);
421 421
         instance.setSaveAsDefault(true);
@@ -426,7 +426,7 @@ public class CoreNewServerDialogModelTest {
426 426
     @Test
427 427
     public void testRemoveListener() {
428 428
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
429
-                controller, serverManager);
429
+                controller, connectionManager);
430 430
         instance.loadModel();
431 431
         instance.addListener(listener);
432 432
         instance.setSaveAsDefault(true);
@@ -441,7 +441,7 @@ public class CoreNewServerDialogModelTest {
441 441
     @Test
442 442
     public void testSaveDefaults() throws URISyntaxException {
443 443
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
444
-                controller, serverManager);
444
+                controller, connectionManager);
445 445
         instance.loadModel();
446 446
         instance.setSelectedProfile(Optional.fromNullable(profile1));
447 447
         instance.setSaveAsDefault(true);
@@ -455,7 +455,7 @@ public class CoreNewServerDialogModelTest {
455 455
     @Test
456 456
     public void testNoSaveDefaults() throws URISyntaxException {
457 457
         CoreNewServerDialogModel instance = new CoreNewServerDialogModel(globalConfig, userConfig,
458
-                controller, serverManager);
458
+                controller, connectionManager);
459 459
         instance.loadModel();
460 460
         instance.setSelectedProfile(Optional.fromNullable(profile1));
461 461
         instance.setSaveAsDefault(false);

Loading…
Annulla
Salva