KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DiningPhilosophers > monolithic > Deployment_PC


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Sylvain Leblanc.
23 Contributor(s): Christophe Contreras.
24
25 ====================================================================*/

26
27 package DiningPhilosophers.monolithic;
28
29 import DiningPhilosophers.*;
30
31 /**
32  * The philosopher dinner application deployment.
33  *
34  * <p>
35  * This application is composed of four philosopher
36  * components, four fork manager components and one observer
37  * component distributed on two servers.
38  * These servers must be named "ComponentServer1" and "ComponentServer2".
39  * The OpenCCM_plugins.jar archive must be
40  * in the current directory and DinningPhilosophers.jar archive
41  * must be in <code>./archives</code> directory.
42  * </p>
43  *
44  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
45  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
46  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</A>
47  *
48  * @version 2.0
49  */

50
51 public class Deployment_PC
52 {
53     /**
54      * The bootstrap of the dinner application.
55      */

56     public static void
57     main(String JavaDoc[] args)
58     throws Exception JavaDoc
59     {
60         String JavaDoc _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase();
61
62         // Init the ORB.
63
System.out.println("Initializing the ORB...");
64
65         // TODO: Need to report this ORB.init() problem to OpenORB developers!
66
// Due to an OpenORB problem, the following lines:
67
// org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
68
// fr.lifl.goal.OpenCCM.Components.Runtime.init(orb);
69
// are replaced by the next line.
70

71         // Init the OpenCCM Components Runtime.
72
org.omg.CORBA.ORB JavaDoc orb = org.objectweb.openccm.Components.Runtime.init(args);
73
74         // Obtain the Name Service.
75
System.out.println("Obtaining the Name Service...");
76         org.omg.CORBA.Object JavaDoc obj =
77             orb.resolve_initial_references("NameService");
78         org.omg.CosNaming.NamingContext JavaDoc ns =
79             org.omg.CosNaming.NamingContextHelper.narrow(obj);
80         obj = orb.resolve_initial_references("CommonNameService");
81         org.omg.CosNaming.NamingContext JavaDoc cns =
82             org.omg.CosNaming.NamingContextHelper.narrow(obj);
83
84         org.omg.CosTransactions.Current current = null;
85         if (_OTS.equals("yes"))
86         {
87             System.out.println("Obtaining the Transaction Service...");
88             org.omg.CORBA.Object JavaDoc objOTS = orb.resolve_initial_references("TransactionCurrent");
89             current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS );
90         }
91
92         try
93         {
94             if ((current!=null)&&(_OTS.equals("yes")))
95             {
96                 System.out.println("Beginning the transaction...");
97                 current.begin();
98             }
99
100             // Obtain the component servers.
101
System.out.println("Obtaining Component Servers...");
102             String JavaDoc cs1_name = System.getProperty("org.objectweb.ccm.DiningPhilosophers.CS1");
103             String JavaDoc cs2_name = System.getProperty("org.objectweb.ccm.DiningPhilosophers.CS2");
104
105             org.omg.CosNaming.NameComponent JavaDoc[] ncomp =
106                     new org.omg.CosNaming.NameComponent JavaDoc[1];
107             ncomp[0] = new org.omg.CosNaming.NameComponent JavaDoc(cs1_name, "");
108             obj = ns.resolve(ncomp);
109             org.objectweb.openccm.Deployment.Server server1 =
110             org.objectweb.openccm.Deployment.ServerHelper.narrow(obj);
111             ncomp[0].id = cs2_name;
112             obj = ns.resolve(ncomp);
113             org.objectweb.openccm.Deployment.Server server2 =
114             org.objectweb.openccm.Deployment.ServerHelper.narrow(obj);
115
116             // Obtain the home factories and archive installators.
117
org.omg.Components.Deployment.ComponentServer server1_cs =
118             server1.provide_component_server();
119             org.omg.Components.Deployment.ComponentInstallation server1_inst =
120             server1.provide_install();
121             org.omg.Components.Deployment.ComponentServer server2_cs =
122             server2.provide_component_server();
123             org.omg.Components.Deployment.ComponentInstallation server2_inst =
124             server2.provide_install();
125
126             // Install archives.
127
System.out.println("Installing archives...");
128             String JavaDoc http_server = System.getProperty("org.objectweb.ccm.DiningPhilosophers.http");
129             server1_inst.install("dinner", http_server + "DiningPhilosophers.jar");
130             server2_inst.install("dinner", http_server + "DiningPhilosophers.jar");
131             // install some plugins already provided by OpenCCM.
132
server1_inst.install("openccm_plugins", http_server + "DiningPhilosophers.jar");
133             server2_inst.install("openccm_plugins", http_server + "DiningPhilosophers.jar");
134
135             // declaring the container types
136
String JavaDoc cont_config =
137             "container = CONTAINER.container ; " +
138             "config_home = container.create_system_home("+
139                     "\"openccm_plugins\", " +
140                     "\"EmptyConfig\", "+
141                     "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+
142             "config = config_home.create_component(JAVA.null) ;" +
143             "container.create_system_home("+
144                     "\"openccm_plugins\", " +
145                     "\"EmptyCoordinatorHome\", "+
146                     "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+
147             "container.create_system_home("+
148                     "\"openccm_plugins\", " +
149                     "\"EmptyControllerHome\", "+
150                     "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+
151             "container.set_container_configuration(config) ;";
152
153             // instantiate a container on each server.
154
org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1];
155             config[0] = new org.objectweb.openccm.Components.ConfigValueImpl();
156             config[0].name = "container_script";
157             org.omg.CORBA.TypeCode JavaDoc string_tc =
158                 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string);
159             org.omg.CORBA.Any JavaDoc value =
160                 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory().
161                             create_dyn_any_from_type_code(string_tc).to_any();
162             value.insert_string(cont_config);
163             config[0].value = value;
164
165             org.omg.Components.Deployment.Container server1_cont =
166                 server1_cs.create_container(config);
167             org.omg.Components.Deployment.Container server2_cont =
168                 server2_cs.create_container(config);
169
170             // Create homes.
171
System.out.println("Instantiating homes...");
172
173             // define a container configuration.
174
java.lang.String JavaDoc home_config =
175                 "container.set_home_configuration(container.get_container_configuration()) ;" +
176                 "container.set_component_configuration(container.get_container_configuration()) ;";
177
178             config[0].name = "home_script";
179             value.insert_string(home_config);
180             config[0].value = value;
181
182             // install homes with this container configuration.
183

