1 26 27 package org.coach.reactorDemo; 28 29 30 36 37 public class reactorDemo 38 { 39 42 public static void 43 main(String [] args) 44 throws Exception 45 { 46 String _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase(); 47 48 System.out.println("Initializing the ORB..."); 50 51 56 org.omg.CORBA.ORB orb = org.objectweb.openccm.Components.Runtime.init(args); 58 59 System.out.println("Obtaining the Name Service..."); 61 org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService"); 62 org.omg.CosNaming.NamingContext nc = org.omg.CosNaming.NamingContextHelper.narrow(obj); 63 64 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("Status = "+current.get_status()); 82 System.out.println("Beginning the transaction..."); 83 current.begin(); 84 } 85 86 System.out.println("Obtaining Component Servers..."); 88 org.omg.CosNaming.NameComponent [] ncomp = new org.omg.CosNaming.NameComponent [1]; 89 ncomp[0] = new org.omg.CosNaming.NameComponent ("ComponentServer1", ""); 90 obj = nc.resolve(ncomp); 91 org.objectweb.openccm.Deployment.Server server1 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 92 ncomp[0].id = "ComponentServer2"; 93 obj = nc.resolve(ncomp); 94 org.objectweb.openccm.Deployment.Server server2 = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 95 96 org.omg.Components.Deployment.ComponentServer server1_cs = server1.provide_component_server(); 98 org.omg.Components.Deployment.ComponentInstallation server1_inst = server1.provide_install(); 99 org.omg.Components.Deployment.ComponentServer server2_cs = server2.provide_component_server(); 100 org.omg.Components.Deployment.ComponentInstallation server2_inst = server2.provide_install(); 101 102 System.out.println("Installing archives..."); 104 String demoPath = null; 106 try { 107 demoPath = new java.io.File (".").getCanonicalPath()+ java.io.File.separator ; 108 }catch(Exception e) { 109 e.printStackTrace(); 110 } 111 112 server1_inst.install("reactorDemo", "file:" + demoPath + "./archives/reactorDemo.jar"); 113 server2_inst.install("reactorDemo", "file:" + demoPath + "./archives/reactorDemo.jar"); 114 115 server1_inst.install("openccm_plugins", "file:" + demoPath + "./archives/OpenCCM_Plugins.jar"); 117 server2_inst.install("openccm_plugins", "file:" + demoPath + "./archives/OpenCCM_Plugins.jar"); 118 119 String cont_config = 126 "container = CONTAINER.container ; " + 127 "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("+ 133 "\"openccm_plugins\", " + 134 "\"EmptyCoordinatorHome\", "+ 135 "\"org.objectweb.openccm.Containers.Plugins.EmptyCoordinatorHome.create\") ;"+ 136 "container.create_system_home("+ 137 "\"openccm_plugins\", " + 138 "\"EmptyControllerHome\", "+ 139 "\"org.objectweb.openccm.Containers.Plugins.EmptyControllerHome.create\") ;"+ 140 "container.set_container_configuration(config) ;"; 141 142 org.omg.Components.Deployment.Container server1_cont = server1_cs.create_container(new org.omg.Components.ConfigValue[0]); 143 org.omg.Components.Deployment.Container server2_cont = server2_cs.create_container(new org.omg.Components.ConfigValue[0]); 144 145 System.out.println("Instantiating homes..."); 147 148 java.lang.String home_config = 149 "container.set_home_configuration(container.get_container_configuration()) ;" + 150 "container.set_component_configuration(container.get_container_configuration()) ;"; 151 152 org.omg.Components.CCMHome h2 = server1_cont.install_home("reactorDemo", "org.coach.reactorDemo.TweeHomeComponentImpl.create_home", new org.omg.Components.ConfigValue[0]); 153 TweeHome sh = TweeHomeHelper.narrow(h2); 154 155 org.omg.Components.CCMHome h1 = server2_cont.install_home("reactorDemo", "org.coach.reactorDemo.EenHomeComponentImpl.create_home", new org.omg.Components.ConfigValue[0]); 156 EenHome ch = EenHomeHelper.narrow(h1); 157 158 System.out.println("Instantiating components"); 160 Twee s1 = sh.create(); 161 Twee s2 = sh.create(); 162 Een c1 = ch.create(); 163 Een c2 = ch.create(); 164 Een c3 = ch.create(); 165 System.out.println("Configuring components..."); 167 s1.the_name("De Ene Twee Server"); 168 s2.the_name("De Andere Twee Server"); 169 c1.the_name("Een 1"); 170 c2.the_name("Een 2"); 171 c3.the_name("Een 3"); 172 173 System.out.println("Interconnecting components..."); 175 i_Aap aapRef1 = s1.provide_ditIsAap(); 176 i_Aap aapRef2 = s2.provide_ditIsAap(); 177 c1.connect_gebruiktAap(aapRef1); 178 c2.connect_gebruiktAap(aapRef1); 179 c3.connect_gebruiktAap(aapRef2); 180 181 System.out.println("Configuration completion..."); 183 s1.configuration_complete(); 184 s2.configuration_complete(); 185 c1.configuration_complete(); 186 c2.configuration_complete(); 187 c3.configuration_complete(); 188 189 System.out.println("Trying to get to the reactor..."); 190 myEnumUnionHolder eenEnum=new myEnumUnionHolder(); 191 myEnumUnion aapje=new myEnumUnion(); 192 aapje.Dummy((short)10); 193 eenEnum.value = aapje; 194 195 for (int k=1; k<2; k++) 196 try { 197 short aval = eenEnum.value.Dummy(); 198 System.out.println("before reactor eenEnum="+ aval + "server name is: " + s2.the_name()); 199 aapRef1.method3("een string", eenEnum, "een andere string"); 200 short val = eenEnum.value.Dummy(); 201 System.out.println("eenEnum na reactor=" + val); 202 } catch (Exception e) { 203 System.out.println("Error......"); 204 e.printStackTrace(); 206 }; 207 208 } catch (Exception e) { 209 if ((current!=null)&&(_OTS.equals("yes"))) 210 { 211 System.out.println("Error during Deployment :"); 212 e.printStackTrace(); 213 System.out.print("Rolling Back ... "); 214 current.rollback(); 215 System.out.println("Done"); 216 System.exit(0); 218 } else { 219 System.out.println("Error during Deployment :"); 220 e.printStackTrace(); 221 } 222 } 223 224 if ((current!=null)&&(_OTS.equals("yes"))) 225 { 226 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 227 228 java.io.BufferedReader _buffer 229 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 230 char _answer = (char) _buffer.read(); 231 232 if ((_answer=='n')||(_answer=='N')) 233 { 234 System.out.print("Rolling Back ... "); 235 current.rollback(); 236 System.out.println("Done"); 237 } else { 238 System.out.print("Committing ... "); 239 current.commit(false); 240 System.out.println("Done"); 241 } 242 } 243 244 System.exit(0); 246 } 247 } 248 249 250 251 252 253 254 255 | Popular Tags |