-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
65 lines (55 loc) · 1.62 KB
/
Main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.io.FileInputStream;
import java.rmi.RemoteException;
import java.util.Scanner;
import java.util.Vector;
public class Main
{
/**
* Init using "java -Djava.security.policy=server.policy Main port configfile.txt serverId cacheSize"
* where configfile.txt is a newline separated list of RMI
* paths, serverId is an integer that denotes the current
* instance (by referring to a line in configfile.txt) and
* cacheSize is the size of the local cache.
*
* If anything fails, a basic cache is used that doesn't use
* RMI.
*/
public Main(String[] args)
{
ICache cache;
try {
if (args.length < 4) throw new Exception("Usage: java -Djava.security.policy=server.policy Main port configfile.txt serverId cacheSize");
Scanner scanner = new Scanner(new FileInputStream(args[1]));
Vector<String> serverNames = new Vector<String>();
while (scanner.hasNextLine()) {
serverNames.add(scanner.nextLine());
}
cache = new RemoteCache(serverNames, Integer.parseInt(args[2]), new BasicCache(Integer.parseInt(args[3])));
} catch (Exception e) {
e.printStackTrace();
System.err.println("Using basic cache...");
try {
cache = new BasicCache();
} catch (RemoteException e1) {
cache = null;
e1.printStackTrace();
}
}
int port;
if (args.length > 0)
port = Integer.parseInt(args[0]);
else
port = 8081;
System.err.println("Using port " + port + "...");
try {
HTTPServer server = new HTTPServer(port, cache);
server.Accept();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args)
{
new Main(args);
}
}