|
@@ -27,7 +27,7 @@ import com.dmdirc.commandparser.CommandManager;
|
27
|
27
|
import com.dmdirc.commandparser.parsers.ServerCommandParser;
|
28
|
28
|
import com.dmdirc.config.ConfigManager;
|
29
|
29
|
import com.dmdirc.config.Identity;
|
30
|
|
-import com.dmdirc.config.IdentityManager;
|
|
30
|
+import com.dmdirc.interfaces.IdentityController;
|
31
|
31
|
import com.dmdirc.interfaces.ServerFactory;
|
32
|
32
|
import com.dmdirc.logger.ErrorLevel;
|
33
|
33
|
import com.dmdirc.logger.Logger;
|
|
@@ -41,6 +41,8 @@ import java.util.List;
|
41
|
41
|
import java.util.Set;
|
42
|
42
|
import java.util.concurrent.CopyOnWriteArraySet;
|
43
|
43
|
|
|
44
|
+import javax.inject.Provider;
|
|
45
|
+
|
44
|
46
|
/**
|
45
|
47
|
* The ServerManager maintains a list of all servers, and provides methods to
|
46
|
48
|
* search or iterate over them.
|
|
@@ -48,12 +50,25 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
48
|
50
|
public class ServerManager implements ServerFactory {
|
49
|
51
|
|
50
|
52
|
/** All servers that currently exist. */
|
51
|
|
- private final Set<Server> servers = new CopyOnWriteArraySet<Server>();
|
|
53
|
+ private final Set<Server> servers = new CopyOnWriteArraySet<>();
|
|
54
|
+
|
|
55
|
+ /** Provider of {@link ParserFactory}s for servers. */
|
|
56
|
+ private final Provider<ParserFactory> parserFactoryProvider;
|
|
57
|
+
|
|
58
|
+ /** The identity controller to use to find profiles. */
|
|
59
|
+ private final IdentityController identityController;
|
52
|
60
|
|
53
|
61
|
/**
|
54
|
62
|
* Creates a new instance of ServerManager.
|
|
63
|
+ *
|
|
64
|
+ * @param parserFactoryProvider The provider of {@link ParserFactory}s to give to servers.
|
|
65
|
+ * @param identityController The identity controller to use to find profiles.
|
55
|
66
|
*/
|
56
|
|
- public ServerManager() {
|
|
67
|
+ public ServerManager(
|
|
68
|
+ final Provider<ParserFactory> parserFactoryProvider,
|
|
69
|
+ final IdentityController identityController) {
|
|
70
|
+ this.parserFactoryProvider = parserFactoryProvider;
|
|
71
|
+ this.identityController = identityController;
|
57
|
72
|
}
|
58
|
73
|
|
59
|
74
|
/** {@inheritDoc} */
|
|
@@ -65,7 +80,7 @@ public class ServerManager implements ServerFactory {
|
65
|
80
|
this,
|
66
|
81
|
configManager,
|
67
|
82
|
new ServerCommandParser(configManager),
|
68
|
|
- new ParserFactory(Main.mainInstance.getPluginManager()),
|
|
83
|
+ parserFactoryProvider.get(),
|
69
|
84
|
WindowManager.getWindowManager(),
|
70
|
85
|
AliasWrapper.getAliasWrapper(),
|
71
|
86
|
CommandManager.getCommandManager(),
|
|
@@ -98,7 +113,7 @@ public class ServerManager implements ServerFactory {
|
98
|
113
|
* @return A list of all servers
|
99
|
114
|
*/
|
100
|
115
|
public List<Server> getServers() {
|
101
|
|
- return new ArrayList<Server>(servers);
|
|
116
|
+ return new ArrayList<>(servers);
|
102
|
117
|
}
|
103
|
118
|
|
104
|
119
|
/**
|
|
@@ -150,7 +165,7 @@ public class ServerManager implements ServerFactory {
|
150
|
165
|
* @return A list of servers connected to the network
|
151
|
166
|
*/
|
152
|
167
|
public List<Server> getServersByNetwork(final String network) {
|
153
|
|
- final List<Server> res = new ArrayList<Server>();
|
|
168
|
+ final List<Server> res = new ArrayList<>();
|
154
|
169
|
|
155
|
170
|
for (Server server : servers) {
|
156
|
171
|
if (server.isNetwork(network)) {
|
|
@@ -168,7 +183,7 @@ public class ServerManager implements ServerFactory {
|
168
|
183
|
* @return A list of servers connected to the network
|
169
|
184
|
*/
|
170
|
185
|
public List<Server> getServersByAddress(final String address) {
|
171
|
|
- final List<Server> res = new ArrayList<Server>();
|
|
186
|
+ final List<Server> res = new ArrayList<>();
|
172
|
187
|
|
173
|
188
|
for (Server server : servers) {
|
174
|
189
|
if (server.getAddress().equalsIgnoreCase(address)) {
|
|
@@ -188,8 +203,8 @@ public class ServerManager implements ServerFactory {
|
188
|
203
|
* @since 0.6.3
|
189
|
204
|
*/
|
190
|
205
|
public Server connectToAddress(final URI uri) {
|
191
|
|
- return connectToAddress(uri, IdentityManager.getIdentityManager()
|
192
|
|
- .getIdentitiesByType("profile").get(0));
|
|
206
|
+ return connectToAddress(uri,
|
|
207
|
+ identityController.getIdentitiesByType("profile").get(0));
|
193
|
208
|
}
|
194
|
209
|
|
195
|
210
|
/**
|
|
@@ -249,8 +264,7 @@ public class ServerManager implements ServerFactory {
|
249
|
264
|
|
250
|
265
|
if (connectedServer == null) {
|
251
|
266
|
try {
|
252
|
|
- connectToAddress(new URI("irc://irc.quakenet.org/DMDirc"),
|
253
|
|
- IdentityManager.getIdentityManager().getIdentitiesByType("profile").get(0));
|
|
267
|
+ connectToAddress(new URI("irc://irc.quakenet.org/DMDirc"));
|
254
|
268
|
} catch (URISyntaxException ex) {
|
255
|
269
|
Logger.appError(ErrorLevel.MEDIUM, "Unable to construct new server", ex);
|
256
|
270
|
}
|