1 26 27 package org.objectweb.ccm.demo3.monolithic; 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 164 org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1]; 166 config[0] = new org.objectweb.openccm.Components.ConfigValueImpl(); 167 config[0].name = "container_script"; 168 org.omg.CORBA.TypeCode string_tc = 169 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string); 170 org.omg.CORBA.Any value = 171 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory(). 172 create_dyn_any_from_type_code(string_tc).to_any(); 173 value.insert_string(cont_config); 174 config[0].value = value; 175 176 177 org.omg.Components.Deployment.Container server1_cont = 178 server1_cs.create_container(config); 179 org.omg.Components.Deployment.Container server2_cont = 180 server2_cs.create_container(config); 181 182 System.out.println("Instantiating homes..."); 184 185 config[0].name = "home_script"; 187 String home_config = 188 "container.set_home_configuration(container.get_container_configuration()) ;" + 191 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 193 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo3/Client:1.0\") ;" + 195 "config.setCallCoordinator(\"the_service\", \"ListCoord\") ;" + 197 "config.setCallControllers(\"the_service\", [ \"Trace\" ]) ;" + 199 "trace_config = PropertySet(\"trace\")" + 201 "trace_config.add(StringProperty(\"filename\", \"./trace_Clients.txt\"))" + 202 "trace_config.add(StringProperty(\"singleton\", \"the_service\"))" + 203 "config.setCallControllersConfig(\"the_service\", [ trace_config ])" + 204 "config.set_parent_configuration(container.get_container_configuration()) ;" + 206 "container.set_component_configuration(config) ;"; 208 209 value.insert_string(home_config); 211 config[0].value = value; 212 213 org.omg.Components.CCMHome h = null; 214 h = server1_cont.install_home("demo3", 215 "org.objectweb.ccm.demo3.monolithic.ClientHomeImpl.create_home", 216 config); 217 ClientHome ch = ClientHomeHelper.narrow(h); 218 219 home_config = 221 "container.set_home_configuration(container.get_container_configuration()) ;" + 224 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 226 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo3/Server:1.0\") ;" + 228 "config.setCallCoordinator(\"the_service\", \"ListCoord\") ;" + 230 "config.setCallControllers(\"the_service\", [ \"Trace\" ]) ;" + 232 "trace_config = PropertySet(\"trace\")" + 234 "trace_config.add(StringProperty(\"filename\", \"./trace_Server_Service.txt\"))" + 235 "config.setCallControllersConfig(\"the_service\", [ trace_config ])" + 236 "config.setCallCoordinator(\"to_consumers\", \"ListCoord\") ;" + 238 "config.setCallControllers(\"to_consumers\", [ \"Trace\" ]) ;" + 240 "trace_config = PropertySet(\"trace\")" + 242 "trace_config.add(StringProperty(\"filename\", \"./trace_Server_TextEvent.txt\"))" + 243 "config.setCallControllersConfig(\"to_consumers\", [ trace_config ])" + 244 "config.set_parent_configuration(container.get_container_configuration()) ;" + 246 "container.set_component_configuration(config) ;"; 248 249 value.insert_string(home_config); 251 config[0].value = value; 252 253 h = server2_cont.install_home("demo3", 254 "org.objectweb.ccm.demo3.monolithic.ServerHomeImpl.create_home", 255 config); 256 ServerHome sh = ServerHomeHelper.narrow(h); 257 258 home_config = 260 "container.set_home_configuration(container.get_container_configuration()) ;" + 263 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 265 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo3/Consumer:1.0\") ;" + 267 "config.setCallCoordinator(\"from_servers\", \"ListCoord\") ;" + 269 "config.setCallControllers(\"from_servers\", [ \"Trace\" ]) ;" + 271 "trace_config = PropertySet(\"trace\")" + 273 "trace_config.add(StringProperty(\"filename\", \"./trace_Consumers.txt\"))" + 274 "trace_config.add(StringProperty(\"singleton\", \"from_servers\"))" + 275 "config.setCallControllersConfig(\"from_servers\", [ trace_config ])" + 276 "config.set_parent_configuration(container.get_container_configuration()) ;" + 278 "container.set_component_configuration(config) ;"; 280 281 value.insert_string(home_config); 283 config[0].value = value; 284 285 h = server1_cont.install_home("demo3", 286 "org.objectweb.ccm.demo3.monolithic.ConsumerHomeImpl.create_home", 287 config); 288 ConsumerHome csh = ConsumerHomeHelper.narrow(h); 289 290 System.out.println("Creating components..."); 292 Server s = sh.create(); 293 Client c1 = ch.create(); 294 Client c2 = ch.create(); 295 Client c3 = ch.create(); 296 Consumer cs1 = csh.create(); 297 Consumer cs2 = csh.create(); 298 Consumer cs3 = csh.create(); 299 300 System.out.println("Configuring components..."); 302 c1.name("Mathieu"); 303 c2.name("Raphael"); 304 c3.name("Philippe"); 305 s.name("The Server"); 306 cs1.name("Mathieu"); 307 cs2.name("Raphael"); 308 cs3.name("Philippe"); 309 310 System.out.println("Interconnecting components..."); 312 Service the_service = s.provide_the_service(); 313 c1.connect_the_service(the_service); 314 c2.connect_the_service(the_service); 315 c3.connect_the_service(the_service); 316 s.subscribe_to_consumers(cs1.get_consumer_from_servers()); 317 s.subscribe_to_consumers(cs2.get_consumer_from_servers()); 318 s.subscribe_to_consumers(cs3.get_consumer_from_servers()); 319 320 System.out.println("Configuration completion..."); 322 cs1.configuration_complete(); 323 cs2.configuration_complete(); 324 cs3.configuration_complete(); 325 s.configuration_complete(); 326 c1.configuration_complete(); 327 c2.configuration_complete(); 328 c3.configuration_complete(); 329 330 } catch (Exception e) { 331 if ((current!=null)&&(_OTS.equals("yes"))) 332 { 333 System.out.println("Error during deployment :"); 334 e.printStackTrace(); 335 System.out.print("Rolling Back ... "); 336 current.rollback(); 337 System.out.println("Done"); 338 System.exit(0); 340 } 341 } 342 343 if ((current!=null)&&(_OTS.equals("yes"))) 344 { 345 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 346 347 java.io.BufferedReader _buffer 348 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 349 char _answer = (char) _buffer.read(); 350 351 if ((_answer=='n')||(_answer=='N')) 352 { 353 System.out.print("Rolling Back ... "); 354 current.rollback(); 355 System.out.println("Done"); 356 } else { 357 System.out.print("Committing ... "); 358 current.commit(false); 359 System.out.println("Done"); 360 } 361 } 362 363 System.exit(0); 365 } 366 } 367 368 369 | Popular Tags |