1 26 27 package org.objectweb.ccm.chat.monolithic; 28 29 import org.objectweb.ccm.chat.*; 30 31 36 37 public class Chat 38 { 39 42 public static void 43 main(String [] args) 44 throws Exception 45 { 46 String _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase(); 47 48 System.out.println("Initializing the ORB..."); 50 51 56 org.omg.CORBA.ORB orb = org.objectweb.openccm.Components.Runtime.init(args); 58 59 System.out.println("Obtaining the Name Service..."); 61 org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService"); 62 org.omg.CosNaming.NamingContext nc = org.omg.CosNaming.NamingContextHelper.narrow(obj); 63 64 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 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 System.out.println("Obtaining Component Servers..."); 88 org.omg.CosNaming.NameComponent [] ncomp = new org.omg.CosNaming.NameComponent [1]; 89 ncomp[0] = new org.omg.CosNaming.NameComponent ("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 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 System.out.println("Installing archives..."); 104 String demoPath = null; 106 try { 107 demoPath = new java.io.File (".").getCanonicalPath()+ java.io.File.separator ; 108 }catch(Exception e) { 109 e.printStackTrace(); 110 } 111 112 server1_inst.install("chat", "file:"+demoPath + "./archives/chat.jar"); 113 server2_inst.install("chat","file:"+ demoPath + "./archives/chat.jar"); 114 115 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 142 143 String cont_config = 144 "container = CONTAINER.container ; " + 146 "JAVA.declare(\"org.objectweb.openccm.Containers\") ; " + 148 "PropertySet = org.objectweb.openccm.Containers.PropertySetImpl ;" + 149 "StringProperty = org.objectweb.openccm.Containers.StringPropertyImpl ;" + 150 "config_home = container.create_system_home("+ 152 "\"openccm_plugins\", " + 153 "\"EmptyConfig\", "+ 154 "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+ 155 "config = config_home.create_component(JAVA.null) ;" + 156 "container.create_system_home("+ 158 "\"openccm_plugins\", " + 159 "\"EmptyCoordinatorHome\", "+ 160 "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+ 161 "container.create_system_home("+ 163 "\"openccm_plugins\", " + 164 "\"EmptyControllerHome\", "+ 165 "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+ 166 "container.create_system_home("+ 168 "\"openccm_plugins\", " + 169 "\"Trace\", " + 170 "\"org.objectweb.openccm.Containers.Plugins.TraceControllerHome.create\") ; "+ 171 "container.create_system_home("+ 173 "\"openccm_plugins\", " + 174 "\"ListCoord\", " + 175 "\"org.objectweb.openccm.Containers.Plugins.ListCoordinatorHome.create\") ; "+ 176 "container.create_system_home("+ 178 "\"openccm_plugins\", " + 179 "\"PortConfig\", " + 180 "\"org.objectweb.openccm.Containers.Plugins.PortSpecificConfigurationHome.create\") ; " + 181 "container.set_container_configuration(config) ;"; 183 184 org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1]; 186 config[0] = new org.objectweb.openccm.Components.ConfigValueImpl(); 187 config[0].name = "container_script"; 188 org.omg.CORBA.TypeCode string_tc = 189 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string); 190 org.omg.CORBA.Any value = 191 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory(). 192 create_dyn_any_from_type_code(string_tc).to_any(); 193 value.insert_string(cont_config); 194 config[0].value = value; 195 196 197 org.omg.Components.Deployment.Container server1_cont = 198 server1_cs.create_container(new org.omg.Components.ConfigValue[0]); 200 org.omg.Components.Deployment.Container server2_cont = 201 server2_cs.create_container(new org.omg.Components.ConfigValue[0]); 203 204 205 System.out.println("Instantiating homes..."); 207 208 config[0].name = "home_script"; 210 211 220 221 java.lang.String home_config = 222 "container.set_home_configuration(container.get_container_configuration()) ;" + 225 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 227 "config.setComponentUId(\"IDL:ccm.objectweb.org/chat/Server:1.0\") ;" + 229 "config.setCallCoordinator(\"for_clients\", \"ListCoord\") ;" + 231 "config.setCallControllers(\"for_clients\", [ \"Trace\" ]) ;" + 233 "trace_config = PropertySet(\"trace\")" + 235 "trace_config.add(StringProperty(\"filename\", \"./trace_Server.txt\"))" + 236 "config.setCallControllersConfig(\"for_clients\", [ trace_config ])" + 237 "config.set_parent_configuration(container.get_container_configuration()) ;" + 239 "container.set_component_configuration(config) ;"; 241 242 value.insert_string(home_config); 244 config[0].value = value; 245 246 org.omg.Components.CCMHome h = 248 server1_cont.install_home("chat", 249 "org.objectweb.ccm.chat.monolithic.ServerHomeImpl.create_home", 250 new org.omg.Components.ConfigValue[0]); 251 ServerHome sh = ServerHomeHelper.narrow(h); 252 253 260 261 home_config = 262 "container.set_home_configuration(container.get_container_configuration()) ;" + 265 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 267 "config.setComponentUId(\"IDL:ccm.objectweb.org/chat/Client:1.0\") ;" + 269 "config.setCallCoordinator(\"to_server\", \"ListCoord\") ;" + 271 "config.setCallControllers(\"to_server\", [ \"Trace\" ]) ;" + 273 "trace_config = PropertySet(\"trace\")" + 275 "trace_config.add(StringProperty(\"filename\", \"./trace_Clients.txt\"))" + 276 "trace_config.add(StringProperty(\"singleton\", \"to_server\"))" + 277 "config.setCallControllersConfig(\"to_server\", [ trace_config ])" + 278 "config.set_parent_configuration(container.get_container_configuration()) ;" + 280 "container.set_component_configuration(config) ;"; 282 283 value.insert_string(home_config); 285 config[0].value = value; 286 287 h = server2_cont.install_home("chat", 289 "org.objectweb.ccm.chat.monolithic.ClientHomeImpl.create_home", 290 new org.omg.Components.ConfigValue[0]); 291 ClientHome ch = ClientHomeHelper.narrow(h); 292 293 294 System.out.println("Instantiating components..."); 296 Server s = sh.create(); 297 Client c1 = ch.create(); 298 Client c2 = ch.create(); 299 300 301 System.out.println("Configuring components..."); 303 s.name("The Server"); 304 c1.name("Cosette"); 305 c2.name("Gavroche"); 306 307 308 System.out.println("Interconnecting components..."); 310 Service for_clients = s.provide_the_service(); 311 c1.connect_the_service(for_clients); 312 c2.connect_the_service(for_clients); 313 s.subscribe_to_consumers(c1.get_consumer_from_servers()); 314 s.subscribe_to_consumers(c2.get_consumer_from_servers()); 315 316 317 System.out.println("Configuration completion..."); 319 s.configuration_complete(); 320 c1.configuration_complete(); 321 c2.configuration_complete(); 322 323 324 } catch (Exception e) { 325 if ((current!=null)&&(_OTS.equals("yes"))) 326 { 327 System.out.println("Error during deployment :"); 328 e.printStackTrace(); 329 System.out.print("Rolling Back ... "); 330 current.rollback(); 331 System.out.println("Done"); 332 System.exit(0); 334 } 335 else 336 { 337 System.out.println("Error during deployment :"); 338 e.printStackTrace(); 339 System.exit(0); 341 } 342 } 343 344 if ((current!=null)&&(_OTS.equals("yes"))) 345 { 346 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 347 348 java.io.BufferedReader _buffer 349 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 350 char _answer = (char) _buffer.read(); 351 352 if ((_answer=='n')||(_answer=='N')) 353 { 354 System.out.print("Rolling Back ... "); 355 current.rollback(); 356 System.out.println("Done"); 357 } 358 else 359 { 360 System.out.print("Committing ... "); 361 current.commit(false); 362 System.out.println("Done"); 363 } 364 } 365 366 System.exit(0); 368 } 369 } 370 371 372 373 374 375 376 377 | Popular Tags |