1 26 27 package org.objectweb.ccm.demo1.cif; 28 29 import org.objectweb.ccm.demo1.*; 30 31 39 40 public class Demo1 41 { 42 45 public static void 46 main(String [] args) 47 throws Exception 48 { 49 String _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase(); 50 51 System.out.println("Initializing the ORB..."); 53 54 59 org.omg.CORBA.ORB orb = org.objectweb.openccm.Components.Runtime.init(args); 61 62 System.out.println("Obtaining the Name Service..."); 64 org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService"); 65 org.omg.CosNaming.NamingContext nc = org.omg.CosNaming.NamingContextHelper.narrow(obj); 66 67 72 org.omg.CosTransactions.Current current = null; 73 if (_OTS.equals("yes")) 74 { 75 System.out.println("Obtaining the Transaction Service..."); 76 org.omg.CORBA.Object objOTS = orb.resolve_initial_references("TransactionCurrent"); 77 current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS ); 78 } 79 80 try 81 { 82 if ((current!=null)&&(_OTS.equals("yes"))) 83 { 84 System.out.println("Status = "+current.get_status()); 85 System.out.println("Beginning the transaction..."); 86 current.begin(); 87 } 88 89 System.out.println("Obtaining Component Servers..."); 91 org.omg.CosNaming.NameComponent [] ncomp = new org.omg.CosNaming.NameComponent [1]; 92 ncomp[0] = new org.omg.CosNaming.NameComponent ("ComponentServer1", ""); 93 obj = nc.resolve(ncomp); 94 org.objectweb.openccm.Deployment.Server server1 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 95 ncomp[0].id = "ComponentServer2"; 96 obj = nc.resolve(ncomp); 97 org.objectweb.openccm.Deployment.Server server2 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 98 99 org.omg.Components.Deployment.ComponentServer server1_cs = server1.provide_component_server(); 101 org.omg.Components.Deployment.ComponentInstallation server1_inst = server1.provide_install(); 102 org.omg.Components.Deployment.ComponentServer server2_cs = server2.provide_component_server(); 103 org.omg.Components.Deployment.ComponentInstallation server2_inst = server2.provide_install(); 104 105 System.out.println("Installing archives..."); 107 String demoPath = null; 109 try { 110 demoPath = new java.io.File (".").getCanonicalPath()+ java.io.File.separator ; 111 }catch(Exception e) { 112 e.printStackTrace(); 113 } 114 115 server1_inst.install("demo1", "file:"+demoPath + "./archives/demo1.jar"); 116 server2_inst.install("demo1", "file:"+demoPath + "./archives/demo1.jar"); 117 118 server1_inst.install("openccm_plugins", "file:"+demoPath + "./archives/OpenCCM_Plugins.jar"); 120 server2_inst.install("openccm_plugins", "file:"+demoPath + "./archives/OpenCCM_Plugins.jar"); 121 122 145 146 String cont_config = 147 "container = CONTAINER.container ; " + 149 "JAVA.declare(\"org.objectweb.openccm.Containers\") ; " + 151 "PropertySet = org.objectweb.openccm.Containers.PropertySetImpl ;" + 152 "StringProperty = org.objectweb.openccm.Containers.StringPropertyImpl ;" + 153 "config_home = container.create_system_home("+ 155 "\"openccm_plugins\", " + 156 "\"EmptyConfig\", "+ 157 "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+ 158 "config = config_home.create_component(JAVA.null) ;" + 159 "container.create_system_home("+ 161 "\"openccm_plugins\", " + 162 "\"EmptyCoordinatorHome\", "+ 163 "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+ 164 "container.create_system_home("+ 166 "\"openccm_plugins\", " + 167 "\"EmptyControllerHome\", "+ 168 "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+ 169 "container.create_system_home("+ 171 "\"openccm_plugins\", " + 172 "\"Trace\", " + 173 "\"org.objectweb.openccm.Containers.Plugins.TraceControllerHome.create\") ; "+ 174 "container.create_system_home("+ 176 "\"openccm_plugins\", " + 177 "\"ListCoord\", " + 178 "\"org.objectweb.openccm.Containers.Plugins.ListCoordinatorHome.create\") ; "+ 179 "container.create_system_home("+ 181 "\"openccm_plugins\", " + 182 "\"PortConfig\", " + 183 "\"org.objectweb.openccm.Containers.Plugins.PortSpecificConfigurationHome.create\") ; " + 184 "container.set_container_configuration(config) ;"; 186 187 org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1]; 189 config[0] = new org.objectweb.openccm.Components.ConfigValueImpl(); 190 config[0].name = "container_script"; 191 org.omg.CORBA.TypeCode string_tc = 192 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string); 193 org.omg.CORBA.Any value = 194 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory(). 195 create_dyn_any_from_type_code(string_tc).to_any(); 196 value.insert_string(cont_config); 197 config[0].value = value; 198 199 200 org.omg.Components.Deployment.Container server1_cont = 201 server1_cs.create_container(new org.omg.Components.ConfigValue[0]); 203 org.omg.Components.Deployment.Container server2_cont = 204 server2_cs.create_container(new org.omg.Components.ConfigValue[0]); 206 207 208 System.out.println("Instantiating homes..."); 210 211 config[0].name = "home_script"; 213 214 223 224 java.lang.String home_config = 225 "container.set_home_configuration(container.get_container_configuration()) ;" + 228 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 230 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo1/Server:1.0\") ;" + 232 "config.setCallCoordinator(\"for_clients\", \"ListCoord\") ;" + 234 "config.setCallControllers(\"for_clients\", [ \"Trace\" ]) ;" + 236 "trace_config = PropertySet(\"trace\")" + 238 "trace_config.add(StringProperty(\"filename\", \"./trace_Server.txt\"))" + 239 "config.setCallControllersConfig(\"for_clients\", [ trace_config ])" + 240 "config.set_parent_configuration(container.get_container_configuration()) ;" + 242 "container.set_component_configuration(config) ;"; 244 245 value.insert_string(home_config); 247 config[0].value = value; 248 249 org.omg.Components.CCMHome h = 251 server1_cont.install_home("demo1", 252 "org.objectweb.ccm.demo1.cif.ServerHomeImpl.create_home", 253 new org.omg.Components.ConfigValue[0]); 254 ServerHome sh = ServerHomeHelper.narrow(h); 255 256 263 264 home_config = 265 "container.set_home_configuration(container.get_container_configuration()) ;" + 268 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 270 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo1/Client:1.0\") ;" + 272 "config.setCallCoordinator(\"to_server\", \"ListCoord\") ;" + 274 "config.setCallControllers(\"to_server\", [ \"Trace\" ]) ;" + 276 "trace_config = PropertySet(\"trace\")" + 278 "trace_config.add(StringProperty(\"filename\", \"./trace_Clients.txt\"))" + 279 "trace_config.add(StringProperty(\"singleton\", \"to_server\"))" + 280 "config.setCallControllersConfig(\"to_server\", [ trace_config ])" + 281 "config.set_parent_configuration(container.get_container_configuration()) ;" + 283 "container.set_component_configuration(config) ;"; 285 286 value.insert_string(home_config); 288 config[0].value = value; 289 290 h = server2_cont.install_home("demo1", 292 "org.objectweb.ccm.demo1.cif.ClientHomeImpl.create_home", 293 new org.omg.Components.ConfigValue[0]); 294 ClientHome ch = ClientHomeHelper.narrow(h); 295 296 297 System.out.println("Instantiating components..."); 299 Server s = sh.create(); 300 Client c1 = ch.create(); 301 Client c2 = ch.create(); 302 Client c3 = ch.create(); 303 304 System.out.println("Configuring components..."); 306 s.the_name("The Server"); 307 c1.the_name("Christophe"); 308 c2.the_name("Romain"); 309 c3.the_name("Philippe"); 310 311 System.out.println("Interconnecting components..."); 313 Display for_clients = s.provide_for_clients(); 314 c1.connect_to_server(for_clients); 315 c2.connect_to_server(for_clients); 316 c3.connect_to_server(for_clients); 317 318 System.out.println("Configuration completion..."); 320 s.configuration_complete(); 321 c1.configuration_complete(); 322 c2.configuration_complete(); 323 c3.configuration_complete(); 324 325 } catch (Exception e) { 326 if ((current!=null)&&(_OTS.equals("yes"))) 327 { 328 System.out.println("Error during deployment :"); 329 e.printStackTrace(); 330 System.out.print("Rolling Back ... "); 331 current.rollback(); 332 System.out.println("Done"); 333 System.exit(0); 335 } 336 else 337 { 338 System.out.println("Error during deployment :"); 339 e.printStackTrace(); 340 System.exit(0); 342 } 343 } 344 345 if ((current!=null)&&(_OTS.equals("yes"))) 346 { 347 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 348 349 java.io.BufferedReader _buffer 350 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 351 char _answer = (char) _buffer.read(); 352 353 if ((_answer=='n')||(_answer=='N')) 354 { 355 System.out.print("Rolling Back ... "); 356 current.rollback(); 357 System.out.println("Done"); 358 } 359 else 360 { 361 System.out.print("Committing ... "); 362 current.commit(false); 363 System.out.println("Done"); 364 } 365 } 366 367 System.exit(0); 369 } 370 } 371 372 373 374 375 376 377 378 | Popular Tags |