1 26 27 package org.objectweb.ccm.demo2.monolithic; 28 29 import org.objectweb.ccm.demo2.*; 30 31 37 38 public class Demo2 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 58 org.omg.CORBA.ORB orb = 60 org.objectweb.openccm.Components.Runtime.init(args); 61 62 System.out.println("Obtaining the Name Service..."); 64 org.omg.CORBA.Object obj = 65 orb.resolve_initial_references("NameService"); 66 org.omg.CosNaming.NamingContext nc = 67 org.omg.CosNaming.NamingContextHelper.narrow(obj); 68 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("Beginning the transaction..."); 82 current.begin(); 83 } 84 85 System.out.println("Obtaining Component Servers..."); 87 org.omg.CosNaming.NameComponent [] ncomp = new org.omg.CosNaming.NameComponent [1]; 88 ncomp[0] = new org.omg.CosNaming.NameComponent ("ComponentServer1", ""); 89 obj = nc.resolve(ncomp); 90 org.objectweb.openccm.Deployment.Server server1 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 91 ncomp[0].id = "ComponentServer2"; 92 obj = nc.resolve(ncomp); 93 org.objectweb.openccm.Deployment.Server server2 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 94 95 org.omg.Components.Deployment.ComponentServer server1_cs = server1.provide_component_server(); 97 org.omg.Components.Deployment.ComponentInstallation server1_inst = server1.provide_install(); 98 org.omg.Components.Deployment.ComponentServer server2_cs = server2.provide_component_server(); 99 org.omg.Components.Deployment.ComponentInstallation server2_inst = server2.provide_install(); 100 101 System.out.println("Installing archives..."); 103 String demoPath = null; 105 try { 106 demoPath = new java.io.File (".").getCanonicalPath()+ java.io.File.separator ; 107 }catch(Exception e) { 108 e.printStackTrace(); 109 } 110 111 server1_inst.install("demo2","file:"+ demoPath + "./archives/demo2.jar"); 112 server2_inst.install("demo2","file:"+ demoPath + "./archives/demo2.jar"); 113 114 server1_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 116 server2_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 117 118 String cont_config = 120 "container = CONTAINER.container ; " + 122 "JAVA.declare(\"org.objectweb.openccm.Containers\") ; " + 124 "PropertySet = org.objectweb.openccm.Containers.PropertySetImpl ;" + 125 "StringProperty = org.objectweb.openccm.Containers.StringPropertyImpl ;" + 126 "config_home = container.create_system_home("+ 128 "\"openccm_plugins\", " + 129 "\"EmptyConfig\", "+ 130 "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+ 131 "config = config_home.create_component(JAVA.null) ;" + 132 "container.create_system_home("+ 134 "\"openccm_plugins\", " + 135 "\"EmptyCoordinatorHome\", "+ 136 "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+ 137 "container.create_system_home("+ 139 "\"openccm_plugins\", " + 140 "\"EmptyControllerHome\", "+ 141 "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+ 142 "container.create_system_home("+ 144 "\"openccm_plugins\", " + 145 "\"Trace\", " + 146 "\"org.objectweb.openccm.Containers.Plugins.TraceControllerHome.create\") ; "+ 147 "container.create_system_home("+ 149 "\"openccm_plugins\", " + 150 "\"ListCoord\", " + 151 "\"org.objectweb.openccm.Containers.Plugins.ListCoordinatorHome.create\") ; "+ 152 "container.create_system_home("+ 154 "\"openccm_plugins\", " + 155 "\"PortConfig\", " + 156 "\"org.objectweb.openccm.Containers.Plugins.PortSpecificConfigurationHome.create\") ; " + 157 "container.set_container_configuration(config) ;"; 159 160 161 org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1]; 163 config[0] = new org.objectweb.openccm.Components.ConfigValueImpl(); 164 config[0].name = "container_script"; 165 org.omg.CORBA.TypeCode string_tc = 166 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string); 167 org.omg.CORBA.Any value = 168 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory(). 169 create_dyn_any_from_type_code(string_tc).to_any(); 170 value.insert_string(cont_config); 171 config[0].value = value; 172 173 org.omg.Components.Deployment.Container server1_cont = 174 server1_cs.create_container(config); 175 org.omg.Components.Deployment.Container server2_cont = 176 server2_cs.create_container(config); 177 178 179 System.out.println("Instantiating homes..."); 181 182 config[0].name = "home_script"; 184 String home_config = 185 "container.set_home_configuration(container.get_container_configuration()) ;" + 188 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 190 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo2/Producer:1.0\") ;" + 192 "config.setCallCoordinator(\"crop\", \"ListCoord\") ;" + 194 "config.setCallControllers(\"crop\", [ \"Trace\" ]) ;" + 196 "trace_config = PropertySet(\"trace\")" + 198 "trace_config.add(StringProperty(\"filename\", \"./trace_Producer.txt\"))" + 199 "config.setCallControllersConfig(\"crop\", [ trace_config ])" + 200 "config.set_parent_configuration(container.get_container_configuration()) ;" + 202 "container.set_component_configuration(config) ;"; 204 205 value.insert_string(home_config); 207 config[0].value = value; 208 209 org.omg.Components.CCMHome h = 210 server2_cont.install_home("demo2", 211 "org.objectweb.ccm.demo2.monolithic.ProducerHomeImpl.create_home", 212 config); 213 ProducerHome ph = ProducerHomeHelper.narrow(h); 214 215 home_config = 217 "container.set_home_configuration(container.get_container_configuration()) ;" + 220 "config = container.find_system_home(\"PortConfig\").create_component(JAVA.null) ;" + 222 "config.setComponentUId(\"IDL:ccm.objectweb.org/demo2/Consumer:1.0\") ;" + 224 "config.setCallCoordinator(\"eat\", \"ListCoord\") ;" + 226 "config.setCallControllers(\"eat\", [ \"Trace\" ]) ;" + 228 "trace_config = PropertySet(\"trace\")" + 230 "trace_config.add(StringProperty(\"filename\", \"./trace_Consumers.txt\"))" + 231 "trace_config.add(StringProperty(\"singleton\", \"eat\"))" + 232 "config.setCallControllersConfig(\"eat\", [ trace_config ])" + 233 "config.set_parent_configuration(container.get_container_configuration()) ;" + 235 "container.set_component_configuration(config) ;"; 237 238 value.insert_string(home_config); 240 config[0].value = value; 241 242 h = server1_cont.install_home("demo2", 243 "org.objectweb.ccm.demo2.monolithic.ConsumerHomeImpl.create_home", 244 config); 245 ConsumerHome ch = ConsumerHomeHelper.narrow(h); 246 247 248 System.out.println("Instantiating components..."); 250 Consumer c1 = ch.create(); 251 Consumer c2 = ch.create(); 252 Consumer c3 = ch.create(); 253 Producer p = ph.create(); 254 255 System.out.println("Configuring components..."); 257 p.name("The Producer"); 258 c1.name("Mathieu"); 259 c2.name("Raphael"); 260 c3.name("Philippe"); 261 262 System.out.println("Interconnecting components..."); 264 p.subscribe_crop(c1.get_consumer_eat()); 265 p.subscribe_crop(c2.get_consumer_eat()); 266 p.subscribe_crop(c3.get_consumer_eat()); 267 268 System.out.println("Configuration completion..."); 270 c1.configuration_complete(); 271 c2.configuration_complete(); 272 c3.configuration_complete(); 273 p.configuration_complete(); 274 275 } catch (Exception e) { 276 if ((current!=null)&&(_OTS.equals("yes"))) 277 { 278 System.out.println("Error during deployment :"); 279 e.printStackTrace(); 280 System.out.print("Rolling Back ... "); 281 current.rollback(); 282 System.out.println("Done"); 283 System.exit(0); 285 } 286 } 287 288 if ((current!=null)&&(_OTS.equals("yes"))) 289 { 290 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 291 292 java.io.BufferedReader _buffer 293 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 294 char _answer = (char) _buffer.read(); 295 296 if ((_answer=='n')||(_answer=='N')) 297 { 298 System.out.print("Rolling Back ... "); 299 current.rollback(); 300 System.out.println("Done"); 301 } else { 302 System.out.print("Committing ... "); 303 current.commit(false); 304 System.out.println("Done"); 305 } 306 } 307 308 System.exit(0); 310 } 311 } 312 313 | Popular Tags |