Project

General

Profile

Revision 11

View differences:

client/ClientApp.java
1
package client;
2

  
3
import java.io.Serializable;
4
import java.nio.file.Path;
5
import java.rmi.registry.LocateRegistry;
6
import java.rmi.registry.Registry;
7
import java.util.*;
8
import java.util.concurrent.ScheduledThreadPoolExecutor;
9

  
10
import server.InterfaceServer;
11

  
12
public class ClientApp implements Serializable{
13

  
14
   private ClientApp() {
15
   }
16

  
17
   public static void main(String[] args) {
18
      String operation ="";
19
      String host ="";
20
      String peer="";
21
      String path = "";
22
      try {
23
         operation = args[0];
24
         host = args[1];
25
         peer = args[2];
26
      }
27
      catch (Exception e){
28
         System.out.println("INVALID ARGUMENTS");
29
      }
30
     
31
      try {
32
         // Getting the registry
33
         Registry registry = LocateRegistry.getRegistry(host);
34

  
35
         // Looking up the registry for the remote object
36
         InterfaceServer stub = (InterfaceServer) registry.lookup(peer);
37

  
38
         // Calling the remote method using the obtained object
39

  
40
         switch (operation) {
41
         case "BACKUP":
42
            System.out.println("EXECUTING BACKUP");
43
            path = args[3];
44
            int replicationDegree = Integer.parseInt(args[4]);
45
            stub.backupFile(path, replicationDegree);
46
            System.out.println("BACKUP DONE");
47
            break;
48
         case "DELETE":
49
            System.out.println("EXECUTING DELETE");
50
            path = args[3];
51
            stub.deleteFile(path);
52
            System.out.println("DELETE DONE");
53
            break;
54
         case "RESTORE":
55
            System.out.println("EXECUTING RESTORE");
56
            path = args[3];
57
            stub.restoreFile(path);
58
            System.out.println("RESTORE DONE");
59
            break;
60
         case "MANAGE":
61
            System.out.println("EXECUTING MANAGE");
62
            int size = Integer.parseInt(args[3]);
63
            stub.manageLocalStorage(size);
64
            System.out.println("MANAGE DONE");
65
            break;
66
         case "RETRIEVE":
67
            System.out.println("EXECUTING RETRIEVE");
68
            stub.retrieveLocalInformation();
69
            System.out.println("RETRIEVE DONE");
70
            break;
71
         default:
72
            System.out.println("Invalid operation or arguments");
73
            break;
74
         }
75

  
76
         System.out.println("Remote method invoked");
77
      } catch (Exception e) {
78
         System.err.println("Client exception: " + e.toString());
79
         e.printStackTrace();
80
      }
81
   }
82

  
83
}

Also available in: Unified diff