1 23 24 28 50 package com.sun.jts.CosTransactions; 51 52 54 import java.util.*; 55 56 import org.omg.CORBA.*; 57 import org.omg.PortableServer.*; 58 import org.omg.CosTransactions.*; 59 import org.omg.PortableServer.POAPackage.ServantNotActive ; 60 import org.omg.PortableServer.POAPackage.ServantAlreadyActive ; 61 62 import com.sun.jts.otsidl.*; 63 import java.util.logging.Logger ; 64 import java.util.logging.Level ; 65 import com.sun.logging.LogDomains; 66 import com.sun.jts.utils.LogFormatter; 67 79 86 public class ControlImpl extends JControlPOA implements Control { 87 88 private static POA poa = null; 89 private Control thisRef = null; 90 91 protected boolean temporary = false; 92 protected boolean inSuspended = false; 93 protected Status tranState = Status.StatusActive; 94 protected CoordinatorImpl coord = null; 95 protected Coordinator coordRef = null; 96 protected TerminatorImpl term = null; 97 protected Terminator termRef = null; 98 protected ControlImpl stacked = null; 99 protected GlobalTID globalTID = null; 100 protected Long localTID = null; 101 protected boolean representsRemote = false; 102 protected PropagationContext cachedContext = null; 103 104 106 protected int outgoing = 0; 107 protected int association = 0; 108 109 112 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 113 114 122 ControlImpl() { 123 124 tranState = Status.StatusActive; 125 126 inSuspended = true; 129 CurrentTransaction.addSuspended(this); 130 131 } 132 133 145 ControlImpl( TerminatorImpl term, 146 CoordinatorImpl coord, 147 GlobalTID globalTID, 148 Long localTID ) { 149 150 151 153 this.term = term; 154 this.coord = coord; 155 this.globalTID = globalTID; 156 this.localTID = localTID; 157 tranState = Status.StatusActive; 158 159 161 inSuspended = true; 162 CurrentTransaction.addSuspended(this); 163 164 if (term != null) { 166 term.setControl(this); 167 } 168 } 169 170 183 ControlImpl( Control ref ) 184 throws Unavailable { 185 186 188 thisRef = ref; 189 representsRemote = true; 190 coordRef = ref.get_coordinator(); 191 termRef = ref.get_terminator(); 192 193 196 try { 197 cachedContext = coordRef.get_txcontext(); 198 globalTID = new GlobalTID(cachedContext.current.otid); 199 } catch( Throwable exc ) { 200 } 201 202 tranState = Status.StatusActive; 203 204 207 209 } 210 211 219 synchronized public void finalize() { 220 221 223 if( inSuspended ) 224 CurrentTransaction.removeSuspended(this); 225 inSuspended = false; 226 227 229 if( term != null ) term.destroy(); 230 231 233 243 244 } 245 246 254 public GlobalTID getGlobalTID() { 255 return globalTID; 256 } 257 258 270 synchronized public otid_t getGlobalTID( StatusHolder status ) 271 throws SystemException { 272 273 otid_t result = null; 274 275 277 if( status != null ) 278 status.value = tranState; 279 280 282 if( globalTID == null ) { 283 284 INTERNAL exc = new INTERNAL(MinorCode.NoGlobalTID, 285 CompletionStatus.COMPLETED_NO); 286 throw exc; 287 } 288 else 289 result = globalTID.realTID; 290 291 return result; 292 } 293 294 309 synchronized public long getLocalTID( StatusHolder status ) 310 throws SystemException { 311 312 long result = 0; 313 314 316 if( status != null ) 317 status.value = tranState; 318 319 321 if( localTID == null ) { 322 INTERNAL exc = new INTERNAL(MinorCode.NoGlobalTID, 323 CompletionStatus.COMPLETED_NO); 324 throw exc; 325 } else { 326 result = localTID.longValue(); 327 } 328 329 return result; 330 } 331 332 333 348 synchronized ControlImpl popControl( StatusHolder status ) { 349 350 ControlImpl result = null; 351 352 354 if( status != null ) 355 status.value = tranState; 356 357 360 result = stacked; 361 stacked = null; 362 363 return result; 364 } 365 366 382 synchronized void pushControl( ControlImpl control, 383 StatusHolder status ) 384 throws SystemException { 385 386 if( tranState == Status.StatusActive ) { 387 388 390 if( stacked != null ) { 391 INTERNAL exc = new INTERNAL(MinorCode.AlreadyStacked, 392 CompletionStatus.COMPLETED_NO); 393 throw exc; 394 } 395 396 398 else 399 stacked = control; 400 } 401 402 404 if( status != null ) 405 status.value = tranState; 406 } 407 408 424 425 synchronized public Terminator get_terminator() 426 throws Unavailable, SystemException { 427 428 Terminator result = termRef; 429 430 434 if( tranState == Status.StatusCommitted ) { 435 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.Completed, 436 CompletionStatus.COMPLETED_NO); 437 throw exc; 438 } 439 440 if( tranState == Status.StatusRolledBack ) { 441 TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO); 442 throw exc; 443 } 444 445 448 if( termRef == null && term != null ) { 449 termRef = term.object(); 450 result = termRef; 451 } 452 453 455 if( result == null ) { 456 Unavailable exc = new Unavailable(); 457 throw exc; 458 } 459 460 return result; 461 } 462 463 synchronized public Terminator get_localTerminator() 464 throws Unavailable, SystemException { 465 466 Terminator result = (Terminator ) term; 467 468 472 if( tranState == Status.StatusCommitted ) { 473 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.Completed, 474 CompletionStatus.COMPLETED_NO); 475 throw exc; 476 } 477 478 if( tranState == Status.StatusRolledBack ) { 479 TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO); 480 throw exc; 481 } 482 483 485 if (result == null) { 486 Unavailable exc = new Unavailable(); 487 throw exc; 488 } 489 490 return result; 491 } 492 493 509 synchronized public Coordinator get_coordinator() 510 throws Unavailable, SystemException { 511 512 Coordinator result = coordRef; 513 514 518 if( tranState == Status.StatusCommitted ) { 519 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.Completed, 520 CompletionStatus.COMPLETED_NO); 521 throw exc; 522 } 523 524 if( tranState == Status.StatusRolledBack ) { 525 TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO); 526 throw exc; 527 } 528 529 532 if( coordRef == null && coord != null ) { 533 coordRef = coord.object(); 534 result = coordRef; 535 } 536 537 539 if( result == null ) { 540 Unavailable exc = new Unavailable(); 541 throw exc; 542 } 543 544 return result; 545 } 546 547 563 synchronized public Coordinator get_localCoordinator() 564 throws Unavailable, SystemException { 565 566 Coordinator result = (Coordinator) coord; 567 568 572 if( tranState == Status.StatusCommitted ) { 573 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.Completed, 574 CompletionStatus.COMPLETED_NO); 575 throw exc; 576 } 577 578 if( tranState == Status.StatusRolledBack ) { 579 TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO); 580 throw exc; 581 } 582 583 585 if( result == null ) { 586 Unavailable exc = new Unavailable(); 587 throw exc; 588 } 589 590 return result; 591 } 592 593 603 604 synchronized boolean isOutgoing() { 605 boolean result = (outgoing != 0); 606 return result; 607 } 608 609 610 619 synchronized boolean isAssociated() { 620 boolean result = (association != 0); 621 return result; 622 } 623 624 632 synchronized int numAssociated() { 633 int result = association; 634 return result; 635 } 636 637 645 synchronized void incrementAssociation() { 646 association++; 647 } 648 649 657 synchronized boolean decrementAssociation() { 658 boolean result = (association > 0); 659 if( result ) association--; 660 return result; 661 } 662 663 671 synchronized void incrementOutgoing() { 672 outgoing++; 673 } 674 675 683 synchronized boolean decrementOutgoing() { 684 boolean result = (outgoing > 0); 685 if( result ) outgoing--; 686 return result; 687 } 688 689 697 synchronized public Status getTranState(){ 698 Status result = tranState; 699 return result; 700 } 701 702 711 synchronized public void setTranState( Status newState ) { 712 tranState = newState; 713 } 714 715 716 726 synchronized ControlImpl popAborted() { 727 728 730 ControlImpl result = stacked; 731 boolean validTID = false; 732 StatusHolder outStatus = new StatusHolder(); 733 while( result != null && !validTID ) { 734 735 738 Long localTID = null; 739 try { 740 localTID = new Long (result.getLocalTID(outStatus)); } 741 catch( Throwable exc ) {} 742 validTID = RecoveryManager.validLocalTID(localTID); 743 744 747 if( !validTID ) { 748 749 752 ControlImpl stacked = result.popControl(outStatus); 753 result.destroy(); 754 755 758 result = stacked; 759 } 760 } 761 762 return result; 763 } 764 765 774 775 synchronized boolean representsRemoteControl() { 776 boolean result = representsRemote; 777 return result; 778 } 779 780 790 synchronized PropagationContext getTXContext() 791 throws Unavailable { 792 PropagationContext result = null; 793 794 797 if( representsRemote ) { 798 if( cachedContext == null ) 799 try { 800 cachedContext = coordRef.get_txcontext(); 801 } catch( OBJECT_NOT_EXIST exc ) { 802 TRANSACTION_ROLLEDBACK ex2 = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO); 803 throw ex2; 804 } 805 result = cachedContext; 806 } 807 808 810 else 811 result = coord.get_txcontext(); 812 813 return result; 814 } 815 816 824 void dump() { 825 } 826 827 835 synchronized final Control object() { 836 if( thisRef == null ) { 837 if( poa == null ) 838 poa = Configuration.getPOA("transient"); 839 840 try { 841 poa.activate_object(this); 842 thisRef = ControlHelper.narrow(poa.servant_to_reference(this)); 843 } catch( ServantAlreadyActive sexc ) { 844 _logger.log(Level.SEVERE,"jts.create_control_object_error",sexc); 845 String msg = LogFormatter.getLocalizedMessage(_logger, 846 "jts.create_control_object_error"); 847 throw new org.omg.CORBA.INTERNAL (msg); 848 } catch( ServantNotActive snexc ) { 849 _logger.log(Level.SEVERE,"jts.create_control_object_error",snexc); 850 String msg = LogFormatter.getLocalizedMessage(_logger, 851 "jts.create_control_object_error"); 852 throw new org.omg.CORBA.INTERNAL (msg); 853 } catch( Exception exc ) { 854 _logger.log(Level.SEVERE,"jts.create_control_object_error",exc); 855 String msg = LogFormatter.getLocalizedMessage(_logger, 856 "jts.create_control_object_error"); 857 throw new org.omg.CORBA.INTERNAL (msg); 858 } 859 } 860 861 return thisRef; 862 } 863 864 872 synchronized public static final ControlImpl servant( JControl control ) { 873 ControlImpl result = null; 874 875 if ( control != null && Configuration.getProxyChecker().isProxy(control)) { 879 return result; 880 } 881 882 if( control instanceof ControlImpl ) { 883 result = (ControlImpl)control; 884 } else if( poa != null ) 885 try { 886 result = (ControlImpl)poa.reference_to_servant(control); 887 if( result.thisRef == null ) 888 result.thisRef = control; 889 } catch( Exception exc ) { 890 _logger.log(Level.WARNING,"jts.cannot_locate_servant","Control"); 891 892 } 893 894 return result; 895 } 896 897 905 synchronized final void destroy() { 906 if ( thisRef != null && Configuration.getProxyChecker().isProxy(thisRef)) { 909 thisRef._release(); 910 } else { 911 if( poa != null && 912 thisRef != null ) 913 try { 914 poa.deactivate_object(poa.reference_to_id(thisRef)); 915 thisRef = null; 916 } catch( Exception exc ) { 917 _logger.log(Level.WARNING,"jts.object_destroy_error","Control"); 918 919 920 } 921 } 922 923 finalize(); 924 925 } 926 927 935 public boolean equals(java.lang.Object o) { 936 return this == o; 937 } 938 939 944 945 private static org.omg.CORBA.NO_IMPLEMENT no_implement = 946 new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 947 948 949 public org.omg.CORBA.Object _duplicate() { 950 throw no_implement; 951 952 } 953 954 public void _release() { 955 throw no_implement; 956 957 } 958 959 public boolean _is_a(String repository_id) { 960 throw no_implement; 961 962 } 963 964 public boolean _is_equivalent(org.omg.CORBA.Object that) { 965 throw no_implement; 966 967 } 968 969 public boolean _non_existent() { 970 throw no_implement; 971 972 } 973 974 public int _hash(int maximum) { 975 throw no_implement; 976 977 } 978 979 public Request _request(String operation) { 980 throw no_implement; 981 982 } 983 984 public Request _create_request(Context ctx, 985 String operation, 986 NVList arg_list, 987 NamedValue result) { 988 throw no_implement; 989 990 } 991 992 public Request _create_request(Context ctx, 993 String operation, 994 NVList arg_list, 995 NamedValue result, 996 ExceptionList exceptions, 997 ContextList contexts) { 998 throw no_implement; 999 1000 } 1001 1002 public org.omg.CORBA.Object _get_interface_def() { 1003 throw no_implement; 1004 1005 } 1006 1007 public org.omg.CORBA.Policy _get_policy(int policy_type) { 1008 throw no_implement; 1009 1010 } 1011 1012 public org.omg.CORBA.DomainManager [] _get_domain_managers() { 1013 throw no_implement; 1014 1015 } 1016 1017 public org.omg.CORBA.Object _set_policy_override( 1018 org.omg.CORBA.Policy [] policies, 1019 org.omg.CORBA.SetOverrideType set_add) { 1020 throw no_implement; 1021 1022 } 1023} 1024 | Popular Tags |