1 26 27 package DiningPhilosophers.monolithic; 28 29 import DiningPhilosophers.*; 30 31 50 51 public class Dinner 52 { 53 56 public static void 57 main(String [] args) 58 throws Exception 59 { 60 String _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase(); 61 62 System.out.println("Initializing the ORB..."); 64 65 71 org.omg.CORBA.ORB orb = 73 org.objectweb.openccm.Components.Runtime.init(args); 74 75 System.out.println("Obtaining the Name Service..."); 77 org.omg.CORBA.Object obj = 78 orb.resolve_initial_references("NameService"); 79 org.omg.CosNaming.NamingContext nc = 80 org.omg.CosNaming.NamingContextHelper.narrow(obj); 81 82 org.omg.CosTransactions.Current current = null; 83 if (_OTS.equals("yes")) 84 { 85 System.out.println("Obtaining the Transaction Service..."); 86 org.omg.CORBA.Object objOTS = orb.resolve_initial_references("TransactionCurrent"); 87 current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS ); 88 } 89 90 try 91 { 92 if ((current!=null)&&(_OTS.equals("yes"))) 93 { 94 System.out.println("Beginning the transaction..."); 95 current.begin(); 96 } 97 98 System.out.println("Obtaining Component Servers..."); 100 org.omg.CosNaming.NameComponent [] ncomp = 101 new org.omg.CosNaming.NameComponent [1]; 102 ncomp[0] = new org.omg.CosNaming.NameComponent ("ComponentServer1", ""); 103 obj = nc.resolve(ncomp); 104 org.objectweb.openccm.Deployment.Server server1 = 105 org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 106 ncomp[0].id = "ComponentServer2"; 107 obj = nc.resolve(ncomp); 108 org.objectweb.openccm.Deployment.Server server2 = 109 org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 110 111 org.omg.Components.Deployment.ComponentServer server1_cs = 113 server1.provide_component_server(); 114 org.omg.Components.Deployment.ComponentInstallation server1_inst = 115 server1.provide_install(); 116 org.omg.Components.Deployment.ComponentServer server2_cs = 117 server2.provide_component_server(); 118 org.omg.Components.Deployment.ComponentInstallation server2_inst = 119 server2.provide_install(); 120 121 System.out.println("Installing archives..."); 123 String demoPath = null; 125 try { 126 demoPath = new java.io.File (".").getCanonicalPath()+ java.io.File.separator ; 127 }catch(Exception e) { 128 e.printStackTrace(); 129 } 130 131 server1_inst.install("dinner","file:"+ demoPath + "./archives/DiningPhilosophers.jar"); 132 server2_inst.install("dinner","file:"+ demoPath + "./archives/DiningPhilosophers.jar"); 133 134 server1_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 136 server2_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 137 138 String cont_config = 140 "container = CONTAINER.container ; " + 141 "config_home = container.create_system_home("+ 142 "\"openccm_plugins\", " + 143 "\"EmptyConfig\", "+ 144 "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+ 145 "config = config_home.create_component(JAVA.null) ;" + 146 "container.create_system_home("+ 147 "\"openccm_plugins\", " + 148 "\"EmptyCoordinatorHome\", "+ 149 "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+ 150 "container.create_system_home("+ 151 "\"openccm_plugins\", " + 152 "\"EmptyControllerHome\", "+ 153 "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+ 154 "container.set_container_configuration(config) ;"; 155 156 org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1]; 158 config[0] = new org.objectweb.openccm.Components.ConfigValueImpl(); 159 config[0].name = "container_script"; 160 org.omg.CORBA.TypeCode string_tc = 161 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string); 162 org.omg.CORBA.Any value = 163 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory(). 164 create_dyn_any_from_type_code(string_tc).to_any(); 165 value.insert_string(cont_config); 166 config[0].value = value; 167 168 169 org.omg.Components.Deployment.Container server1_cont = 170 server1_cs.create_container(config); 171 org.omg.Components.Deployment.Container server2_cont = 172 server2_cs.create_container(config); 173 174 System.out.println("Instantiating homes..."); 176 177 java.lang.String home_config = 179 "container.set_home_configuration(container.get_container_configuration()) ;" + 180 "container.set_component_configuration(container.get_container_configuration()) ;"; 181 182 config[0].name = "home_script"; 183 value.insert_string(home_config); 184 config[0].value = value; 185 186 org.omg.Components.CCMHome h = 188 server1_cont.install_home("dinner", 189 "DiningPhilosophers.monolithic.PhilosopherHomeImpl.create_home", 190 config); 191 PhilosopherHome ph = PhilosopherHomeHelper.narrow(h); 192 193 h = server2_cont.install_home("dinner", 194 "DiningPhilosophers.monolithic.ForkHomeImpl.create_home", 195 config); 196 ForkHome fh = ForkHomeHelper.narrow(h); 197 h = server2_cont.install_home("dinner", 198 "DiningPhilosophers.monolithic.ObserverHomeImpl.create_home", 199 config); 200 ObserverHome oh = ObserverHomeHelper.narrow(h); 201 202 System.out.println("Creating components..."); 204 Philosopher p1 = ph._new("Mathieu"); 205 Philosopher p2 = ph._new("Raphael"); 206 Philosopher p3 = ph._new("Philippe"); 207 Philosopher p4 = ph._new("Sylvain"); 208 ForkManager f1 = fh.create(); 209 ForkManager f2 = fh.create(); 210 ForkManager f3 = fh.create(); 211 ForkManager f4 = fh.create(); 212 Observer o = oh.create(); 213 214 System.out.println("Configuring components..."); 216 217 System.out.println("Interconnecting components..."); 219 220 Fork fork = f1.provide_the_fork(); 221 p1.connect_right(fork); 222 p2.connect_left(fork); 223 224 fork = f2.provide_the_fork(); 225 p2.connect_right(fork); 226 p3.connect_left(fork); 227 228 fork = f3.provide_the_fork(); 229 p3.connect_right(fork); 230 p4.connect_left(fork); 231 232 fork = f4.provide_the_fork(); 233 p4.connect_right(fork); 234 p1.connect_left(fork); 235 236 StatusInfoConsumer consumer = o.get_consumer_info(); 237 p1.subscribe_info(consumer); 238 p2.subscribe_info(consumer); 239 p3.subscribe_info(consumer); 240 p4.subscribe_info(consumer); 241 242 System.out.println("Configuration completion..."); 244 f1.configuration_complete(); 245 f2.configuration_complete(); 246 f3.configuration_complete(); 247 f4.configuration_complete(); 248 o.configuration_complete(); 249 p1.configuration_complete(); 250 p2.configuration_complete(); 251 p3.configuration_complete(); 252 p4.configuration_complete(); 253 254 } catch (Exception e) { 255 if ((current!=null)&&(_OTS.equals("yes"))) 256 { 257 System.out.println("Error during deployment :"); 258 e.printStackTrace(); 259 System.out.print("Rolling Back ... "); 260 current.rollback(); 261 System.out.println("Done"); 262 System.exit(0); 264 } 265 } 266 267 if ((current!=null)&&(_OTS.equals("yes"))) 268 { 269 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 270 271 java.io.BufferedReader _buffer 272 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 273 char _answer = (char) _buffer.read(); 274 275 if ((_answer=='n')||(_answer=='N')) 276 { 277 System.out.print("Rolling Back ... "); 278 current.rollback(); 279 System.out.println("Done"); 280 } else { 281 System.out.print("Committing ... "); 282 current.commit(false); 283 System.out.println("Done"); 284 } 285 } 286 287 System.exit(0); 288 } 289 } 290 | Popular Tags |