-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWebServer.java
More file actions
48 lines (36 loc) · 1.12 KB
/
WebServer.java
File metadata and controls
48 lines (36 loc) · 1.12 KB
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
import java.io.IOException;
import org.apache.log4j.Logger;
import com.google.gson.Gson;
public class WebServer {
private static Logger log = Logger.getLogger(WebServer.class);
public static Gson g = new Gson();
public static int delayModifier = 2;
public static void main(String[] args) {
int MyID = Integer.parseInt(args[0]);
String MyIP = args[1];
int MyPort = Integer.parseInt(args[2]);
ServerStateManager.init(MyID, MyIP, MyPort);
log.info(ServerStateManager.getSnapshot());
String DataServerAddress = null;
int DataServerPort = 0;
if (MyID != 0) {
DataServerAddress = args[3];
DataServerPort = Integer.parseInt(args[4]);
ServerStateManager.updateSnapshot(DataServerAddress, DataServerPort);
}
if (MyID > -1) {
if (MyID != 0) {
ServerStateManager.initReplication(DataServerAddress, DataServerPort);
}
new GossipThread().start();
}
log.info("Starting server type: " + ((MyID > -1) ? "backend" : "frontend") + " port: " + MyPort);
Thread t = null;
try {
t = new HttpRequestListener(MyPort);
} catch (IOException e) {
}
t.setDaemon(false);
t.start();
}
}