1 23 24 28 50 package com.sun.jts.CosTransactions; 51 52 54 import org.omg.CORBA.*; 55 import org.omg.PortableServer.*; 56 import org.omg.CosTransactions.*; 57 58 import com.sun.jts.otsidl.*; 59 import com.sun.jts.trace.*; 60 import java.util.logging.Logger ; 61 import java.util.logging.Level ; 62 import com.sun.logging.LogDomains; 63 import com.sun.jts.utils.LogFormatter; 64 65 79 86 public class CurrentImpl extends org.omg.CORBA.LocalObject 87 implements org.omg.CosTransactions.Current { 88 private int timeOut = 0; 89 private static boolean active = true; 90 private TransactionFactory factory = null; 91 94 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 95 96 104 CurrentImpl() { 105 106 108 CurrentTransaction.initialise(); 109 } 110 111 119 public void finalize() { 120 } 121 122 145 public void begin() 146 throws INVALID_TRANSACTION, SystemException, SubtransactionsUnavailable { 147 148 ControlImpl controlImpl = null; 149 150 152 synchronized(this) { 153 154 156 if( !active ) { 157 NO_PERMISSION exc = new NO_PERMISSION(0,CompletionStatus.COMPLETED_NO); 158 throw exc; 159 } 160 161 163 try { 164 controlImpl = CurrentTransaction.getCurrent(); 165 } catch( SystemException exc ) { 166 } 167 168 171 } 172 173 176 if( controlImpl != null ) 177 try { 178 179 182 Coordinator coord = controlImpl.get_coordinator(); 183 184 186 Control control = coord.create_subtransaction(); 187 188 193 JControl jcontrol = JControlHelper.narrow(control); 194 if( jcontrol != null ) 195 controlImpl = ControlImpl.servant(jcontrol); 196 197 200 if( controlImpl == null ) 201 controlImpl = new ControlImpl(control); 202 } catch( Throwable exc ) { 203 SubtransactionsUnavailable ex2 = new SubtransactionsUnavailable(); 204 throw ex2; 205 } 206 207 209 else { 210 try { 217 218 222 synchronized(this) { 223 if( factory == null ) 224 factory = Configuration.getFactory(); 225 } 226 227 229 if (factory != null) { 230 if(_logger.isLoggable(Level.FINEST)) 231 { 232 _logger.logp(Level.FINEST,"CurrentImpl","begin()", 233 "Before invoking create() on TxFactory"); 234 } 235 236 if (Configuration.isLocalFactory()) { 237 controlImpl = ((TransactionFactoryImpl) factory).localCreate(timeOut); 238 } else { 239 Control control = factory.create(timeOut); 240 241 246 JControl jcontrol = JControlHelper.narrow(control); 247 if (jcontrol != null) { 248 controlImpl = ControlImpl.servant(jcontrol); 249 } 250 251 254 if (controlImpl == null) { 255 controlImpl = new ControlImpl(control); 256 } 257 } 258 } 259 } catch( Throwable exc ) { 260 _logger.log(Level.WARNING, 261 "jts.unexpected_error_in_begin",exc); 262 263 } 264 } 265 266 268 if( controlImpl == null ){ 269 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.FactoryFailed, 270 CompletionStatus.COMPLETED_NO); 271 throw exc; 272 } 273 274 277 else 278 try { 279 if(_logger.isLoggable(Level.FINEST)) 280 { 281 _logger.logp(Level.FINEST,"CurrentImpl","begin()", 282 "Before invoking CurrentTransaction.setCurrent(control,true)"); 283 } 284 CurrentTransaction.setCurrent(controlImpl,true); 285 } 286 287 290 catch( INVALID_TRANSACTION exc ) { 291 controlImpl.destroy(); 292 throw (INVALID_TRANSACTION)exc.fillInStackTrace(); 293 } 294 295 } 296 297 324 public void begin(int time_out) 325 throws INVALID_TRANSACTION, SystemException, SubtransactionsUnavailable { 326 327 ControlImpl controlImpl = null; 328 329 331 synchronized(this) { 332 333 335 if( !active ) { 336 NO_PERMISSION exc = new NO_PERMISSION(0,CompletionStatus.COMPLETED_NO); 337 throw exc; 338 } 339 340 342 try { 343 controlImpl = CurrentTransaction.getCurrent(); 344 } catch( SystemException exc ) { 345 } 346 347 350 } 351 352 355 if( controlImpl != null ) 356 try { 357 358 361 Coordinator coord = controlImpl.get_coordinator(); 362 363 365 Control control = coord.create_subtransaction(); 366 367 372 JControl jcontrol = JControlHelper.narrow(control); 373 if( jcontrol != null ) 374 controlImpl = ControlImpl.servant(jcontrol); 375 376 379 if( controlImpl == null ) 380 controlImpl = new ControlImpl(control); 381 } catch( Throwable exc ) { 382 SubtransactionsUnavailable ex2 = new SubtransactionsUnavailable(); 383 throw ex2; 384 } 385 386 388 else { 389 try { 396 397 401 synchronized(this) { 402 if( factory == null ) 403 factory = Configuration.getFactory(); 404 } 405 406 408 if (factory != null) { 409 if(_logger.isLoggable(Level.FINEST)) 410 { 411 _logger.logp(Level.FINEST,"CurrentImpl","begin()", 412 "Before invoking create() on TxFactory"); 413 } 414 415 if (Configuration.isLocalFactory()) { 416 controlImpl = ((TransactionFactoryImpl) factory).localCreate(time_out); 417 } else { 418 Control control = factory.create(time_out); 419 420 425 JControl jcontrol = JControlHelper.narrow(control); 426 if (jcontrol != null) { 427 controlImpl = ControlImpl.servant(jcontrol); 428 } 429 430 433 if (controlImpl == null) { 434 controlImpl = new ControlImpl(control); 435 } 436 } 437 } 438 } catch( Throwable exc ) { 439 _logger.log(Level.WARNING, 440 "jts.unexpected_error_in_begin",exc); 441 442 } 443 } 444 445 447 if( controlImpl == null ){ 448 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.FactoryFailed, 449 CompletionStatus.COMPLETED_NO); 450 throw exc; 451 } 452 453 456 else 457 try { 458 if(_logger.isLoggable(Level.FINEST)) 459 { 460 _logger.logp(Level.FINEST,"CurrentImpl","begin()", 461 "Before invoking CurrentTransaction.setCurrent(control,true)"); 462 } 463 CurrentTransaction.setCurrent(controlImpl,true); 464 } 465 466 469 catch( INVALID_TRANSACTION exc ) { 470 controlImpl.destroy(); 471 throw (INVALID_TRANSACTION)exc.fillInStackTrace(); 472 } 473 474 } 475 477 478 502 public void commit( boolean reportHeuristics ) 503 throws NO_PERMISSION, INVALID_TRANSACTION, TRANSACTION_ROLLEDBACK, 504 NoTransaction, HeuristicHazard, HeuristicMixed, SystemException { 505 506 509 ControlImpl controlImpl = CurrentTransaction.getCurrent(); 510 if( controlImpl == null ) { 511 NoTransaction exc = new NoTransaction(); 512 throw exc; 513 } 514 515 518 int active = 1; 519 520 if( !controlImpl.representsRemoteControl() ) { 521 522 StatusHolder status = new StatusHolder(); 523 Long localTID = new Long (controlImpl.getLocalTID(status)); 524 525 if( status.value != Status.StatusActive ) { 526 527 CurrentTransaction.endCurrent(true); 535 536 if( status.value == Status.StatusRolledBack ) { 537 TRANSACTION_ROLLEDBACK exc = 538 new TRANSACTION_ROLLEDBACK(0, CompletionStatus.COMPLETED_NO); 539 throw exc; 540 } 541 542 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.Completed, 543 CompletionStatus.COMPLETED_NO); 544 throw exc; 545 } 546 547 550 active = controlImpl.numAssociated(); 551 } 552 553 556 if( (active != 1) || (controlImpl.isOutgoing()) ) { 557 if( active != 1 ) { 558 } 559 560 if( controlImpl.isOutgoing() ) { 561 } 562 563 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.DeferredActivities, 564 CompletionStatus.COMPLETED_NO); 565 throw exc; 566 } 567 568 571 else { 572 Terminator term = null; 573 574 if (Configuration.isLocalFactory()) { 575 try { 576 term = controlImpl.get_localTerminator(); 577 } catch (Throwable exc) { 578 NO_PERMISSION ex2 = new NO_PERMISSION(0,CompletionStatus.COMPLETED_NO); 579 throw ex2; 580 } 581 } else { 582 try { 583 term = controlImpl.get_terminator(); 584 } catch( Throwable exc ) { 585 NO_PERMISSION ex2 = new NO_PERMISSION(0,CompletionStatus.COMPLETED_NO); 586 throw ex2; 587 } 588 589 595 600 try { 601 if( Configuration.getProxyChecker().isProxy(term) ) 602 CurrentTransaction.endCurrent(true); 603 } catch( Throwable exc ) {} 604 } 605 607 try{ 608 term.commit(reportHeuristics); 609 } catch (TRANSACTION_ROLLEDBACK e) { 610 CurrentTransaction.endCurrent(true); 616 throw e; 617 } 618 619 621 controlImpl.destroy(); 622 } 623 624 } 625 626 645 public void rollback() 646 throws NoTransaction, INVALID_TRANSACTION, NO_PERMISSION, 647 TRANSACTION_ROLLEDBACK, SystemException { 648 649 ControlImpl controlImpl = CurrentTransaction.getCurrent(); 650 651 if( controlImpl == null ) { 652 NoTransaction exc = new NoTransaction(); 653 throw exc; 654 } 655 656 659 int active = 1; 660 661 if( !controlImpl.representsRemoteControl() ) { 662 663 StatusHolder status = new StatusHolder(); 664 Long localTID = new Long (controlImpl.getLocalTID(status)); 665 666 if( status.value != Status.StatusActive ) { 667 668 CurrentTransaction.endCurrent(true); 676 677 if( status.value == Status.StatusRolledBack ) { 678 682 return; 683 } 684 685 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.Completed, 686 CompletionStatus.COMPLETED_NO); 687 throw exc; 688 } 689 690 693 active = controlImpl.numAssociated(); 694 } 695 696 699 if( (active != 1) || (controlImpl.isOutgoing()) ) { 700 if( active != 1 ) { 701 } 702 703 if( controlImpl.isOutgoing() ) { 704 } 705 706 INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.DeferredActivities, 707 CompletionStatus.COMPLETED_NO); 708 throw exc; 709 } 710 711 714 else { 715 Terminator term = null; 716 717 if (Configuration.isLocalFactory()) { 718 try { 719 term = controlImpl.get_localTerminator(); 720 } catch( Unavailable exc ) { 721 NO_PERMISSION ex2 = new NO_PERMISSION(0,CompletionStatus.COMPLETED_NO); 722 throw ex2; 723 } 724 } else { 725 try { 726 term = controlImpl.get_terminator(); 727 } catch( Unavailable exc ) { 728 NO_PERMISSION ex2 = new NO_PERMISSION(0,CompletionStatus.COMPLETED_NO); 729 throw ex2; 730 } 731 732 738 743 try { 744 if( Configuration.getProxyChecker().isProxy(term) ) 745 CurrentTransaction.endCurrent(true); 746 } catch( Throwable exc ) {} 747 } 748 750 try{ 751 term.rollback(); 752 } catch (TRANSACTION_ROLLEDBACK e) { 753 CurrentTransaction.endCurrent(true); 759 } 761 762 764 controlImpl.destroy(); 765 } 766 767 } 768 769 781 public void rollback_only() 782 throws NoTransaction { 783 784 787 try { 788 Coordinator coord = CurrentTransaction.getCurrentCoordinator(); 789 790 792 coord.rollback_only(); 793 } catch( Throwable exc ) { 794 throw new NoTransaction(); 795 } 796 797 } 798 799 808 public Status get_status() { 809 810 Status result = Status.StatusNoTransaction; 811 try { 812 Coordinator coord = CurrentTransaction.getCurrentCoordinator(); 813 814 816 if( coord != null ) 817 result = coord.get_status(); 818 } catch( Unavailable exc ) { 819 } catch( TRANSACTION_ROLLEDBACK exc ) { 820 result = Status.StatusRolledBack; 821 } catch( SystemException exc ) { 822 result = Status.StatusUnknown; 823 } 824 825 return result; 826 } 827 828 837 public String get_transaction_name() { 838 839 String result = null; 840 try { 841 Coordinator coord = CurrentTransaction.getCurrentCoordinator(); 842 843 845 if( coord != null ) 846 result = coord.get_transaction_name(); 847 } 848 849 852 catch( Unavailable exc ) {} 853 854 return result; 855 } 856 857 865 public void set_timeout( int timeout ) { 866 if (timeout >= 0) { 870 timeOut = timeout; 871 } 872 } 873 874 public int get_timeout() { 875 return timeOut; 876 } 877 878 890 public Control get_control() 891 throws TRANSACTION_ROLLEDBACK { 892 Control result = null; 893 894 900 ControlImpl control = CurrentTransaction.getCurrent(); 901 if (control != null) { 902 if (Configuration.isLocalFactory()) { 903 result = (Control) control; 904 } else { 905 result = control.object(); 906 } 907 } 908 909 return result; 910 } 911 912 921 public Control suspend() { 922 Control result = null; 923 ControlImpl cImpl = CurrentTransaction.endCurrent(false); 924 if(_logger.isLoggable(Level.FINEST)) 925 { 926 _logger.logp(Level.FINEST,"CurrentImpl","suspend()", 927 "Current thread has been disassociated from control :" 928 +cImpl); 929 } 930 931 if (Configuration.isLocalFactory()) { 932 result = (Control) cImpl; 933 } else { 934 if (cImpl != null) { 935 result = cImpl.object(); 936 } 937 } 938 939 return result; 940 } 941 942 958 public void resume( Control control ) 959 throws InvalidControl, INVALID_TRANSACTION { 960 961 ControlImpl contImpl = null; 962 963 966 if( control == null ) 967 CurrentTransaction.endCurrent(false); 968 else { 969 970 if (Configuration.isLocalFactory()) { 971 contImpl = (ControlImpl) control; 972 } else { 973 JControl jcontrol = JControlHelper.narrow(control); 975 976 978 if( jcontrol != null ) 979 contImpl = ControlImpl.servant(jcontrol); 980 981 984 if( contImpl == null ) 985 try { 986 contImpl = new ControlImpl(control); 987 } catch( Exception exc ) { 988 989 InvalidControl ex2 = new InvalidControl(); 990 throw ex2; 991 } 992 } 993 994 997 try { 998 CurrentTransaction.endCurrent(false); 999 CurrentTransaction.setCurrent(contImpl,false); 1000 if(_logger.isLoggable(Level.FINEST)) 1001 { 1002 _logger.logp(Level.FINEST,"CurrentImpl","resume(control)", 1003 "Current thread has been associated with control :" 1004 +contImpl); 1005 } 1006 } 1007 1008 1011 catch( INVALID_TRANSACTION exc ) { 1012 throw (INVALID_TRANSACTION)exc.fillInStackTrace(); 1013 } 1014 } 1015 1016 } 1017 1018 1026 1027 synchronized void shutdown( boolean immediate ) { 1028 1029 1031 CurrentTransaction.shutdown(immediate); 1032 1033 } 1034 1035 1043 static void deactivate() { 1044 active = false; 1045 } 1046 1047 public String [] _ids() { 1051 return null; 1052 } 1053} 1054 | Popular Tags |