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