1 26 27 package org.objectweb.ccm.demo3.cif; 28 29 import org.objectweb.ccm.demo3.*; 30 31 38 39 public class Demo3 40 { 41 44 public static void 45 main(String [] args) 46 throws Exception 47 { 48 String _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase(); 49 50 System.out.println("Initializing the ORB..."); 52 53 59 org.omg.CORBA.ORB orb = 61 org.objectweb.openccm.Components.Runtime.init(args); 62 63 System.out.println("Obtaining the Name Service..."); 65 org.omg.CORBA.Object obj = 66 orb.resolve_initial_references("NameService"); 67 org.omg.CosNaming.NamingContext nc = 68 org.omg.CosNaming.NamingContextHelper.narrow(obj); 69 70 org.omg.CosTransactions.Current current = null; 71 if (_OTS.equals("yes")) 72 { 73 System.out.println("Obtaining the Transaction Service..."); 74 org.omg.CORBA.Object objOTS = orb.resolve_initial_references("TransactionCurrent"); 75 current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS ); 76 } 77 78 try 79 { 80 if ((current!=null)&&(_OTS.equals("yes"))) 81 { 82 System.out.println("Beginning the transaction..."); 83 current.begin(); 84 } 85 86 System.out.println("Obtaining Component Servers..."); 88 org.omg.CosNaming.NameComponent [] ncomp = 89 new org.omg.CosNaming.NameComponent [1]; 90 ncomp[0] = new org.omg.CosNaming.NameComponent ("ComponentServer1", ""); 91 obj = nc.resolve(ncomp); 92 org.objectweb.openccm.Deployment.Server server1 = 93 org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 94 ncomp[0].id = "ComponentServer2"; 95 obj = nc.resolve(ncomp); 96 org.objectweb.openccm.Deployment.Server server2 = 97 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 String demoPath = null; 108 try { 109 demoPath = new java.io.File (".").getCanonicalPath()+ java.io.File.separator ; 110 }catch(Exception e) { 111 e.printStackTrace(); 112 } 113 114 server1_inst.install("demo3","file:"+ demoPath + "./archives/demo3.jar"); 115 server2_inst.install("demo3","file:"+ demoPath + "./archives/demo3.jar"); 116 117 server1_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 119 server2_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 120 121 String cont_config = 123 "container = CONTAINER.container ; " + 125 "JAVA.declare(\"org.objectweb.openccm.Containers\") ; " + 127 "PropertySet = org.objectweb.openccm.Containers.PropertySetImpl ;" + 128 "StringProperty = org.objectweb.openccm.Containers.StringPropertyImpl ;" + 129 "config_home = container.create_system_home("+ 131 "\"openccm_plugins\", " + 132 "\"EmptyConfig\", "+ 133 "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+ 134 "config = config_home.create_component(JAVA.null) ;" + 135 "container.create_system_home("+ 137 "\"openccm_plugins\", " + 138 "\"EmptyCoordinatorHome\", "+ 139 "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+ 140 "container.create_system_home("+ 142 "\"openccm_plugins\", " + 143 "\"EmptyControllerHome\", "+ 144 "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+ 145 "container.create_system_home("+ 147 "\"openccm_plugins\", " + 148 "\"Trace\", " + 149 "\"org.objectweb.openccm.Containers.Plugins.TraceControllerHome.create\") ; "+ 150 "container.create_system_home("+ 152 "\"openccm_plugins\", " + 153 "\"ListCoord\", " + 154 "\"org.objectweb.openccm.Containers.Plugins.ListCoordinatorHome.create\") ; "+ 155 "container.create_system_home("+ 157 "\"openccm_plugins\", " + 158 "\"PortConfig\", " + 159 "\"org.objectweb.openccm.Containers.Plugins.PortSpecificConfigurationHome.create\") ; " + 160 "container.set_container_configuration(config) ;"; 162 163 org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1]; 165 config[0] = new org.objectweb.openccm.Components.ConfigValueImpl(); 166 config[0].name = "container_script"; 167 org.omg.CORBA.TypeCode string_tc = 168 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string); 169 org.omg.CORBA.Any value = 170 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory(). 171 create_dyn_any_from_type_code(string_tc).to_any(); 172 value.insert_string(cont_config); 173 config[0].value = value; 174 175 176 org.omg.Components.Deployment.Container server1_cont = 177 server1_cs.create_container(config); 178 org.omg.Components.Deployment.Container server2_cont = 179 server2_cs.create_container(config); 180 181 System.out.println("Instantiating homes..."); 183 184 config[0].name = "home_script"; 186 String home_config = 187 "container.set_home_configuration(container.get_container_configuration()) ;" + 190 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 192 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo3/Client:1.0\") ;" + 194 "config.setCallCoordinator(\"the_service\", \"ListCoord\") ;" + 196 "config.setCallControllers(\"the_service\", [ \"Trace\" ]) ;" + 198 "trace_config = PropertySet(\"trace\")" + 200 "trace_config.add(StringProperty(\"filename\", \"./trace_Clients.txt\"))" + 201 "trace_config.add(StringProperty(\"singleton\", \"the_service\"))" + 202 "config.setCallControllersConfig(\"the_service\", [ trace_config ])" + 203 "config.set_parent_configuration(container.get_container_configuration()) ;" + 205 "container.set_component_configuration(config) ;"; 207 208 value.insert_string(home_config); 210 config[0].value = value; 211 212 org.omg.Components.CCMHome h = null; 213 h = server1_cont.install_home("demo3", 214 "org.objectweb.ccm.demo3.cif.ClientHomeImpl.create_home", 215 config); 216 ClientHome ch = ClientHomeHelper.narrow(h); 217 218 home_config = 220 "container.set_home_configuration(container.get_container_configuration()) ;" + 223 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 225 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo3/Server:1.0\") ;" + 227 "config.setCallCoordinator(\"the_service\", \"ListCoord\") ;" + 229 "config.setCallControllers(\"the_service\", [ \"Trace\" ]) ;" + 231 "trace_config = PropertySet(\"trace\")" + 233 "trace_config.add(StringProperty(\"filename\", \"./trace_Server_Service.txt\"))" + 234 "config.setCallControllersConfig(\"the_service\", [ trace_config ])" + 235 "config.setCallCoordinator(\"to_consumers\", \"ListCoord\") ;" + 237 "config.setCallControllers(\"to_consumers\", [ \"Trace\" ]) ;" + 239 "trace_config = PropertySet(\"trace\")" + 241 "trace_config.add(StringProperty(\"filename\", \"./trace_Server_TextEvent.txt\"))" + 242 "config.setCallControllersConfig(\"to_consumers\", [ trace_config ])" + 243 "config.set_parent_configuration(container.get_container_configuration()) ;" + 245 "container.set_component_configuration(config) ;"; 247 248 value.insert_string(home_config); 250 config[0].value = value; 251 252 h = server2_cont.install_home("demo3", 253 "org.objectweb.ccm.demo3.cif.ServerHomeImpl.create_home", 254 config); 255 ServerHome sh = ServerHomeHelper.narrow(h); 256 257 home_config = 259 "container.set_home_configuration(container.get_container_configuration()) ;" + 262 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 264 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo3/Consumer:1.0\") ;" + 266 "config.setCallCoordinator(\"from_servers\", \"ListCoord\") ;" + 268 "config.setCallControllers(\"from_servers\", [ \"Trace\" ]) ;" + 270 "trace_config = PropertySet(\"trace\")" + 272 "trace_config.add(StringProperty(\"filename\", \"./trace_Consumers.txt\"))" + 273 "trace_config.add(StringProperty(\"singleton\", \"from_servers\"))" + 274 "config.setCallControllersConfig(\"from_servers\", [ trace_config ])" + 275 "config.set_parent_configuration(container.get_container_configuration()) ;" + 277 "container.set_component_configuration(config) ;"; 279 280 value.insert_string(home_config); 282 config[0].value = value; 283 284 h = server1_cont.install_home("demo3", 285 "org.objectweb.ccm.demo3.cif.ConsumerHomeImpl.create_home", 286 config); 287 ConsumerHome csh = ConsumerHomeHelper.narrow(h); 288 289 System.out.println("Creating components..."); 291 Server s = sh.create(); 292 Client c1 = ch.create(); 293 Client c2 = ch.create(); 294 Client c3 = ch.create(); 295 Consumer cs1 = csh.create(); 296 Consumer cs2 = csh.create(); 297 Consumer cs3 = csh.create(); 298 299 System.out.println("Configuring components..."); 301 c1.name("Romain"); 302 c2.name("Christophe"); 303 c3.name("Philippe"); 304 s.name("The Server"); 305 cs1.name("Romain"); 306 cs2.name("Christophe"); 307 cs3.name("Philippe"); 308 309 System.out.println("Interconnecting components..."); 311 Service the_service = s.provide_the_service(); 312 c1.connect_the_service(the_service); 313 c2.connect_the_service(the_service); 314 c3.connect_the_service(the_service); 315 s.subscribe_to_consumers(cs1.get_consumer_from_servers()); 316 s.subscribe_to_consumers(cs2.get_consumer_from_servers()); 317 s.subscribe_to_consumers(cs3.get_consumer_from_servers()); 318 319 System.out.println("Configuration completion..."); 321 cs1.configuration_complete(); 322 cs2.configuration_complete(); 323 cs3.configuration_complete(); 324 s.configuration_complete(); 325 c1.configuration_complete(); 326 c2.configuration_complete(); 327 c3.configuration_complete(); 328 329 } catch (Exception e) { 330 if ((current!=null)&&(_OTS.equals("yes"))) 331 { 332 System.out.println("Error during deployment :"); 333 e.printStackTrace(); 334 System.out.print("Rolling Back ... "); 335 current.rollback(); 336 System.out.println("Done"); 337 System.exit(0); 339 } 340 } 341 342 if ((current!=null)&&(_OTS.equals("yes"))) 343 { 344 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 345 346 java.io.BufferedReader _buffer 347 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 348 char _answer = (char) _buffer.read(); 349 350 if ((_answer=='n')||(_answer=='N')) 351 { 352 System.out.print("Rolling Back ... "); 353 current.rollback(); 354 System.out.println("Done"); 355 } else { 356 System.out.print("Committing ... "); 357 current.commit(false); 358 System.out.println("Done"); 359 } 360 } 361 362 System.exit(0); 364 } 365 } 366 367 368 | Popular Tags |