167f1e0e4432afad029ea452dd766a8eb0aa8591
[RRRRHHHH_Code] / ruralHouses / src / launcher / RMILauncher.java
1 package launcher;
2
3 import java.rmi.Naming;
4 import java.rmi.RMISecurityManager;
5 import java.rmi.Remote;
6
7 import businessLogic.AccountManager;
8 import businessLogic.AdminManager;
9 import businessLogic.BookingManager;
10 import businessLogic.HouseManager;
11 import businessLogic.LoginManager;
12 import businessLogic.OfferManager;
13 import businessLogic.OwnerManager;
14
15 public class RMILauncher {
16
17         public static void main(String[] args) {
18                 RMILauncher.startRegistry();
19                 RMILauncher.initRemoteObject();
20         }
21
22         private static void startRegistry() {
23                 System.setProperty("java.security.policy", "java.policy");
24                 System.setSecurityManager(new RMISecurityManager());
25                 try {
26                         java.rmi.registry.LocateRegistry.createRegistry(9999);
27                 } catch (Exception e) {
28                         System.out.println(e.toString()
29                                         + "\nRMI registry was already created");
30                 }
31
32         }
33
34         private static void initRemoteObject() {
35                 boolean adm = runAdmin();
36                 boolean bok = runBooking();
37                 boolean hou = runHouse();
38                 boolean off = runOffer();
39                 boolean own = runOwner();
40                 boolean log = runLogin();
41                 boolean acc = runAccount();
42
43                 System.out.println("  Admin: "+adm+
44                                                         "\t Booking:  "+bok+
45                                                         "\t House:  "+hou+
46                                                         "\t Login:  "+log+
47                                                         "\t Offer:  "+off+
48                                                         "\t Owner:  "+own+
49                                                         "\t Account: "+acc);
50         }
51         
52         private static boolean runAdmin() {
53                 try {
54                         Remote remoteObject = new AdminManager();
55                         String authService = "rmi://localhost:9999//AdM";
56                         Naming.rebind(authService, remoteObject);
57                         return true;
58                 } catch (Exception e) {
59                         System.out.println(e.toString());
60                         return false;
61                 }
62         }
63
64         private static boolean runAccount() {
65                 try {
66                         Remote remoteObject = new AccountManager();
67                         String authService = "rmi://localhost:9999//AcM";
68                         Naming.rebind(authService, remoteObject);
69                         return true;
70                 } catch (Exception e) {
71                         System.out.println(e.toString());
72                         return false;
73                 }
74         }
75         
76         private static boolean runBooking() {
77                 try {
78                         Remote remoteBooking = new BookingManager();
79                         String authService = "rmi://localhost:9999//BoM";
80                         Naming.rebind(authService, remoteBooking);
81                         return true;
82                 } catch (Exception e) {
83                         System.out.println(e.toString());
84                         return false;
85                 }
86         }
87
88         
89         private static boolean runHouse() {
90                 try {
91                         Remote remoteHouse = new HouseManager();
92                         String authService = "rmi://localhost:9999//HoM";
93                         Naming.rebind(authService, remoteHouse);
94                         return true;
95                 } catch (Exception e) {
96                         System.out.println(e.toString());
97                         return false;
98                 }
99         }
100
101         
102         private static boolean runLogin() {
103                 try {
104                         Remote remoteLogin = new LoginManager();
105                         String authService = "rmi://localhost:9999//LoM";
106                         Naming.rebind(authService, remoteLogin);
107                         return true;
108                 } catch (Exception e) {
109                         System.out.println(e.toString());
110                         return false;
111                 }
112         }
113
114         
115         private static boolean runOffer() {
116                 try {
117                         Remote remoteOffer = new OfferManager();
118                         String authService = "rmi://localhost:9999//OfM";
119                         Naming.rebind(authService, remoteOffer);
120                         return true;
121                 } catch (Exception e) {
122                         System.out.println(e.toString());
123                         return false;
124                 }
125         }
126
127         
128         private static boolean runOwner() {
129                 try {
130                         Remote remoteOwner = new OwnerManager();
131                         String authService = "rmi://localhost:9999//OwM";
132                         Naming.rebind(authService, remoteOwner);
133                         return true;
134                 } catch (Exception e) {
135                         System.out.println(e.toString());
136                         return false;
137                 }
138         }
139         
140         
141 }