Project

General

Profile

Statistics
| Revision:

root / src / TestApp.java

History | View | Annotate | Download (2.39 KB)

1
import java.rmi.registry.LocateRegistry;
2
import java.rmi.registry.Registry;
3

    
4
public class TestApp {
5
        public int mode = 0;
6

    
7
        public TestApp() {
8
        }
9

    
10
        public static void main(String args[]) {
11

    
12
                String host = (args.length < 1) ? null : args[0];
13
                System.out.print("Host: " + host + "\n");
14
                String filePathName;
15
                int replication;
16
                int size;
17

    
18
                String subProtocol = args[1];
19
                System.out.print("SubProtocol: " + subProtocol + "\n");
20

    
21
                try {
22
                        Registry registry = LocateRegistry.getRegistry(null);
23
                        RMInterface stub = (RMInterface) registry.lookup(host);
24

    
25
                        switch (subProtocol) {
26
                        case "BACKUP":
27
                                filePathName = args[2];
28
                                System.out.print("File: " + filePathName + "\n");
29

    
30
                                try {
31
                                        replication = Integer.parseInt(args[3]);
32

    
33
                                } catch (NumberFormatException e) {
34
                                        replication = 0;
35
                                }
36
                                System.out.print("Replication: " + replication + "\n");
37
                        
38
                                stub.backupFile(filePathName, replication);
39

    
40
                                break;
41
                        case "BACKUPENH":
42
                                filePathName = args[2];
43
                                System.out.print("File: " + filePathName + "\n");
44
                                try {
45
                                        replication = Integer.parseInt(args[3]);
46
                                } catch (NumberFormatException e) {
47
                                        replication = 0;
48
                                }
49
                                System.out.print("Replication: " + replication + "\n");
50
                                stub.backupEnhFile(filePathName, replication);
51
                                break;
52
                        case "RESTORE":
53
                                filePathName = args[2];
54
                                System.out.print("File: " + filePathName + "\n");
55
                                stub.restoreFile(filePathName);
56
                                break;
57
                        case "RESTOREENH":
58
                                filePathName = args[2];
59
                                System.out.print("File: " + filePathName + "\n");
60
                                break;
61
                        case "DELETE":
62
                                filePathName = args[2];
63
                                stub.deleteFile(filePathName);
64
                                System.out.print("File: " + filePathName + "\n");
65
                                break;
66
                        case "DELETEENH":
67
                                filePathName = args[2];
68
                                System.out.print("File: " + filePathName + "\n");
69
                                break;
70
                        case "RECLAIM":
71
                                try {
72
                                        size = Integer.parseInt(args[2]);
73
                                } catch (NumberFormatException e) {
74
                                        size = 0;
75
                                }
76
                                System.out.print("size: " + size + "\n");
77
                                stub.reclaim(size);
78
                                break;
79
                        case "RECLAIMENH":
80
                                try {
81
                                        replication = Integer.parseInt(args[3]);
82
                                } catch (NumberFormatException e) {
83
                                        replication = 0;
84
                                }
85
                                System.out.print("Replication: " + replication + "\n");
86
                                break;
87
                        case "STATE":
88
                                System.out.println(stub.state());
89
                                break;
90
                        default:
91
                                break;
92
                        }
93
                } catch (Exception e) {
94
                        System.err.println("Client exception: " + e.toString());
95
                        e.printStackTrace();
96
                }
97
        }
98
}