KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > reactorDemo


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm@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, Mathieu Vadet.
23 Contributor(s): Romain Rouvoy, Christophe Contreras.
24
25 ====================================================================*/

26
27 package org.coach.reactorDemo;
28
29
30 /**
31  * The demo1 application Deployment.
32  *
33  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</A>
34  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</A>
35  */

36
37 public class reactorDemo
38 {
39     /**
40      * The bootstrap of the demo1 application.
41      */

42     public static void
43     main(String JavaDoc[] args)
44     throws Exception JavaDoc
45     {
46        String JavaDoc _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase();
47
48        // Init the ORB.
49
System.out.println("Initializing the ORB...");
50
51        // TODO: Need to report this ORB.init() problem to OpenORB developers!
52
// Due to an OpenORB problem, the following line:
53
// org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
54
// are replaced by the next line.
55

56        // Init the OpenCCM Components Runtime.
57
org.omg.CORBA.ORB JavaDoc orb = org.objectweb.openccm.Components.Runtime.init(args);
58
59        // Obtain the Name Service.
60
System.out.println("Obtaining the Name Service...");
61        org.omg.CORBA.Object JavaDoc obj = orb.resolve_initial_references("NameService");
62        org.omg.CosNaming.NamingContext JavaDoc nc = org.omg.CosNaming.NamingContextHelper.narrow(obj);
63        
64 // String[] ids = orb.list_initial_services();
65
// System.out.println("R‰f‰rences initiales disponibles : ");
66
// for (int i=0;i<ids.length;i++)
67
// System.out.println("-> "+ids[i]);
68

69        org.omg.CosTransactions.Current current = null;
70        if (_OTS.equals("yes"))
71          {
72             System.out.println("Obtaining the Transaction Service...");
73             org.omg.CORBA.Object JavaDoc objOTS = orb.resolve_initial_references("TransactionCurrent");
74             current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS );
75          }
76
77        try
78          {
79             if ((current!=null)&&(_OTS.equals("yes")))
80               {
81                  System.out.println("Status = "+current.get_status());
82                  System.out.println("Beginning the transaction...");
83                  current.begin();
84               }
85             
86             // Obtain the component servers.
87
System.out.println("Obtaining Component Servers...");
88             org.omg.CosNaming.NameComponent JavaDoc[] ncomp = new org.omg.CosNaming.NameComponent JavaDoc[1];
89             ncomp[0] = new org.omg.CosNaming.NameComponent JavaDoc("ComponentServer1", "");
90             obj = nc.resolve(ncomp);
91             org.objectweb.openccm.Deployment.Server server1 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj);
92             ncomp[0].id = "ComponentServer2";
93             obj = nc.resolve(ncomp);
94             org.objectweb.openccm.Deployment.Server server2 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj);
95
96             // Obtain the container homes and archive installators.
97
org.omg.Components.Deployment.ComponentServer server1_cs = server1.provide_component_server();
98             org.omg.Components.Deployment.ComponentInstallation server1_inst = server1.provide_install();
99             org.omg.Components.Deployment.ComponentServer server2_cs = server2.provide_component_server();
100             org.omg.Components.Deployment.ComponentInstallation server2_inst = server2.provide_install();
101
102             // Install archives.
103
System.out.println("Installing archives...");
104             // get the current directory and store it as a String
105
String JavaDoc demoPath = null;
106             try {
107                 demoPath = new java.io.File JavaDoc(".").getCanonicalPath()+ java.io.File.separator ;
108             }catch(Exception JavaDoc e) {
109                 e.printStackTrace();
110             }
111
112             server1_inst.install("reactorDemo", "file:" + demoPath + "./archives/reactorDemo.jar");
113             server2_inst.install("reactorDemo", "file:" + demoPath + "./archives/reactorDemo.jar");
114
115             // install some plugins already provided by OpenCCM.
116
server1_inst.install("openccm_plugins", "file:" + demoPath + "./archives/OpenCCM_Plugins.jar");
117             server2_inst.install("openccm_plugins", "file:" + demoPath + "./archives/OpenCCM_Plugins.jar");
118
119             // declaring the container types
120
//
121
// Uncomment this part for a minimal configuration
122
// and comment the following one.
123
//
124
//
125
String JavaDoc cont_config =
126              "container = CONTAINER.container ; " +
127              "config_home = container.create_system_home("+
128              "\"openccm_plugins\", " +
129              "\"EmptyConfig\", "+
130              "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+
131              "config = config_home.create_component(JAVA.null) ;" +
132              "container.create_system_home("+
133              "\"openccm_plugins\", " +
134              "\"EmptyCoordinatorHome\", "+
135              "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+
136              "container.create_system_home("+
137              "\"openccm_plugins\", " +
138              "\"EmptyControllerHome\", "+
139              "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+
140              "container.set_container_configuration(config) ;";
141              
142             org.omg.Components.Deployment.Container server1_cont = server1_cs.create_container(new org.omg.Components.ConfigValue[0]);
143             org.omg.Components.Deployment.Container server2_cont = server2_cs.create_container(new org.omg.Components.ConfigValue[0]);
144
145             // Install homes.
146
System.out.println("Instantiating homes...");
147            
148             java.lang.String JavaDoc home_config =
149               "container.set_home_configuration(container.get_container_configuration()) ;" +
150               "container.set_component_configuration(container.get_container_configuration()) ;";
151
152             org.omg.Components.CCMHome h2 = server1_cont.install_home("reactorDemo", "org.coach.reactorDemo.TweeHomeComponentImpl.create_home", new org.omg.Components.ConfigValue[0]);
153             TweeHome sh = TweeHomeHelper.narrow(h2);
154
155             org.omg.Components.CCMHome h1 = server2_cont.install_home("reactorDemo", "org.coach.reactorDemo.EenHomeComponentImpl.create_home", new org.omg.Components.ConfigValue[0]);
156             EenHome ch = EenHomeHelper.narrow(h1);
157           
158             // Create components.
159
System.out.println("Instantiating components");
160             Twee s1 = sh.create();
161             Twee s2 = sh.create();
162             Een c1 = ch.create();
163             Een c2 = ch.create();
164             Een c3 = ch.create();
165             // Configure components.
166
System.out.println("Configuring components...");
167             s1.the_name("De Ene Twee Server");
168             s2.the_name("De Andere Twee Server");
169             c1.the_name("Een 1");
170             c2.the_name("Een 2");
171             c3.the_name("Een 3");
172             
173             // Connect clients and server.
174
System.out.println("Interconnecting components...");
175             i_Aap aapRef1 = s1.provide_ditIsAap();
176             i_Aap aapRef2 = s2.provide_ditIsAap();
177             c1.connect_gebruiktAap(aapRef1);
178             c2.connect_gebruiktAap(aapRef1);
179             c3.connect_gebruiktAap(aapRef2);
180
181             // Configuration completion.
182
System.out.println("Configuration completion...");
183             s1.configuration_complete();
184             s2.configuration_complete();
185             c1.configuration_complete();
186             c2.configuration_complete();
187             c3.configuration_complete();
188             
189             System.out.println("Trying to get to the reactor...");
190         myEnumUnionHolder eenEnum=new myEnumUnionHolder();
191         myEnumUnion aapje=new myEnumUnion();
192         aapje.Dummy((short)10);
193         eenEnum.value = aapje;
194             
195 for (int k=1; k<2; k++)
196           try {
197 short aval = eenEnum.value.Dummy();
198             System.out.println("before reactor eenEnum="+ aval + "server name is: " + s2.the_name());
199             aapRef1.method3("een string", eenEnum, "een andere string");
200             short val = eenEnum.value.Dummy();
201             System.out.println("eenEnum na reactor=" + val);
202           } catch (Exception JavaDoc e) {
203                System.out.println("Error......");
204                  // dump stack
205
e.printStackTrace();
206           };
207         
208          } catch (Exception JavaDoc e) {
209             if ((current!=null)&&(_OTS.equals("yes")))
210               {
211                  System.out.println("Error during Deployment :");
212                  e.printStackTrace();
213                  System.out.print("Rolling Back ... ");
214                  current.rollback();
215                  System.out.println("Done");
216                  // Force to exit.
217
System.exit(0);
218               } else {
219                  System.out.println("Error during Deployment :");
220                  e.printStackTrace();
221         }
222          }
223        
224        if ((current!=null)&&(_OTS.equals("yes")))
225          {
226             System.out.print("Do you want to commit the Deployment ? [Y/n] ");
227             
228             java.io.BufferedReader JavaDoc _buffer
229               = new java.io.BufferedReader JavaDoc(new java.io.InputStreamReader JavaDoc(System.in));
230             char _answer = (char) _buffer.read();
231             
232             if ((_answer=='n')||(_answer=='N'))
233               {
234                  System.out.print("Rolling Back ... ");
235                  current.rollback();
236                  System.out.println("Done");
237               } else {
238                  System.out.print("Committing ... ");
239                  current.commit(false);
240                  System.out.println("Done");
241               }
242          }
243        
244        // Force to exit.
245
System.exit(0);
246     }
247 }
248
249
250
251
252
253
254
255
Popular Tags