-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMasterServer.java
More file actions
67 lines (58 loc) · 2.06 KB
/
MasterServer.java
File metadata and controls
67 lines (58 loc) · 2.06 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.ExportException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Scanner;
public class MasterServer{
public MasterServer() {}
public static void main(String args[]) {
Registry registry = null;
Scanner sc = new Scanner(System.in);
try {
registry = LocateRegistry.createRegistry(1099);
} catch(ExportException ee) {
try{
registry = LocateRegistry.getRegistry(1099);
} catch(Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
System.err.println("Port already in use, Attempting to use the open registry");
} catch(Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
try {
// Getting the registry
MasterServerImpl obj = new MasterServerImpl();
UtilsServer stub = (UtilsServer) UnicastRemoteObject.exportObject(obj, 0);
registry.rebind("Dream11-master", stub);
System.err.println("Master Server ready");
String command="", name="";
while(sc.hasNextLine()) {
command = sc.next();
switch(command) {
case "exit":
case "quit":
case "q":
stub.Query("exit 0");
System.exit(0);
break;
case "add_node":
name = sc.next();
stub.AddNode(name);
break;
case "delete_node":
name = sc.next();
stub.DeleteNode(name);
break;
default:
System.err.println(command);
}
}
} catch (Exception e) {
System.err.println("Master Server exception: " + e.toString());
e.printStackTrace();
}
}
}