Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code
[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
14 @SuppressWarnings("deprecation")
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 log = runLogin();
40                 boolean acc = runAccount();
41
42                 System.out.println("  Admin: "+adm+
43                                                         "\t Booking:  "+bok+
44                                                         "\t House:  "+hou+
45                                                         "\t Login:  "+log+
46                                                         "\t Offer:  "+off+
47                                                         "\t Account: "+acc);
48         }
49         
50         private static boolean runAdmin() {
51                 try {
52                         Remote remoteObject = new AdminManager();
53                         String authService = "rmi://localhost:9999//AdM";
54                         Naming.rebind(authService, remoteObject);
55                         return true;
56                 } catch (Exception e) {
57                         System.out.println(e.toString());
58                         return false;
59                 }
60         }
61
62         private static boolean runAccount() {
63                 try {
64                         Remote remoteObject = new AccountManager();
65                         String authService = "rmi://localhost:9999//AcM";
66                         Naming.rebind(authService, remoteObject);
67                         return true;
68                 } catch (Exception e) {
69                         System.out.println(e.toString());
70                         return false;
71                 }
72         }
73         
74         private static boolean runBooking() {
75                 try {
76                         Remote remoteBooking = new BookingManager();
77                         String authService = "rmi://localhost:9999//BoM";
78                         Naming.rebind(authService, remoteBooking);
79                         return true;
80                 } catch (Exception e) {
81                         System.out.println(e.toString());
82                         return false;
83                 }
84         }
85
86         
87         private static boolean runHouse() {
88                 try {
89                         Remote remoteHouse = new HouseManager();
90                         String authService = "rmi://localhost:9999//HoM";
91                         Naming.rebind(authService, remoteHouse);
92                         return true;
93                 } catch (Exception e) {
94                         System.out.println(e.toString());
95                         return false;
96                 }
97         }
98
99         
100         private static boolean runLogin() {
101                 try {
102                         Remote remoteLogin = new LoginManager();
103                         String authService = "rmi://localhost:9999//LoM";
104                         Naming.rebind(authService, remoteLogin);
105                         return true;
106                 } catch (Exception e) {
107                         System.out.println(e.toString());
108                         return false;
109                 }
110         }
111
112         
113         private static boolean runOffer() {
114                 try {
115                         Remote remoteOffer = new OfferManager();
116                         String authService = "rmi://localhost:9999//OfM";
117                         Naming.rebind(authService, remoteOffer);
118                         return true;
119                 } catch (Exception e) {
120                         System.out.println(e.toString());
121                         return false;
122                 }
123         }
124
125         
126
127         
128         
129 }