1 26 27 package DiningPhilosophers.monolithic; 28 29 import DiningPhilosophers.*; 30 31 50 51 public class Deployment_PDA 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 ns = 80 org.omg.CosNaming.NamingContextHelper.narrow(obj); 81 obj = orb.resolve_initial_references("CommonNameService"); 82 org.omg.CosNaming.NamingContext cns = 83 org.omg.CosNaming.NamingContextHelper.narrow(obj); 84 85 org.omg.CosTransactions.Current current = null; 86 if (_OTS.equals("yes")) 87 { 88 System.out.println("Obtaining the Transaction Service..."); 89 org.omg.CORBA.Object objOTS = orb.resolve_initial_references("TransactionCurrent"); 90 current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS ); 91 } 92 93 try 94 { 95 if ((current!=null)&&(_OTS.equals("yes"))) 96 { 97 System.out.println("Beginning the transaction..."); 98 current.begin(); 99 } 100 101 System.out.println("Obtaining Component Servers..."); 103 String cs1_name = System.getProperty("org.objectweb.ccm.DiningPhilosophers.CS1"); 104 String cs2_name = System.getProperty("org.objectweb.ccm.DiningPhilosophers.CS2"); 105 106 org.omg.CosNaming.NameComponent [] ncomp = 107 new org.omg.CosNaming.NameComponent [1]; 108 ncomp[0] = new org.omg.CosNaming.NameComponent (cs1_name, ""); 109 obj = ns.resolve(ncomp); 110 org.objectweb.openccm.Deployment.Server server1 = 111 org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 112 ncomp[0].id = cs2_name; 113 obj = ns.resolve(ncomp); 114 org.objectweb.openccm.Deployment.Server server2 = 115 org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 116 117 org.omg.Components.Deployment.ComponentServer server1_cs = 119 server1.provide_component_server(); 120 org.omg.Components.Deployment.ComponentInstallation server1_inst = 121 server1.provide_install(); 122 org.omg.Components.Deployment.ComponentServer server2_cs = 123 server2.provide_component_server(); 124 org.omg.Components.Deployment.ComponentInstallation server2_inst = 125 server2.provide_install(); 126 127 System.out.println("Installing archives..."); 129 String http_server = System.getProperty("org.objectweb.ccm.DiningPhilosophers.http"); 130 server1_inst.install("dinner", http_server + "DiningPhilosophers.jar"); 131 server2_inst.install("dinner", http_server + "DiningPhilosophers.jar"); 132 server1_inst.install("openccm_plugins", http_server + "DiningPhilosophers.jar"); 134 server2_inst.install("openccm_plugins", http_server + "DiningPhilosophers.jar"); 135 136 String cont_config = 138 "container = CONTAINER.container ; " + 139 "config_home = container.create_system_home("+ 140 "\"openccm_plugins\", " + 141 "\"EmptyConfig\", "+ 142 "\"org.objectweb.openccm.Containers.Plugins.EmptyConfigurationHome.create\") ;"+ 143 "config = config_home.create_component(JAVA.null) ;" + 144 "container.create_system_home("+ 145 "\"openccm_plugins\", " + 146 "\"EmptyCoordinatorHome\", "+ 147 "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+ 148 "container.create_system_home("+ 149 "\"openccm_plugins\", " + 150 "\"EmptyControllerHome\", "+ 151 "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+ 152 "container.set_container_configuration(config) ;"; 153 154 org.omg.Components.ConfigValue[] config = new org.omg.Components.ConfigValue[1]; 156 config[0] = new org.objectweb.openccm.Components.ConfigValueImpl(); 157 config[0].name = "container_script"; 158 org.omg.CORBA.TypeCode string_tc = 159 org.objectweb.openccm.corba.TheORB.getORB().get_primitive_tc(org.omg.CORBA.TCKind.tk_string); 160 org.omg.CORBA.Any value = 161 org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory(). 162 create_dyn_any_from_type_code(string_tc).to_any(); 163 value.insert_string(cont_config); 164 config[0].value = value; 165 166 167 org.omg.Components.Deployment.Container server1_cont = 168 server1_cs.create_container(config); 169 org.omg.Components.Deployment.Container server2_cont = 170 server2_cs.create_container(config); 171 172 System.out.println("Instantiating homes..."); 174 175 java.lang.String home_config = 177 "container.set_home_configuration(container.get_container_configuration()) ;" + 178 "container.set_component_configuration(container.get_container_configuration()) ;"; 179 180 config[0].name = "home_script"; 181 value.insert_string(home_config); 182 config[0].value = value; 183 184 186 org.omg.Components.CCMHome h = 188 server1_cont.install_home("dinner", 189 "DiningPhilosophers.monolithic.ObserverHomePdaImpl.create_home", 190 config); 191 ObserverHome oh_pda = ObserverHomeHelper.narrow(h); 192 h = server1_cont.install_home("dinner", 193 "DiningPhilosophers.monolithic.PhilosopherHomePdaImpl.create_home", 194 config); 195 PhilosopherHome ph_pda = PhilosopherHomeHelper.narrow(h); 196 197 h = server2_cont.install_home("dinner", 199 "DiningPhilosophers.monolithic.ObserverHomeImpl.create_home", 200 config); 201 ObserverHome oh = ObserverHomeHelper.narrow(h); 202 203 h = server2_cont.install_home("dinner", 204 "DiningPhilosophers.monolithic.PhilosopherHomeImpl.create_home", 205 config); 206 PhilosopherHome ph = PhilosopherHomeHelper.narrow(h); 207 208 h = server2_cont.install_home("dinner", 209 "DiningPhilosophers.monolithic.ForkHomeImpl.create_home", 210 config); 211 ForkHome fh = ForkHomeHelper.narrow(h); 212 213 215 org.omg.CosNaming.NameComponent [] nc = 217 new org.omg.CosNaming.NameComponent [1]; 218 nc[0] = new org.omg.CosNaming.NameComponent (); 219 nc[0].id = "OpenCCM_PDA"; 220 nc[0].kind = ""; 221 222 try { 223 ns = cns.bind_new_context(nc); 224 } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) { 225 ns = org.omg.CosNaming.NamingContextHelper.narrow(cns.resolve(nc)); 226 } 227 228 nc[0].id = "ObserverHomePC"; 229 ns.rebind(nc, oh); 230 231 nc[0].id = "PhilosopherHome"; 232 ns.rebind(nc, ph); 233 234 nc[0].id = "ForkHome"; 235 ns.rebind(nc, fh); 236 237 nc[0].id = "ObserverHome"; 238 ns.rebind(nc, oh_pda); 239 240 nc[0].id = "PhilosopherHomePDA"; 241 ns.rebind(nc, ph_pda); 242 243 } catch (Exception e) { 244 if ((current!=null)&&(_OTS.equals("yes"))) 245 { 246 System.out.println("Error during deployment :"); 247 e.printStackTrace(); 248 System.out.print("Rolling Back ... "); 249 current.rollback(); 250 System.out.println("Done"); 251 System.exit(0); 253 } 254 throw e; 255 } 256 257 if ((current!=null)&&(_OTS.equals("yes"))) 258 { 259 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 260 261 java.io.BufferedReader _buffer 262 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 263 char _answer = (char) _buffer.read(); 264 265 if ((_answer=='n')||(_answer=='N')) 266 { 267 System.out.print("Rolling Back ... "); 268 current.rollback(); 269 System.out.println("Done"); 270 } else { 271 System.out.print("Committing ... "); 272 current.commit(false); 273 System.out.println("Done"); 274 } 275 } 276 277 System.exit(0); 279 } 280 } 281 | Popular Tags |