root / src / TestApp.java @ 2
History | View | Annotate | Download (2.25 KB)
1 |
|
---|---|
2 |
import RMI.Service; |
3 |
|
4 |
import java.io.IOException; |
5 |
import java.rmi.NotBoundException; |
6 |
import java.rmi.RemoteException; |
7 |
import java.rmi.registry.LocateRegistry; |
8 |
import java.rmi.registry.Registry; |
9 |
|
10 |
public class TestApp { |
11 |
|
12 |
private static String peer; |
13 |
private static String protocol; |
14 |
private static String filePath; |
15 |
private static String host; |
16 |
private static int space; |
17 |
private static int replication; |
18 |
|
19 |
|
20 |
public static void main(String args[]) { |
21 |
|
22 |
if (argumentsValid(args)) {
|
23 |
System.out.println(" Must use this format: java TestApp <host> <peer_ap> <sub_protocol> <opnd_1> <opnd_2>"); |
24 |
System.out.println("Terminating"); |
25 |
return;
|
26 |
} |
27 |
|
28 |
TestApp app = new TestApp();
|
29 |
|
30 |
app.peer = args[1];
|
31 |
app.protocol = args[2];
|
32 |
app.host = args[0];
|
33 |
|
34 |
try {
|
35 |
|
36 |
Registry registry = LocateRegistry.getRegistry(host); |
37 |
Service stub = null;
|
38 |
try {
|
39 |
stub = (Service) registry.lookup(peer); |
40 |
} catch (NotBoundException e) { |
41 |
e.printStackTrace(); |
42 |
} |
43 |
|
44 |
|
45 |
switch (protocol) {
|
46 |
|
47 |
case "BACKUP": |
48 |
System.out.println("Backing up"); |
49 |
app.filePath = args[3];
|
50 |
app.replication = Integer.parseInt(args[4]); |
51 |
stub.backup(filePath, replication); |
52 |
break;
|
53 |
case "RESTORE": |
54 |
app.filePath = args[3];
|
55 |
stub.restore(filePath); |
56 |
break;
|
57 |
case "DELETE": |
58 |
app.filePath = args[3];
|
59 |
stub.delete(filePath); |
60 |
break;
|
61 |
case "RECLAIM": |
62 |
app.space = Integer.parseInt(args[3]); |
63 |
stub.manage(space); |
64 |
break;
|
65 |
case "STATE": |
66 |
stub.state(); |
67 |
break;
|
68 |
} |
69 |
} catch (RemoteException e) { |
70 |
e.printStackTrace(); |
71 |
} catch (IOException e) { |
72 |
e.printStackTrace(); |
73 |
} |
74 |
|
75 |
} |
76 |
|
77 |
private static boolean argumentsValid(String args[]) { |
78 |
|
79 |
if (args.length < 2 || args.length > 5) |
80 |
return true; |
81 |
return false; |
82 |
} |
83 |
} |
84 |
|