184             // On laptop
185
org.omg.Components.CCMHome h =
186                         server2_cont.install_home("dinner",
187                                                 "DiningPhilosophers.monolithic.PhilosopherHomeImpl.create_home",
188                                                 config);
189             PhilosopherHome ph = PhilosopherHomeHelper.narrow(h);
190
191             h = server2_cont.install_home("dinner",
192                                             "DiningPhilosophers.monolithic.ForkHomeImpl.create_home",
193                                             config);
194             ForkHome fh = ForkHomeHelper.narrow(h);
195             h = server2_cont.install_home("dinner",
196                                             "DiningPhilosophers.monolithic.ObserverHomeImpl.create_home",
197                                             config);
198             ObserverHome oh = ObserverHomeHelper.narrow(h);
199
200             // Register homes in the name service
201

202             // creating OpenCCM Context
203
org.omg.CosNaming.NameComponent JavaDoc[] nc =
204                 new org.omg.CosNaming.NameComponent JavaDoc[1];
205             nc[0] = new org.omg.CosNaming.NameComponent JavaDoc();
206             nc[0].id = "OpenCCM";
207             nc[0].kind = "";
208
209             try {
210                 ns = cns.bind_new_context(nc);
211             } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound JavaDoc ex) {
212                 ns = org.omg.CosNaming.NamingContextHelper.narrow(cns.resolve(nc));
213             }
214
215             nc[0].id = "PhilosopherHome";
216             ns.rebind(nc, ph);
217
218             nc[0].id = "ForkHome";
219             ns.rebind(nc, fh);
220
221             nc[0].id = "ObserverHome";
222             ns.rebind(nc, oh);
223
224         } catch (Exception JavaDoc e) {
225             if ((current!=null)&&(_OTS.equals("yes")))
226             {
227                 System.out.println("Error during deployment :");
228                 e.printStackTrace();
229                 System.out.print("Rolling Back ... ");
230                 current.rollback();
231                 System.out.println("Done");
232                 // Force to exit.
233
System.exit(0);
234              }
235         }
236
237         if ((current!=null)&&(_OTS.equals("yes")))
238         {
239             System.out.print("Do you want to commit the Deployment ? [Y/n] ");
240
241             java.io.BufferedReader JavaDoc _buffer =
242                     new java.io.BufferedReader JavaDoc(new java.io.InputStreamReader JavaDoc(System.in));
243             char _answer = (char) _buffer.read();
244
245             if ((_answer=='n')||(_answer=='N'))
246             {
247                 System.out.print("Rolling Back ... ");
248                 current.rollback();
249                 System.out.println("Done");
250             }
251             else
252             {
253                 System.out.print("Committing ... ");
254                 current.commit(false);
255                 System.out.println("Done");
256             }
257         }
258
259         // Force to exit.
260
System.exit(0);
261     }
262 }
263
264
265
266
267
268
Popular Tags