1 26 27 package org.objectweb.openccm.plugins.transaction.deployment; 28 29 import org.objectweb.openccm.plugins.transaction.deployment.util.*; 30 import org.omg.CosTransactions.Coordinator ; 31 32 40 public class ResourceManagerImpl 41 extends ResourceManagerPOA 42 implements ResourceManagerLocal 43 { 44 52 protected static int resources_count_=3; 53 54 61 protected ResourceVector[] resources_; 62 63 66 protected TransactionManagerLocal OTSManager_; 67 68 71 protected Coordinator coordinator_; 72 73 84 public 85 ResourceManagerImpl (Coordinator coordinator, 86 TransactionManagerLocal manager) 87 { 88 coordinator_ = coordinator; 89 OTSManager_ = manager; 90 resources_ = new ResourceVector[resources_count_]; 91 for (int i=0 ; i < resources_count_ ; i++) 92 resources_[i] = new ResourceVector(); 93 } 94 95 106 protected void 107 apply(ResourceTreatment action) 108 throws Exception 109 { 110 for (int i=1 ; i<=resources_count_ ; i++) 111 resources_[resources_count_-i].apply(action); 112 } 113 114 120 protected void 121 reverse_apply(ResourceTreatment action) 122 throws Exception 123 { 124 for (int i=0 ; i < resources_count_ ; i++) 125 resources_[i].apply(action); 126 } 127 128 132 protected void 133 removeItself() 134 { 135 try { 136 OTSManager_.remove_manager (this); 137 } catch ( org.omg.Components.RemoveFailure ex ){ } 138 try { 139 _poa().deactivate_object( _poa().servant_to_id( this ) ); 140 } catch ( org.omg.PortableServer.POAPackage.ObjectNotActive ex ){ 141 } catch ( org.omg.PortableServer.POAPackage.WrongPolicy ex ) { 142 } catch ( org.omg.PortableServer.POAPackage.ServantNotActive ex ) { 143 } 144 } 145 146 152 166 public void 167 add_component_server (ComponentServerResource ref) 168 { 169 resources_[2].addElement (ref); 170 } 171 172 181 public void 182 add_container (ContainerResource ref) 183 { 184 resources_[1].addElement (ref); 185 } 186 187 196 public void 197 add_home (CCMHomeResource ref) 198 { 199 resources_[0].addElement (ref); 200 } 201 202 211 public void 212 remove_component_server(ComponentServerResource ref) 213 throws org.omg.Components.RemoveFailure 214 { 215 resources_[2].removeElement (ref); 216 } 217 218 227 public void 228 remove_container (ContainerResource ref) 229 throws org.omg.Components.RemoveFailure 230 { 231 resources_[1].removeElement (ref); 232 } 233 234 243 public void 244 remove_home (CCMHomeResource ref) 245 throws org.omg.Components.RemoveFailure 246 { 247 resources_[0].removeElement (ref); 248 } 249 250 263 public org.omg.CosTransactions.Vote 264 prepare() 265 throws org.omg.CosTransactions.HeuristicMixed, 266 org.omg.CosTransactions.HeuristicHazard 267 { 268 try { 269 ResourcePrepare _vote = new ResourcePrepare(); 270 apply(_vote); 271 return _vote.final_vote(); 272 } catch (Exception ex) { 273 return org.omg.CosTransactions.Vote.VoteRollback; 274 } 275 } 276 277 284 public void 285 rollback() 286 throws org.omg.CosTransactions.HeuristicCommit, 287 org.omg.CosTransactions.HeuristicMixed, 288 org.omg.CosTransactions.HeuristicHazard 289 { 290 try 291 { 292 reverse_apply(new ResourceRollback()); 293 } catch (org.omg.CosTransactions.HeuristicCommit ex) { 294 throw ex; 295 } catch (org.omg.CosTransactions.HeuristicMixed ex) { 296 throw ex; 297 } catch (org.omg.CosTransactions.HeuristicHazard ex) { 298 throw ex; 299 } catch (Exception ex) { } 300 removeItself(); 301 } 302 303 310 public void 311 commit() 312 throws org.omg.CosTransactions.NotPrepared, 313 org.omg.CosTransactions.HeuristicRollback, 314 org.omg.CosTransactions.HeuristicMixed, 315 org.omg.CosTransactions.HeuristicHazard 316 { 317 try { 318 apply(new ResourceCommit()); 319 } catch (org.omg.CosTransactions.NotPrepared ex) { 320 throw ex; 321 } catch (org.omg.CosTransactions.HeuristicRollback ex) { 322 throw ex; 323 } catch (org.omg.CosTransactions.HeuristicMixed ex) { 324 throw ex; 325 } catch (org.omg.CosTransactions.HeuristicHazard ex) { 326 throw ex; 327 } catch (Exception ex) { } 328 removeItself(); 329 } 330 331 338 public void 339 commit_one_phase() 340 throws org.omg.CosTransactions.HeuristicHazard 341 { 342 try { 343 apply(new ResourceCommitOnePhase()); 344 } catch(org.omg.CosTransactions.HeuristicHazard ex) { 345 throw ex; 346 } catch (Exception ex) { } 347 removeItself(); 348 } 349 350 357 public void 358 forget() 359 { 360 removeItself(); 361 } 362 363 379 public Coordinator 380 coordinator() 381 { 382 return coordinator_; 383 } 384 } 385 386 | Popular Tags |