1 23 24 28 29 51 package com.sun.jts.CosTransactions; 52 53 import org.omg.CORBA.*; 54 import org.omg.PortableServer.*; 55 import org.omg.CosTransactions.*; 56 57 import org.omg.CosNaming.*; 58 import org.omg.CosNaming.NamingContextPackage.*; 59 60 import com.sun.jts.trace.*; 61 62 import java.util.logging.Logger ; 63 import java.util.logging.Level ; 64 import com.sun.logging.LogDomains; 65 import com.sun.jts.utils.LogFormatter; 66 67 78 79 86 class TransactionFactoryImpl extends TransactionFactoryPOA implements TransactionFactory { 87 88 private static POA poa = null; 89 private TransactionFactory thisRef = null; 90 91 static boolean active = true; 92 93 94 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 95 105 TransactionFactoryImpl() { 106 107 109 TimeoutManager.initialise(); 110 RecoveryManager.initialise(); 111 } 112 113 125 public Control create(int timeOut) throws SystemException { 126 127 Control result = null; 128 129 ControlImpl cimpl = localCreate(timeOut); 130 131 if (cimpl == null) { 132 return result; 133 } 134 135 if (Configuration.isLocalFactory()) { 136 result = (Control) cimpl; 137 } else { 138 result = cimpl.object(); 139 } 140 141 return result; 142 } 143 144 156 public ControlImpl localCreate(int timeOut) throws SystemException { 157 158 160 if (!active) { 161 NO_PERMISSION exc = 162 new NO_PERMISSION(0, CompletionStatus.COMPLETED_NO); 163 throw exc; 164 } 165 166 168 RecoveryManager.waitForResync(); 169 170 175 TopCoordinator coordinator = null; 176 TerminatorImpl terminator = null; 177 ControlImpl result = null; 178 179 try { 180 coordinator = new TopCoordinator(timeOut); 181 182 188 terminator = new TerminatorImpl(coordinator,false); 189 190 194 result = new ControlImpl(terminator, coordinator, 198 coordinator.getGlobalTid(), 199 new Long (coordinator.getLocalTID())); 200 if(_logger.isLoggable(Level.FINE)) 201 { 202 _logger.logp(Level.FINE,"TransactionFactoryImpl","localCreate()", 203 "Control object :" + result + 204 " corresponding to this transaction has been created"+ 205 "GTID is : "+ 206 ((TopCoordinator)coordinator).superInfo.globalTID.toString()); 207 } 208 209 } catch (Throwable exc) { 210 211 213 if (coordinator != null) { 214 coordinator.finalize(); 215 } 216 217 if (terminator != null) { 218 terminator.finalize(); 219 } 220 if (result != null) { 221 ((ControlImpl) result).finalize(); 222 } 223 224 result = null; 225 } 226 227 return result; 228 } 229 230 242 public Control recreate(PropagationContext context) 243 throws SystemException { 244 245 247 if (!active) { 248 NO_PERMISSION exc = 249 new NO_PERMISSION(0,CompletionStatus.COMPLETED_NO); 250 throw exc; 251 } 252 253 255 if (context.current == null || context.current.otid.formatID == -1) { 256 return null; 257 } 258 259 262 GlobalTID globalTID = new GlobalTID(context.current.otid); 263 CoordinatorImpl subordinate = 264 RecoveryManager.getCoordinator(globalTID); 265 Control result = null; 266 267 276 ProxyChecker checker = Configuration.getProxyChecker(); 277 if (subordinate == null && 278 !checker.isProxy(context.current.coord)) { 279 280 TRANSACTION_ROLLEDBACK exc = 281 new TRANSACTION_ROLLEDBACK(0, CompletionStatus.COMPLETED_NO); 282 throw exc; 283 } 284 285 288 if (subordinate == null) { 289 RecoveryManager.waitForResync(); 290 subordinate = RecoveryManager.getCoordinator(globalTID); 291 } 292 293 300 try { 301 302 if (subordinate == null) { 303 304 if (context.parents.length > 0) { 305 306 CoordinatorImpl[] newAncestors = 307 new CoordinatorImpl[context.parents.length]; 308 309 313 for (int i = context.parents.length - 1; i >= 0; i--) { 314 315 317 GlobalTID subGlobalTID = 318 new GlobalTID(context.parents[i].otid); 319 subordinate = 320 RecoveryManager.getCoordinator(subGlobalTID); 321 322 if (subordinate == null) { 323 324 if (i == context.parents.length - 1) { 325 326 331 subordinate = new TopCoordinator( 332 context.timeout, 333 subGlobalTID, 334 (Coordinator) context.parents[i]. 335 coord._duplicate(), 336 true); 337 338 } else { 339 340 345 CoordinatorImpl[] subAncestors = 346 new CoordinatorImpl[context.parents.length 347 - i - 1]; 348 System.arraycopy(newAncestors, i + 1, 349 subAncestors, 0, 350 context. 351 parents.length - i - 1); 352 353 subordinate = 354 new SubCoordinator( 355 subGlobalTID, 356 (Coordinator)context.parents[i]. 357 coord._duplicate(), 358 true, 359 subAncestors); 360 361 364 newAncestors[i+1].addChild(subordinate); 365 } 366 } 367 368 372 context.parents[i].coord._release(); 373 newAncestors[i] = subordinate; 374 } 375 376 381 subordinate = 382 new SubCoordinator(globalTID, 383 (Coordinator) context.current. 384 coord._duplicate(), 385 true, 386 newAncestors); 387 388 391 393 newAncestors[0].addChild(subordinate); 394 } else { 395 396 401 subordinate = new TopCoordinator( 402 context.timeout, 403 globalTID, 404 (Coordinator) context. 405 current.coord._duplicate(), 406 true); 407 } 408 409 412 } else { 413 414 subordinate.setPermanent(); 417 418 } 419 420 423 if (Configuration.isLocalFactory()) { 424 result = (Control) new ControlImpl(null, subordinate, globalTID, 425 new Long (subordinate.getLocalTID()) 426 ); 427 } else { 428 result = new ControlImpl(null, subordinate, globalTID, 429 new Long (subordinate.getLocalTID()) 430 ).object(); 431 } 432 433 } catch (Throwable exc) { 434 435 _logger.log(Level.SEVERE,"jts.unable_to_create_subordinate_coordinator"); 438 String msg = LogFormatter.getLocalizedMessage(_logger, 439 "jts.unable_to_create_subordinate_coordinator"); 440 throw new org.omg.CORBA.INTERNAL (msg); 441 } 442 443 return result; 444 } 445 446 456 public Control recreate(GlobalTID tid, int timeout) 457 throws SystemException { 458 459 if (!active) { 461 NO_PERMISSION exc = 462 new NO_PERMISSION(0, CompletionStatus.COMPLETED_NO); 463 throw exc; 464 } 465 466 CoordinatorImpl subordinate = RecoveryManager.getCoordinator(tid); 469 Control result = null; 470 471 if (subordinate == null) { 474 RecoveryManager.waitForResync(); 475 subordinate = RecoveryManager.getCoordinator(tid); 476 } 477 478 485 try { 486 if (subordinate == null) { 487 subordinate = new TopCoordinator( 492 timeout, tid, new TxInflowCoordinator(), 493 true); 494 } else { 495 Status status = subordinate.get_status(); 496 if ((status != Status.StatusMarkedRollback) && 497 (status != Status.StatusActive)) { 498 throw new INVALID_TRANSACTION("tx completion in-progress"); 499 } 500 subordinate.setPermanent(); 503 } 504 505 if (Configuration.isLocalFactory()) { 508 result = (Control) new ControlImpl(null, subordinate, tid, 509 new Long (subordinate.getLocalTID()) 510 ); 511 } else { 512 result = new ControlImpl(null, subordinate, tid, 513 new Long (subordinate.getLocalTID()) 514 ).object(); 515 } 516 } catch (Throwable exc) { 517 _logger.log(Level.WARNING,"jts.unable_to_create_subordinate_coordinator"); 520 String msg = LogFormatter.getLocalizedMessage(_logger, 521 "jts.unable_to_create_subordinate_coordinator"); 522 INTERNAL intExc = new INTERNAL(msg); 524 intExc.initCause(exc); 526 throw intExc; 527 } 528 529 return result; 530 } 531 532 541 static void deactivate() { 542 543 active = false; 544 545 547 TimeoutManager.shutdown(false); 548 RecoveryManager.shutdown(false); 549 DelegatedRecoveryManager.shutdown(false); 550 } 551 552 560 synchronized TransactionFactory object() { 561 if (thisRef == null) { 562 if (poa == null) { 563 poa = Configuration.getPOA("transient"); 564 } 565 566 try { 567 poa.activate_object(this); 568 thisRef = TransactionFactoryHelper. 569 narrow(poa.servant_to_reference(this)); 570 572 576 577 NamingContext namingContext = null; 578 try { 579 namingContext = NamingContextHelper.narrow( 580 Configuration.getORB().resolve_initial_references("NameService")); 581 } catch (Exception exc) { 582 _logger.log(Level.WARNING,"jts.orb_not_running"); 583 } 584 585 try { 586 NameComponent nc = new NameComponent(TransactionFactoryHelper.id(), ""); 587 NameComponent path[] = { nc }; 588 namingContext.rebind(path, thisRef); 589 } catch (Exception exc) { 590 _logger.log(Level.WARNING,"jts.cannot_register_with_orb", 591 "TransactionFactory"); 592 } 593 } catch (Exception exc) { 594 _logger.log(Level.SEVERE,"jts.create_transactionfactory_object_error"); 595 String msg = LogFormatter.getLocalizedMessage(_logger, 596 "jts.create_transactionfactory_object_error"); 597 throw new org.omg.CORBA.INTERNAL (msg); 598 } 599 } 600 601 return thisRef; 602 } 603 604 612 synchronized static final TransactionFactoryImpl servant(TransactionFactory factory) { 613 TransactionFactoryImpl result = null; 614 615 if (factory != null && Configuration.getProxyChecker().isProxy(factory)) { 619 return result; 620 } 621 622 if (factory instanceof TransactionFactoryImpl ) { 623 result = (TransactionFactoryImpl) factory; 624 } else if (poa != null) { 625 try { 626 result = (TransactionFactoryImpl) poa.reference_to_servant(factory); 627 if( result.thisRef == null ) 628 result.thisRef = factory; 629 } catch( Exception exc ) { 630 _logger.log(Level.WARNING,"jts.cannot_locate_servant", 631 "TransactionFactory"); 632 } 633 } 634 635 return result; 636 } 637 638 643 644 public org.omg.CORBA.Object _duplicate() { 645 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 646 } 647 648 public void _release() { 649 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 650 } 651 652 public boolean _is_a(String repository_id) { 653 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 654 } 655 656 public boolean _is_equivalent(org.omg.CORBA.Object that) { 657 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 658 } 659 660 public boolean _non_existent() { 661 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 662 } 663 664 public int _hash(int maximum) { 665 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 666 } 667 668 public Request _request(String operation) { 669 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 670 } 671 672 public Request _create_request(Context ctx, 673 String operation, 674 NVList arg_list, 675 NamedValue result) { 676 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 677 } 678 679 public Request _create_request(Context ctx, 680 String operation, 681 NVList arg_list, 682 NamedValue result, 683 ExceptionList exceptions, 684 ContextList contexts) { 685 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 686 } 687 688 public org.omg.CORBA.Object _get_interface_def() { 689 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 690 } 691 692 public org.omg.CORBA.Policy _get_policy(int policy_type) { 693 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 694 } 695 696 public org.omg.CORBA.DomainManager [] _get_domain_managers() { 697 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 698 } 699 700 public org.omg.CORBA.Object _set_policy_override( 701 org.omg.CORBA.Policy [] policies, 702 org.omg.CORBA.SetOverrideType set_add) { 703 throw new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 704 } 705 } 706 | Popular Tags |