1 23 24 28 50 package com.sun.jts.CosTransactions; 51 52 import java.util.*; 53 54 import org.omg.CORBA.*; 55 import org.omg.CosTransactions.*; 56 57 import com.sun.jts.otsidl.*; 58 import com.sun.jts.trace.*; 59 import com.sun.jts.jtsxa.OTSResourceImpl; 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 import javax.transaction.xa.*; 66 82 83 93 class RegisteredResources { 94 private ArrayList resourceObjects = null; 95 private ArrayList resourceStates = null; 96 private CoordinatorLog logRecord = null; 97 private java.lang.Object logSection = null; 98 private java.lang.Object heuristicLogSection = null; 99 private Resource laoResource = null; 100 private CoordinatorImpl coord = null; 101 private static boolean lastXAResCommit = false; 102 107 private int nRes=0; 109 110 113 private final static String LOG_SECTION_NAME = "RR"; 115 private final static String HEURISTIC_LOG_SECTION_NAME = "RRH"; 116 117 static { 118 String lastXAResCommitProp = System.getProperty("com.sun.jts.lastagentcommit"); 119 if (lastXAResCommitProp != null && "true".equals(lastXAResCommitProp.toLowerCase())) { 120 lastXAResCommit = true; 121 } 122 } 123 124 127 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 128 146 RegisteredResources(CoordinatorLog log, CoordinatorImpl coord) { 147 148 resourceObjects = new ArrayList(); 149 resourceStates = new ArrayList(); 150 151 153 logRecord = log; 154 155 if (log != null) { 156 157 159 161 163 } 165 this.coord = coord; 166 } 167 168 177 RegisteredResources(CoordinatorImpl coord) { this.coord = coord;} 178 179 188 public void finalize() { 189 190 if (resourceObjects != null) { 191 empty(); 192 } 193 194 resourceObjects = null; 195 resourceStates = null; 196 logRecord = null; 197 logSection = null; 198 heuristicLogSection = null; 199 } 200 201 213 214 void reconstruct(CoordinatorLog log) { 215 216 217 219 resourceObjects = new ArrayList(); 220 resourceStates = new ArrayList(); 221 boolean infiniteRetry = true; 222 223 225 234 int commitRetries = Configuration.getRetries(); 235 if (commitRetries >= 0) 236 infiniteRetry = false; 237 238 240 244 heuristicLogSection = log.createSection(HEURISTIC_LOG_SECTION_NAME); 245 java.lang.Object [] resources = log.getObjects(heuristicLogSection); 246 for(int i = 0; i < resources.length; i++) { 247 boolean exceptionThrown=true; 248 int commitRetriesLeft = commitRetries; 249 while(exceptionThrown){ 250 try { 251 Resource res = 252 ResourceHelper.narrow((org.omg.CORBA.Object )resources[i]); 253 if (res != null) { 254 resourceObjects.add(res); 255 nRes++; 256 resourceStates.add(ResourceStatus.Heuristic); 257 } 258 exceptionThrown=false; 259 } catch (Throwable exc) { 260 if(exc instanceof TRANSIENT || exc instanceof COMM_FAILURE) { 261 264 _logger.log(Level.WARNING,"jts.exception_on_resource_operation", 266 new java.lang.Object []{exc.toString(), 267 "reconstruct"}); 268 if (commitRetriesLeft > 0 || infiniteRetry) { 269 270 if (!infiniteRetry) { 273 commitRetriesLeft--; 274 } 275 276 try { 277 Thread.sleep(Configuration.COMMIT_RETRY_WAIT); 278 } catch( Throwable e ) {} 279 280 } else { 281 282 _logger.log(Level.SEVERE,"jts.retry_limit_exceeded", 285 new java.lang.Object [] { 286 new Integer (commitRetries), "commit"}); 287 String msg = LogFormatter.getLocalizedMessage(_logger, 288 "jts.retry_limit_exceeded", 289 new java.lang.Object [] { 290 new Integer (commitRetries), "commit"}); 291 throw new org.omg.CORBA.INTERNAL (msg); 292 } 296 } 297 else{ 298 exceptionThrown=false; 299 } 300 } 301 } 302 } 303 304 307 logSection = log.createSection(LOG_SECTION_NAME); 308 resources = log.getObjects(logSection); 309 for (int i = 0; i < resources.length; i++) { 310 boolean exceptionThrown=true; 311 int commitRetriesLeft = commitRetries; 312 while(exceptionThrown){ 313 try { 314 Resource res = 315 ResourceHelper.narrow((org.omg.CORBA.Object )resources[i]); 316 if (res != null) { 317 resourceObjects.add(res); 318 nRes++; 319 resourceStates.add(ResourceStatus.Registered); 320 } 321 exceptionThrown=false; 322 } catch (Throwable exc) { 323 if(exc instanceof TRANSIENT || exc instanceof COMM_FAILURE) { 324 327 _logger.log(Level.WARNING,"jts.exception_on_resource_operation", 329 new java.lang.Object [] {exc.toString(),"reconstruct"}); 330 if (commitRetriesLeft > 0 || infiniteRetry) { 331 332 if (!infiniteRetry) { 335 commitRetriesLeft--; 336 } 337 338 try { 339 Thread.sleep(Configuration.COMMIT_RETRY_WAIT); 340 } catch( Throwable e ) {} 341 342 } else { 343 344 _logger.log(Level.SEVERE,"jts.retry_limit_exceeded", 347 new java.lang.Object [] {new Integer (commitRetries), 348 "commit"}); 349 String msg = LogFormatter.getLocalizedMessage(_logger, 350 "jts.retry_limit_exceeded", 351 new java.lang.Object [] { 352 new Integer (commitRetries), 353 "commit"}); 354 355 throw new org.omg.CORBA.INTERNAL (msg); 356 } 359 } 360 else{ 361 exceptionThrown=false; 362 } 363 } 364 365 } 366 } 367 368 logRecord = log; 369 } 370 380 int addRes(Resource obj) { 381 382 384 387 resourceObjects.add(obj); 388 nRes++; 389 resourceStates.add(ResourceStatus.Registered); 390 392 395 return nRes; 396 } 397 398 407 void empty() { 408 409 411 resourceObjects.clear(); 412 nRes=0; 413 resourceStates.clear(); 414 } 415 416 427 boolean involved() { 428 429 boolean result = (nRes != 0 ); 430 431 return result; 432 } 433 434 443 int numRegistered() { 444 445 return nRes; 446 } 447 448 470 Vote distributePrepare() throws HeuristicMixed, HeuristicHazard { 471 boolean isProxy = false; 472 Vote result = Vote.VoteReadOnly; 473 int laoIndex = -1; 474 475 481 for (int i = 0; 482 i < nRes && result != Vote.VoteRollback; 483 i++) { 484 485 Resource currResource = (Resource) resourceObjects.get(i); 486 487 if ((i == nRes - 1) && lastXAResCommit && (laoResource == null) && 488 result == Vote.VoteCommit) { 489 try { 490 if(_logger.isLoggable(Level.FINER)) 491 { 492 _logger.logp(Level.FINER,"RegisteredResources", 493 "distributePrepare()", 494 "Before invoking commit on LA resource = " + 495 currResource); 496 } 497 currResource.commit_one_phase(); 498 resourceStates.set(i, ResourceStatus.Completed); 499 if(_logger.isLoggable(Level.FINER)) 500 { 501 _logger.logp(Level.FINER,"RegisteredResources", 502 "distributePrepare()", 503 "After invoking commit on LA resource = "+ 504 currResource); 505 } 506 } catch (Throwable exc) { 507 result = Vote.VoteRollback; 508 resourceStates.set(i,ResourceStatus.Completed); 509 } 510 return result; 511 } 512 513 516 519 if(!(currResource instanceof OTSResourceImpl)) { 523 ProxyChecker checkProxy = Configuration.getProxyChecker(); 524 isProxy = checkProxy.isProxy(currResource); 525 } 526 527 Vote currResult = Vote.VoteRollback; 528 529 try { 530 if(_logger.isLoggable(Level.FINER)) 531 { 532 _logger.logp(Level.FINER,"RegisteredResources","prepare()", 533 "Before invoking prepare() on resource:" + 534 currResource); 535 } 536 currResult = currResource.prepare(); 537 if(currResult == null) { 539 if(_logger.isLoggable(Level.FINER)) 540 { 541 _logger.logp(Level.FINER,"RegisteredResources","prepare()", 542 "Marking the current resource as LAO:" + 543 currResource); 544 } 545 laoResource = currResource; 546 laoIndex = i; 547 continue; 548 } 549 if(_logger.isLoggable(Level.FINER)) 550 { 551 _logger.logp(Level.FINER,"RegisteredResources","prepare()", 552 "After invoking prepare() on resource:" + 553 currResource + ";This resource voted : "+ 554 currResult); 555 } 556 } catch (Throwable exc) { 557 558 567 boolean hazard = exc instanceof HeuristicHazard; 568 if (exc instanceof HeuristicMixed || hazard) { 569 570 574 resourceStates.set(i,ResourceStatus.Heuristic); 575 576 try { 577 distributeRollback(true); 578 } catch (Throwable ex2) { 579 580 583 if (ex2 instanceof HeuristicMixed && hazard) { 584 hazard = false; 585 } 586 } 587 588 590 if (hazard) { 591 HeuristicHazard ex2 = new HeuristicHazard(); 592 throw ex2; 593 } else { 594 HeuristicMixed ex2 = new HeuristicMixed(); 595 throw ex2; 596 } 597 } 598 599 _logger.log(Level.WARNING,"jts.exception_on_resource_operation", 603 new java.lang.Object [] {exc.toString(),"prepare"}); 604 } 605 606 608 610 if (currResult == Vote.VoteCommit) { 611 if (logRecord != null) { 612 if (!(currResource instanceof OTSResourceImpl)) { 613 if (logSection == null) 614 logSection = logRecord.createSection(LOG_SECTION_NAME); 615 logRecord.addObject(logSection, currResource); 616 } 617 } 618 619 if (result == Vote.VoteReadOnly) { 620 result = Vote.VoteCommit; 621 } 622 } else { 623 624 634 resourceStates.set(i,ResourceStatus.Completed); 635 if (isProxy) { 636 currResource._release(); 637 } 638 639 if (currResult == Vote.VoteRollback) { 640 result = currResult; 641 } 642 } 643 } 644 645 if (result == Vote.VoteCommit && laoResource != null) { 646 try { 647 if(_logger.isLoggable(Level.FINER)) 648 { 649 _logger.logp(Level.FINER,"RegisteredResources", 650 "distributePrepare()", 651 "Before invoking commit on LA resource = " + 652 laoResource); 653 } 654 resourceStates.set(laoIndex, ResourceStatus.Completed); 656 if(_logger.isLoggable(Level.FINER)) 657 { 658 _logger.logp(Level.FINER,"RegisteredResources", 659 "distributePrepare()", 660 "After invoking commit on LA resource = "+ 661 laoResource); 662 } 663 } catch (Throwable exc) { 664 result = Vote.VoteRollback; 665 resourceStates.set(laoIndex,ResourceStatus.Completed); 666 } 667 } 668 return result; 669 } 670 671 Resource getLAOResource() { 672 return laoResource; 673 } 674 675 676 677 703 void distributeCommit() throws HeuristicMixed, HeuristicHazard, NotPrepared { 704 boolean infiniteRetry = true; 705 boolean isProxy = false; 706 707 boolean heuristicException = false; 708 boolean heuristicMixed = false; 709 710 712 721 int commitRetries = Configuration.getRetries(); 722 if (commitRetries >= 0) 723 infiniteRetry = false; 724 725 726 729 boolean transactionCompleted = true; 730 String msg = null; 731 for (int i = 0; i < nRes; i++) { 732 733 Resource currResource = (Resource) resourceObjects.get(i); 734 735 738 if ((ResourceStatus) resourceStates.get(i) == 739 ResourceStatus.Registered) { 740 741 boolean heuristicRaised = false; 742 743 746 if(!(currResource instanceof com.sun.jts.jtsxa.OTSResourceImpl)) { 750 ProxyChecker checkProxy = Configuration.getProxyChecker(); 751 isProxy = checkProxy.isProxy(currResource); 752 } 753 754 756 resourceStates.set(i,ResourceStatus.Completing); 757 758 762 int commitRetriesLeft = commitRetries; 763 boolean exceptionThrown = true; 764 while (exceptionThrown) { 765 try { 766 if(_logger.isLoggable(Level.FINER)) 767 { 768 _logger.logp(Level.FINER,"RegisteredResources", 769 "distributeCommit()", 770 "Before invoking commit on resource = " + 771 currResource); 772 } 773 currResource.commit(); 774 if(_logger.isLoggable(Level.FINER)) 775 { 776 _logger.logp(Level.FINER,"RegisteredResources", 777 "distributeCommit()", 778 "After invoking commit on resource = "+ 779 currResource); 780 } 781 exceptionThrown = false; 782 } catch (Throwable exc) { 783 784 if (exc instanceof HeuristicCommit) { 785 786 heuristicException = true; 789 heuristicRaised = true; 790 exceptionThrown = false; 791 792 } else if (exc instanceof HeuristicRollback || 793 exc instanceof HeuristicHazard || 794 exc instanceof HeuristicMixed) { 795 800 heuristicException = true; 801 heuristicMixed = !(exc instanceof HeuristicHazard); 802 heuristicRaised = true; 803 exceptionThrown = false; 804 805 } else if (exc instanceof INV_OBJREF || 806 exc instanceof OBJECT_NOT_EXIST) { 807 808 exceptionThrown = false; 811 812 } else if (exc instanceof NotPrepared) { 813 814 _logger.log(Level.SEVERE, 822 "jts.exception_on_resource_operation", 823 new java.lang.Object [] {exc.toString(),"commit"}); 824 825 throw (NotPrepared)exc; 826 833 } else if (!(exc instanceof TRANSIENT) && 834 !(exc instanceof COMM_FAILURE)) { 835 839 _logger.log(Level.SEVERE, 841 "jts.exception_on_resource_operation", 842 new java.lang.Object [] {exc.toString(),"commit"}); 843 844 exceptionThrown = false; 845 transactionCompleted = false; 846 msg = LogFormatter.getLocalizedMessage(_logger, 847 "jts.exception_on_resource_operation", 848 new java.lang.Object [] {exc.toString(), 849 "commit"}); 850 851 } else if (commitRetriesLeft > 0 || infiniteRetry) { 852 853 if (!infiniteRetry) { 856 commitRetriesLeft--; 857 } 858 859 try { 860 Thread.sleep(Configuration.COMMIT_RETRY_WAIT); 861 } catch( Throwable e ) {} 862 863 } else { 864 865 _logger.log(Level.SEVERE,"jts.retry_limit_exceeded", 868 new java.lang.Object [] { 869 new Integer (commitRetries), "commit"}); 870 871 exceptionThrown = false; 872 transactionCompleted = false; 873 msg = LogFormatter.getLocalizedMessage(_logger, 874 "jts.retry_limit_exceeded", 875 new java.lang.Object [] { 876 new Integer (commitRetries), "commit"}); 877 } 878 } 879 } 880 881 882 if (heuristicRaised) { 883 884 887 resourceStates.set(i,ResourceStatus.Heuristic); 888 889 if (logRecord != null) { 890 if (!(currResource instanceof OTSResourceImpl)) { 891 if (heuristicLogSection == null) 892 heuristicLogSection = 893 logRecord.createSection(HEURISTIC_LOG_SECTION_NAME); 894 logRecord.addObject(heuristicLogSection, currResource); 895 } 896 } 897 } else { 898 899 902 resourceStates.set(i,ResourceStatus.Completed); 903 if (isProxy) { 904 currResource._release(); 905 } 906 } 907 } 908 } 909 910 914 if (heuristicException) 915 distributeForget(commitRetries, infiniteRetry, heuristicMixed); 916 917 if (!transactionCompleted) { 918 if (coord != null) 919 RecoveryManager.addToIncompleTx(coord, true); 920 if (msg != null) 921 throw new org.omg.CORBA.INTERNAL (msg); 922 else 923 throw new org.omg.CORBA.INTERNAL (); 924 } 925 926 } 928 929 956 void distributeRollback(boolean heuristicException) 957 throws HeuristicMixed, HeuristicHazard { 958 959 boolean infiniteRetry = true; 960 boolean heuristicMixed = false; 961 boolean isProxy = false; 962 963 965 975 int commitRetries = Configuration.getRetries(); 976 if (commitRetries >= 0) 977 infiniteRetry = false; 978 979 980 981 984 boolean transactionCompleted = true; 985 String msg = null; 986 for (int i = 0; i < nRes; i++) { 987 988 Resource currResource = (Resource)resourceObjects.get(i); 989 990 993 if (resourceStates.get(i).equals( 994 ResourceStatus.Registered)) { 995 boolean heuristicRaised = false; 996 997 1000 if (!(currResource instanceof com.sun.jts.jtsxa.OTSResourceImpl)) { 1004 ProxyChecker checkProxy = Configuration.getProxyChecker(); 1005 isProxy = checkProxy.isProxy(currResource); 1006 } 1007 1008 1010 resourceStates.set(i,ResourceStatus.Completing); 1011 1012 1016 int rollbackRetriesLeft = commitRetries; 1017 boolean exceptionThrown = true; 1018 while (exceptionThrown) { 1019 try { 1020 if(_logger.isLoggable(Level.FINER)) 1021 { 1022 _logger.logp(Level.FINER,"RegisteredResources", 1023 "distributeRollback()", 1024 "Before invoking rollback on resource = "+ 1025 currResource); 1026 } 1027 currResource.rollback(); 1028 if(_logger.isLoggable(Level.FINER)) 1029 { 1030 _logger.logp(Level.FINER,"RegisteredResources", 1031 "distributeRollback()", 1032 "After invoking rollback on resource = "+ 1033 currResource); 1034 } 1035 exceptionThrown = false; 1036 } catch (Throwable exc) { 1037 1038 if (exc instanceof TRANSACTION_ROLLEDBACK) { 1039 1040 exceptionThrown = false; 1043 } 1044 1045 if (exc instanceof HeuristicRollback) { 1046 1047 heuristicException = true; 1051 heuristicRaised = true; 1052 exceptionThrown = false; 1053 1054 } else if (exc instanceof HeuristicCommit || 1055 exc instanceof HeuristicHazard || 1056 exc instanceof HeuristicMixed) { 1057 1058 heuristicException = true; 1063 heuristicMixed = !(exc instanceof HeuristicHazard); 1064 heuristicRaised = true; 1065 exceptionThrown = false; 1066 1067 } else if (exc instanceof INV_OBJREF || 1068 exc instanceof OBJECT_NOT_EXIST){ 1069 1070 exceptionThrown = false; 1074 1075 } else if (!(exc instanceof TRANSIENT) && 1076 !(exc instanceof COMM_FAILURE)) { 1077 1078 _logger.log(Level.SEVERE, 1082 "jts.exception_on_resource_operation", 1083 new java.lang.Object [] 1084 { exc.toString(), "rollback"}); 1085 1086 msg = LogFormatter.getLocalizedMessage(_logger, 1087 "jts.exception_on_resource_operation", 1088 new java.lang.Object [] { exc.toString(), 1089 "rollback"}); 1090 exceptionThrown = false; 1091 transactionCompleted = false; 1092 1093 } else if (rollbackRetriesLeft > 0 || infiniteRetry) { 1094 1095 1098 if (!infiniteRetry) { 1099 rollbackRetriesLeft--; 1100 } 1101 1102 try { 1103 Thread.sleep(Configuration.COMMIT_RETRY_WAIT); 1104 } catch( Throwable e ) {} 1105 1106 } else { 1107 1108 _logger.log(Level.SEVERE,"jts.retry_limit_exceeded", 1111 new java.lang.Object [] 1112 { new Integer (commitRetries), "rollback"}); 1113 1114 msg = LogFormatter.getLocalizedMessage(_logger, 1115 "jts.retry_limit_exceeded", 1116 new java.lang.Object [] 1117 { new Integer (commitRetries), "rollback"}); 1118 1119 exceptionThrown = false; 1120 transactionCompleted = false; 1121 } 1122 } 1123 } 1124 1125 if (heuristicRaised) { 1126 1127 1130 resourceStates.set(i,ResourceStatus.Heuristic); 1131 if (logRecord != null) { 1132 if (!(currResource instanceof OTSResourceImpl)) { 1133 if (heuristicLogSection == null) 1134 heuristicLogSection = 1135 logRecord.createSection(HEURISTIC_LOG_SECTION_NAME); 1136 1137 logRecord.addObject(heuristicLogSection,currResource); 1138 } 1139 } 1140 1141 } else { 1142 1143 1146 resourceStates.set(i,ResourceStatus.Completed); 1147 if (isProxy) { 1148 currResource._release(); 1149 } 1150 } 1151 } 1152 } 1153 1154 1155 1160 if (heuristicException) 1161 distributeForget(commitRetries, infiniteRetry, heuristicMixed); 1162 1163 if (!transactionCompleted) { 1164 if (coord != null) 1165 RecoveryManager.addToIncompleTx(coord, false); 1166 if (msg != null) 1167 throw new org.omg.CORBA.INTERNAL (msg); 1168 else 1169 throw new org.omg.CORBA.INTERNAL (); 1170 } 1171 1172 } 1174 1175 1197 private void distributeForget(int retries, boolean infinite, 1198 boolean heuristicMixed) throws HeuristicMixed, HeuristicHazard { 1199 1200 boolean isProxy = false; 1201 1202 1205 if (logRecord != null) { 1206 logRecord.write(true); 1207 } 1208 1209 1212 for (int i = 0; i < nRes; i++) { 1213 1214 1217 if ((ResourceStatus)resourceStates.get(i) == 1218 ResourceStatus.Heuristic) { 1219 1220 Resource currResource = (Resource)resourceObjects.get(i); 1221 1222 1225 if(!(currResource instanceof com.sun.jts.jtsxa.OTSResourceImpl)) { 1229 ProxyChecker checkProxy = Configuration.getProxyChecker(); 1230 isProxy = checkProxy.isProxy(currResource); 1231 } 1232 1233 1235 int retriesLeft = retries; 1236 boolean exceptionThrown = true; 1237 while (exceptionThrown) { 1238 try { 1239 currResource.forget(); 1240 exceptionThrown = false; 1241 } catch (Throwable exc) { 1242 1243 if (exc instanceof INV_OBJREF || 1244 exc instanceof OBJECT_NOT_EXIST) { 1245 1246 exceptionThrown = false; 1249 1250 } else if (!(exc instanceof COMM_FAILURE) && 1251 !(exc instanceof TRANSIENT)) { 1252 1253 exceptionThrown = false; 1258 1259 } else if (retriesLeft > 0 || infinite) { 1260 1261 if (!infinite) { 1264 retriesLeft--; 1265 } 1266 1267 try { 1268 Thread.sleep(Configuration.COMMIT_RETRY_WAIT); 1269 } catch( Throwable e ) {} 1270 1271 } else { 1272 1273 _logger.log(Level.SEVERE,"jts.retry_limit_exceeded", 1276 new java.lang.Object [] { new Integer (retries), 1277 "forget"}); 1278 String msg = LogFormatter.getLocalizedMessage(_logger, 1279 "jts.retry_limit_exceeded", 1280 new java.lang.Object [] 1281 { new Integer (retries), "forget"}); 1282 throw new org.omg.CORBA.INTERNAL (msg); 1283 } 1284 } 1285 } 1286 1287 1291 resourceStates.set(i,ResourceStatus.Completed); 1292 if (isProxy) { 1293 currResource._release(); 1294 } 1295 } 1296 } 1297 1298 1301 if (heuristicMixed) { 1302 HeuristicMixed exc = new HeuristicMixed(); 1303 throw exc; 1304 } else { 1305 HeuristicHazard exc = new HeuristicHazard(); 1306 throw exc; 1307 } 1308 } 1309 1310 1324 void distributeSubcommit(Coordinator parent) 1325 throws TRANSACTION_ROLLEDBACK { 1326 1327 boolean exceptionRaised = false; 1328 boolean isProxy = false; 1329 1330 1333 for (int i = 0; i < nRes; i++) { 1334 1335 SubtransactionAwareResource currResource = 1336 (SubtransactionAwareResource)resourceObjects.get(i); 1337 1338 if(!(currResource instanceof com.sun.jts.jtsxa.OTSResourceImpl)) { 1342 ProxyChecker checkProxy = Configuration.getProxyChecker(); 1343 isProxy = checkProxy.isProxy(currResource); 1344 } 1345 1346 1348 try { 1349 currResource.commit_subtransaction(parent); 1350 } catch (Throwable exc) { 1351 1352 1356 if (exc instanceof TRANSACTION_ROLLEDBACK) { 1357 exceptionRaised = true; 1358 } 1359 } 1360 1361 1363 resourceStates.set(i,ResourceStatus.Completed); 1364 1365 1367 if (isProxy) { 1368 currResource._release(); 1369 } 1370 } 1371 1372 1374 if (exceptionRaised) { 1375 throw new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_YES); 1376 } 1377 } 1378 1379 1389 void distributeSubrollback() { 1390 boolean isProxy = false; 1391 1392 1395 1396 for (int i = 0; i < nRes; i++) { 1397 SubtransactionAwareResource currResource = 1398 (SubtransactionAwareResource) resourceObjects.get(i); 1399 1400 if(!(currResource instanceof com.sun.jts.jtsxa.OTSResourceImpl)) { 1404 ProxyChecker checkProxy = Configuration.getProxyChecker(); 1405 isProxy = checkProxy.isProxy(currResource); 1406 } 1407 1408 1410 try { 1411 currResource.rollback_subtransaction(); 1412 } catch (Throwable exc) {} 1413 1414 resourceStates.set(i,ResourceStatus.Completed); 1415 1416 1418 if (isProxy) { 1419 currResource._release(); 1420 } 1421 } 1422 } 1423 1424 1435 1446 1447 1456 void commitOnePhase() throws HeuristicMixed, HeuristicHazard { 1457 1458 boolean infiniteRetry = true; 1459 1460 boolean heuristicRaisedSetStatus = false; 1461 boolean heuristicExceptionFlowForget = false; 1462 boolean isProxy = false; 1463 1464 boolean heuristicMixed = false; 1465 boolean heuristicHazard = false; 1466 boolean rollback_occurred = false; 1467 boolean outstanding_resources = true; 1468 int retry_limit; 1469 int no_of_attempts; 1470 1471 1473 1491 int commitRetries = Configuration.getRetries(); 1492 if (commitRetries >= 0) 1493 infiniteRetry = false; 1494 1495 1496 if (nRes > 1) { 1499 _logger.log(Level.SEVERE,"jts.exception_on_resource_operation", 1500 new java.lang.Object [] { "commitOnePhase", ">1 Resource"}); 1501 String msg = LogFormatter.getLocalizedMessage(_logger, 1502 "jts.exception_on_resource_operation", 1503 new java.lang.Object [] 1504 { "commitOnePhase", ">1 Resource"}); 1505 throw new org.omg.CORBA.INTERNAL (msg); 1506 } 1507 1508 1511 Resource currResource = (Resource) resourceObjects.get(0); 1512 1513 if ((ResourceStatus) resourceStates.get(0) != 1518 ResourceStatus.Registered) { 1519 return; 1520 } 1521 1522 1525 if(!(currResource instanceof com.sun.jts.jtsxa.OTSResourceImpl)) { 1529 ProxyChecker checkProxy = Configuration.getProxyChecker(); 1530 isProxy = checkProxy.isProxy(currResource); 1531 } 1532 1533 1535 resourceStates.set(0,ResourceStatus.Completing); 1536 1537 1540 int commitRetriesLeft = commitRetries; 1541 1542 boolean exceptionThrownTryAgain = true; 1543 1544 while (exceptionThrownTryAgain) { 1545 try { 1546 if(_logger.isLoggable(Level.FINEST)) 1547 { 1548 _logger.logp(Level.FINEST,"RegisteredResources","commitOnePhase()", 1549 "Before invoking commit_one_phase() on resource:" + 1550 currResource ); 1551 } 1552 1553 currResource.commit_one_phase(); 1554 1555 if(_logger.isLoggable(Level.FINEST)) 1556 { 1557 _logger.logp(Level.FINEST,"RegisteredResources","commitOnePhase()", 1558 "After invoking commit_one_phase() on resource:" + 1559 currResource ); 1560 } 1561 resourceStates.set(0,ResourceStatus.Completed); 1562 exceptionThrownTryAgain = false; 1563 } catch (Throwable exc) { 1564 1565 if (exc instanceof TRANSACTION_ROLLEDBACK) { 1566 rollback_occurred = true; 1570 resourceStates.set(0,ResourceStatus.Completed); 1571 exceptionThrownTryAgain = false; 1572 1573 } else if (exc instanceof HeuristicHazard) { 1574 1575 1579 1580 1587 XAException e = (XAException) ((Throwable )exc).getCause(); 1588 if ((e!= null) && (e.errorCode >= XAException.XA_RBBASE && e.errorCode <= XAException.XA_RBEND)) { 1589 rollback_occurred = true; 1590 resourceStates.set(0,ResourceStatus.Completed); 1591 exceptionThrownTryAgain = false; 1592 } 1593 else { 1594 heuristicExceptionFlowForget = true; 1595 heuristicRaisedSetStatus = true; 1596 exceptionThrownTryAgain = false; 1597 heuristicMixed = false; 1598 } 1599 1601 1602 } else if (exc instanceof INV_OBJREF || 1603 exc instanceof OBJECT_NOT_EXIST) { 1604 1605 1610 resourceStates.set(0,ResourceStatus.Completed); 1611 exceptionThrownTryAgain = false; 1612 1613 } else if (exc instanceof NotPrepared) { 1614 1615 _logger.log(Level.SEVERE,"jts.exception_on_resource_operation", 1622 new java.lang.Object [] { exc.toString(), 1623 "commit one phase"}); 1624 String msg = LogFormatter.getLocalizedMessage(_logger, 1625 "jts.exception_on_resource_operation", 1626 new java.lang.Object [] { exc.toString(), 1627 "commit one phase"}); 1628 throw new org.omg.CORBA.INTERNAL (msg); 1629 1630 } else if (!(exc instanceof TRANSIENT) && 1631 !(exc instanceof COMM_FAILURE)) { 1632 1633 _logger.log(Level.SEVERE,"jts.exception_on_resource_operation", 1637 new java.lang.Object [] { exc.toString(), 1638 "commit one phase"}); 1639 String msg = LogFormatter.getLocalizedMessage(_logger, 1640 "jts.exception_on_resource_operation", 1641 new java.lang.Object [] { exc.toString(), 1642 "commit one phase"}); 1643 throw new org.omg.CORBA.INTERNAL (msg); 1644 1645 } else if (commitRetriesLeft > 0 || infiniteRetry) { 1646 1647 if (!infiniteRetry) { 1650 commitRetriesLeft--; 1651 } 1652 1653 try { 1654 Thread.sleep(Configuration.COMMIT_RETRY_WAIT); 1655 } catch (Throwable e) {} 1656 1657 } else { 1658 1659 _logger.log(Level.SEVERE,"jts.retry_limit_exceeded", 1674 new java.lang.Object [] { new Integer (commitRetries), 1675 "commitOnePhase"}); 1676 String msg = LogFormatter.getLocalizedMessage(_logger, 1677 "jts.retry_limit_exceeded", 1678 new java.lang.Object [] { 1679 new Integer (commitRetries),"commitOnePhase"}); 1680 throw new org.omg.CORBA.INTERNAL (msg); 1681 } 1682 } } 1685 1688 if (heuristicRaisedSetStatus) { 1689 resourceStates.set(0,ResourceStatus.Heuristic); 1690 if (logRecord != null) { 1691 if (!(currResource instanceof OTSResourceImpl)) { 1693 if (heuristicLogSection == null) 1694 heuristicLogSection = 1695 logRecord.createSection(HEURISTIC_LOG_SECTION_NAME); 1696 logRecord.addObject(heuristicLogSection,currResource); 1697 } 1698 } 1699 } else { 1700 1703 resourceStates.set(0,ResourceStatus.Completed); 1704 if (isProxy) { 1705 currResource._release(); 1706 } 1707 } 1708 1709 1713 if (heuristicExceptionFlowForget) { 1714 distributeForget(commitRetries, infiniteRetry, heuristicMixed); 1715 } 1717 1718 if (rollback_occurred) { 1719 throw new TRANSACTION_ROLLEDBACK(0, 1720 CompletionStatus.COMPLETED_YES); 1721 } 1722 1723 } 1725 1726 1737 } 1739 1740 | Popular Tags |