-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerState.java
executable file
·52 lines (40 loc) · 1.02 KB
/
ServerState.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package myServer2;
/*
* AUTHOR : Min Gao
* Project1-Multi-Server Chat System
*/
import java.util.ArrayList;
public class ServerState {
private static ServerState instance;
private Conf thisServer;
private ArrayList<Conf> activeServers;
private ServerState() {
activeServers = new ArrayList<>();
}
public static synchronized ServerState getInstance() {
if(instance == null) {
instance = new ServerState();
}
return instance;
}
public synchronized void serverConnected(Conf server) {
activeServers.add(server);
}
public ArrayList<Conf> getServerList() {
return activeServers;
}
public synchronized Conf getRemoteServerConf(String serverid) {
for (Conf serverConf : activeServers) {
if (serverConf.getServerid().equals(serverid)) {
return serverConf;
}
}
return null;
}
public synchronized void setThisServer(Conf serverConf) {
this.thisServer = serverConf;
}
public synchronized Conf getThisServer() {
return thisServer;
}
}