Project

General

Profile

Statistics
| Revision:

root / proj / src / TestApp.java @ 2

History | View | Annotate | Download (4.02 KB)

1

    
2
import java.io.File;
3
import java.io.IOException;
4
import java.net.DatagramPacket;
5
import java.net.InetAddress;
6
import java.net.MulticastSocket;
7
import java.net.UnknownHostException;
8
import java.rmi.registry.LocateRegistry;
9
import java.rmi.registry.Registry;
10

    
11

    
12
 
13
 
14
public class TestApp {
15
     
16
        private static String peer_ap;
17
        private static String sub_protocol;
18
        private static String file_path;
19
        private static double disk_space = 0;
20
        private static int ReplicationDeg = 0;
21
        
22
    public static void main(String[] args) throws UnknownHostException { //<peer_ap> <sub_protocol> <opnd_1> <opnd_2> 
23
            
24
            peer_ap = args[0];
25
        sub_protocol = args[1];
26
        
27
        
28
        try {               
29
            
30
            // Getting the registry                        
31
            Registry registry = LocateRegistry.getRegistry(null); 
32
       
33
            // Looking up the registry for the remote object 
34
            RMI stub = (RMI) registry.lookup(peer_ap); 
35
       
36
          
37
                System.out.println("PROTOCOL:  "+sub_protocol);
38
                
39
            if(sub_protocol.equals("BACKUP"))
40
            {
41
            
42
                    if(args.length != 4) {
43
                            System.out.println("Invalid arguments for Backup protocol");
44
                            System.out.println("java TestApp <peer_ap> BACKUP <file_path> <replication_degree>");
45
                            return;
46
                    }
47
                    ReplicationDeg = Integer.parseInt(args[3]);
48
                file_path = args[2];
49
                
50
                File f = new File(file_path);
51
                if(!f.exists()) { 
52
                    System.out.println("ERROR: File path specified doesn't lead to a file.");
53
                    
54
                    return;
55
                }
56
                
57
                stub.operation(sub_protocol, file_path, ReplicationDeg, disk_space);
58
            }
59
            else if(sub_protocol.equals("RESTORE"))
60
            {
61
                    if(args.length != 3) {
62
                            System.out.println("Invalid arguments for Restore protocol");
63
                            System.out.println("java TestApp <peer_ap> RESTORE <file_path>");
64
                            return;
65
                    }
66
                    
67
                file_path = args[2];
68
                
69
                stub.operation(sub_protocol, file_path, 0, 0);
70
            }
71
            else if(sub_protocol.equals("DELETE"))
72
            {
73
                    if(args.length != 3) {
74
                            System.out.println("Invalid arguments for Delete protocol");
75
                            System.out.println("java TestApp <peer_ap> DELETE <file_path> ");
76
                            return;
77
                    }
78
                    
79
                    
80
                    
81
                file_path = args[2];
82
                
83
              
84
                
85
                
86
                stub.operation(sub_protocol, file_path, ReplicationDeg, disk_space);
87
            }
88
            else if(sub_protocol.equals("RECLAIM"))
89
            {
90
                    if(args.length != 3) {
91
                            System.out.println("Invalid arguments for Reclaim protocol");
92
                            System.out.println("java TestApp <peer_ap> RECLAIM <space>");
93
                            return;
94
                    }
95
                    
96
                disk_space = Double.parseDouble(args[2]);
97
                
98
                stub.operation(sub_protocol, file_path, ReplicationDeg, disk_space);
99
            }
100
            
101
            else if(sub_protocol.equals("STATE"))
102
            {
103
                    if(args.length != 2) {
104
                            System.out.println("Invalid arguments for State protocol");
105
                            System.out.println("java TestApp <peer_ap> STATE");
106
                            return;
107
                    }
108

    
109
                stub.operation(sub_protocol, file_path, ReplicationDeg, disk_space);
110
               
111
            }
112
            
113
            
114
                 
115
           } catch (Exception e) {
116
                   System.err.println("TestApp Exception: " + e.toString());
117
                      e.printStackTrace();
118
           }
119
              
120
        System.out.println("PROTOCOL EXECUTED");
121
        
122
    }
123
    
124
   
125
}