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