1 26 27 package org.objectweb.ccm.demo1.monolithic; 28 29 import org.objectweb.ccm.demo1.*; 30 31 37 38 public class Demo1 39 { 40 43 public static void 44 main(String [] args) 45 throws Exception 46 { 47 String _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase(); 48 49 System.out.println("Initializing the ORB..."); 51 52 57 org.omg.CORBA.ORB orb = org.objectweb.openccm.Components.Runtime.init(args); 59 60 System.out.println("Obtaining the Name Service..."); 62 org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService"); 63 org.omg.CosNaming.NamingContext nc = org.omg.CosNaming.NamingContextHelper.narrow(obj); 64 65 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("Status = "+current.get_status()); 83 System.out.println("Beginning the transaction..."); 84 current.begin(); 85 } 86 87 System.out.println("Obtaining Component Servers..."); 89 org.omg.CosNaming.NameComponent [] ncomp = 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 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 93 ncomp[0].id = "ComponentServer2"; 94 obj = nc.resolve(ncomp); 95 org.objectweb.openccm.Deployment.Server server2 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 96 97 org.omg.Components.Deployment.ComponentServer server1_cs = server1.provide_component_server(); 99 org.omg.Components.Deployment.ComponentInstallation server1_inst = server1.provide_install(); 100 org.omg.Components.Deployment.ComponentServer server2_cs = server2.provide_component_server(); 101 org.omg.Components.Deployment.ComponentInstallation server2_inst = server2.provide_install(); 102 103 System.out.println("Installing archives..."); 105 String demoPath = null; 107 try { 108 demoPath = new java.io.File (".").getCanonicalPath()+ java.io.File.separator ; 109 }catch(Exception e) { 110 e.printStackTrace(); 111 } 112 113 server1_inst.install("demo1","file:"+ demoPath + "./archives/demo1.jar"); 114 server2_inst.install("demo1", "file:"+demoPath + "./archives/demo1.jar"); 115 116 server1_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 118 server2_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 119 120 143 144 String cont_config = 145 "container = CONTAINER.container ; " + 147 "JAVA.declare(\"org.objectweb.openccm.Containers\") ; " + 149 "PropertySet = org.objectweb.openccm.Containers.PropertySetImpl ;" + 150 "StringProperty = org.objectweb.openccm.Containers.StringPropertyImpl ;" + 151 "config_home = container.create_system_home("+ 153 "\"openccm_plugins\", " + 154 "\"EmptyConfig\", "+ 155 "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+ 156 "config = config_home.create_component(JAVA.null) ;" + 157 "container.create_system_home("+ 159 "\"openccm_plugins\", " + 160 "\"EmptyCoordinatorHome\", "+ 161 "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+ 162 "container.create_system_home("+ 164 "\"openccm_plugins\", " + 165 "\"EmptyControllerHome\", "+ 166 "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+ 167 "container.create_system_home("+ 169 "\"openccm_plugins\", " + 170 "\"Trace\", " + 171 "\"org.objectweb.openccm.Containers.Plugins.TraceControllerHome.create\") ; "+ 172 "container.create_system_home("+ 174 "\"openccm_plugins\", " + 175 "\"ListCoord\", " + 176 "\"org.objectweb.openccm.Containers.Plugins.ListCoordinatorHome.create\") ; "+ 177 "container.create_system_home("+ 179 "\"openccm_plugins\", " + 180 "\"PortConfig\", " + 181 "\"org.objectweb.openccm.Containers.Plugins.PortSpecificConfigurationHome.create\") ; " + 182 "container.set_container_configuration(config) ;"; 184 185 org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1]; 187 config[0] = new org.objectweb.openccm.Components.ConfigValueImpl(); 188 config[0].name = "container_script"; 189 org.omg.CORBA.TypeCode string_tc = 190 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string); 191 org.omg.CORBA.Any value = 192 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory(). 193 create_dyn_any_from_type_code(string_tc).to_any(); 194 value.insert_string(cont_config); 195 config[0].value = value; 196 197 198 org.omg.Components.Deployment.Container server1_cont = 199 server1_cs.create_container(new org.omg.Components.ConfigValue[0]); 201 org.omg.Components.Deployment.Container server2_cont = 202 server2_cs.create_container(new org.omg.Components.ConfigValue[0]); 204 205 206 System.out.println("Instantiating homes..."); 208 209 config[0].name = "home_script"; 211 212 221 222 java.lang.String home_config = 223 "container.set_home_configuration(container.get_container_configuration()) ;" + 226 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 228 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo1/Server:1.0\") ;" + 230 "config.setCallCoordinator(\"for_clients\", \"ListCoord\") ;" + 232 "config.setCallControllers(\"for_clients\", [ \"Trace\" ]) ;" + 234 "trace_config = PropertySet(\"trace\")" + 236 "trace_config.add(StringProperty(\"filename\", \"./trace_Server.txt\"))" + 237 "config.setCallControllersConfig(\"for_clients\", [ trace_config ])" + 238 "config.set_parent_configuration(container.get_container_configuration()) ;" + 240 "container.set_component_configuration(config) ;"; 242 243 value.insert_string(home_config); 245 config[0].value = value; 246 247 org.omg.Components.CCMHome h = server1_cont.install_home("demo1", "org.objectweb.ccm.demo1.monolithic.ServerHomeImpl.create_home", new org.omg.Components.ConfigValue[0]); 249 ServerHome sh = ServerHomeHelper.narrow(h); 250 251 258 259 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/demo1/Client:1.0\") ;" + 267 "config.setCallCoordinator(\"to_server\", \"ListCoord\") ;" + 269 "config.setCallControllers(\"to_server\", [ \"Trace\" ]) ;" + 271 "trace_config = PropertySet(\"trace\")" + 273 "trace_config.add(StringProperty(\"filename\", \"./trace_Clients.txt\"))" + 274 "trace_config.add(StringProperty(\"singleton\", \"to_server\"))" + 275 "config.setCallControllersConfig(\"to_server\", [ 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 = server2_cont.install_home("demo1", "org.objectweb.ccm.demo1.monolithic.ClientHomeImpl.create_home", new org.omg.Components.ConfigValue[0]); 287 ClientHome ch = ClientHomeHelper.narrow(h); 288 289 290 System.out.println("Instantiating components..."); 292 Server s = sh.create(); 293 Client c1 = ch.create(); 294 Client c2 = ch.create(); 295 Client c3 = ch.create(); 296 297 System.out.println("Configuring components..."); 299 s.the_name("The Server"); 300 c1.the_name("Mathieu"); 301 c2.the_name("Raphael"); 302 c3.the_name("Philippe"); 303 304 System.out.println("Interconnecting components..."); 306 Display for_clients = s.provide_for_clients(); 307 c1.connect_to_server(for_clients); 308 c2.connect_to_server(for_clients); 309 c3.connect_to_server(for_clients); 310 311 System.out.println("Configuration completion..."); 313 s.configuration_complete(); 314 c1.configuration_complete(); 315 c2.configuration_complete(); 316 c3.configuration_complete(); 317 318 } catch (Exception e) { 319 if ((current!=null)&&(_OTS.equals("yes"))) 320 { 321 System.out.println("Error during deployment :"); 322 e.printStackTrace(); 323 System.out.print("Rolling Back ... "); 324 current.rollback(); 325 System.out.println("Done"); 326 System.exit(0); 328 } 329 } 330 331 if ((current!=null)&&(_OTS.equals("yes"))) 332 { 333 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 334 335 java.io.BufferedReader _buffer 336 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 337 char _answer = (char) _buffer.read(); 338 339 if ((_answer=='n')||(_answer=='N')) 340 { 341 System.out.print("Rolling Back ... "); 342 current.rollback(); 343 System.out.println("Done"); 344 } else { 345 System.out.print("Committing ... "); 346 current.commit(false); 347 System.out.println("Done"); 348 } 349 } 350 351 System.exit(0); 353 } 354 } 355 356 357 358 359 360 361 362 | Popular Tags |