1 26 27 package org.objectweb.ccm.demo2.cif; 28 29 import org.objectweb.ccm.demo2.*; 30 31 38 39 public class Demo2 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 = 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 org.omg.CosTransactions.Current current = null; 68 if (_OTS.equals("yes")) 69 { 70 System.out.println("Obtaining the Transaction Service..."); 71 org.omg.CORBA.Object objOTS = orb.resolve_initial_references("TransactionCurrent"); 72 current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS ); 73 } 74 75 try 76 { 77 if ((current!=null)&&(_OTS.equals("yes"))) 78 { 79 System.out.println("Beginning the transaction..."); 80 current.begin(); 81 } 82 83 System.out.println("Obtaining Component Servers..."); 85 org.omg.CosNaming.NameComponent [] ncomp = new org.omg.CosNaming.NameComponent [1]; 86 ncomp[0] = new org.omg.CosNaming.NameComponent ("ComponentServer1", ""); 87 obj = nc.resolve(ncomp); 88 org.objectweb.openccm.Deployment.Server server1 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 89 ncomp[0].id = "ComponentServer2"; 90 obj = nc.resolve(ncomp); 91 org.objectweb.openccm.Deployment.Server server2 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 92 93 org.omg.Components.Deployment.ComponentServer server1_cs = server1.provide_component_server(); 95 org.omg.Components.Deployment.ComponentInstallation server1_inst = server1.provide_install(); 96 org.omg.Components.Deployment.ComponentServer server2_cs = server2.provide_component_server(); 97 org.omg.Components.Deployment.ComponentInstallation server2_inst = server2.provide_install(); 98 99 System.out.println("Installing archives..."); 101 String demoPath = null; 103 try { 104 demoPath = new java.io.File (".").getCanonicalPath()+ java.io.File.separator ; 105 }catch(Exception e) { 106 e.printStackTrace(); 107 } 108 109 server1_inst.install("demo2","file:"+ demoPath + "./archives/demo2.jar"); 110 server2_inst.install("demo2","file:"+ demoPath + "./archives/demo2.jar"); 111 112 server1_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 114 server2_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 115 116 String cont_config = 118 "container = CONTAINER.container ; " + 120 "JAVA.declare(\"org.objectweb.openccm.Containers\") ; " + 122 "PropertySet = org.objectweb.openccm.Containers.PropertySetImpl ;" + 123 "StringProperty = org.objectweb.openccm.Containers.StringPropertyImpl ;" + 124 "config_home = container.create_system_home("+ 126 "\"openccm_plugins\", " + 127 "\"EmptyConfig\", "+ 128 "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+ 129 "config = config_home.create_component(JAVA.null) ;" + 130 "container.create_system_home("+ 132 "\"openccm_plugins\", " + 133 "\"EmptyCoordinatorHome\", "+ 134 "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+ 135 "container.create_system_home("+ 137 "\"openccm_plugins\", " + 138 "\"EmptyControllerHome\", "+ 139 "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+ 140 "container.create_system_home("+ 142 "\"openccm_plugins\", " + 143 "\"Trace\", " + 144 "\"org.objectweb.openccm.Containers.Plugins.TraceControllerHome.create\") ; "+ 145 "container.create_system_home("+ 147 "\"openccm_plugins\", " + 148 "\"ListCoord\", " + 149 "\"org.objectweb.openccm.Containers.Plugins.ListCoordinatorHome.create\") ; "+ 150 "container.create_system_home("+ 152 "\"openccm_plugins\", " + 153 "\"PortConfig\", " + 154 "\"org.objectweb.openccm.Containers.Plugins.PortSpecificConfigurationHome.create\") ; " + 155 "container.set_container_configuration(config) ;"; 157 158 159 org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1]; 161 config[0] = new org.objectweb.openccm.Components.ConfigValueImpl(); 162 config[0].name = "container_script"; 163 org.omg.CORBA.TypeCode string_tc = 164 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string); 165 org.omg.CORBA.Any value = 166 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory(). 167 create_dyn_any_from_type_code(string_tc).to_any(); 168 value.insert_string(cont_config); 169 config[0].value = value; 170 171 org.omg.Components.Deployment.Container server1_cont = 172 server1_cs.create_container(config); 173 org.omg.Components.Deployment.Container server2_cont = 174 server2_cs.create_container(config); 175 176 177 System.out.println("Instantiating homes..."); 179 180 config[0].name = "home_script"; 182 String home_config = 183 "container.set_home_configuration(container.get_container_configuration()) ;" + 186 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 188 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo2/Producer:1.0\") ;" + 190 "config.setCallCoordinator(\"crop\", \"ListCoord\") ;" + 192 "config.setCallControllers(\"crop\", [ \"Trace\" ]) ;" + 194 "trace_config = PropertySet(\"trace\")" + 196 "trace_config.add(StringProperty(\"filename\", \"./trace_Producer.txt\"))" + 197 "config.setCallControllersConfig(\"crop\", [ trace_config ])" + 198 "config.set_parent_configuration(container.get_container_configuration()) ;" + 200 "container.set_component_configuration(config) ;"; 202 203 value.insert_string(home_config); 205 config[0].value = value; 206 207 org.omg.Components.CCMHome h = 208 server2_cont.install_home("demo2", 209 "org.objectweb.ccm.demo2.cif.ProducerHomeImpl.create_home", 210 config); 211 ProducerHome ph = ProducerHomeHelper.narrow(h); 212 213 home_config = 215 "container.set_home_configuration(container.get_container_configuration()) ;" + 218 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 220 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo2/Consumer:1.0\") ;" + 222 "config.setCallCoordinator(\"eat\", \"ListCoord\") ;" + 224 "config.setCallControllers(\"eat\", [ \"Trace\" ]) ;" + 226 "trace_config = PropertySet(\"trace\")" + 228 "trace_config.add(StringProperty(\"filename\", \"./trace_Consumers.txt\"))" + 229 "trace_config.add(StringProperty(\"singleton\", \"eat\"))" + 230 "config.setCallControllersConfig(\"eat\", [ trace_config ])" + 231 "config.set_parent_configuration(container.get_container_configuration()) ;" + 233 "container.set_component_configuration(config) ;"; 235 236 value.insert_string(home_config); 238 config[0].value = value; 239 240 h = server1_cont.install_home("demo2", 241 "org.objectweb.ccm.demo2.cif.ConsumerHomeImpl.create_home", 242 config); 243 ConsumerHome ch = ConsumerHomeHelper.narrow(h); 244 245 246 System.out.println("Instantiating components..."); 248 Consumer c1 = ch.create(); 249 Consumer c2 = ch.create(); 250 Consumer c3 = ch.create(); 251 Producer p = ph.create(); 252 253 System.out.println("Configuring components..."); 255 p.name("The Producer"); 256 c1.name("Christophe"); 257 c2.name("Sylvain"); 258 c3.name("Romain"); 259 260 System.out.println("Interconnecting components..."); 262 p.subscribe_crop(c1.get_consumer_eat()); 263 p.subscribe_crop(c2.get_consumer_eat()); 264 p.subscribe_crop(c3.get_consumer_eat()); 265 266 System.out.println("Configuration completion..."); 268 c1.configuration_complete(); 269 c2.configuration_complete(); 270 c3.configuration_complete(); 271 p.configuration_complete(); 272 273 } catch (Exception e) { 274 if ((current!=null)&&(_OTS.equals("yes"))) 275 { 276 System.out.println("Error during deployment :"); 277 e.printStackTrace(); 278 System.out.print("Rolling Back ... "); 279 current.rollback(); 280 System.out.println("Done"); 281 System.exit(0); 283 } 284 } 285 286 if ((current!=null)&&(_OTS.equals("yes"))) 287 { 288 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 289 290 java.io.BufferedReader _buffer 291 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 292 char _answer = (char) _buffer.read(); 293 294 if ((_answer=='n')||(_answer=='N')) 295 { 296 System.out.print("Rolling Back ... "); 297 current.rollback(); 298 System.out.println("Done"); 299 } else { 300 System.out.print("Committing ... "); 301 current.commit(false); 302 System.out.println("Done"); 303 } 304 } 305 306 System.exit(0); 308 } 309 } 310 311 | Popular Tags |