1 23 24 28 37 38 60 package com.sun.jts.CosTransactions; 61 62 import java.util.*; 63 64 import org.omg.CORBA.*; 65 import org.omg.CosTransactions.*; 66 67 import com.sun.jts.otsidl.*; 68 import java.util.logging.Logger ; 69 import java.util.logging.Level ; 70 import com.sun.logging.LogDomains; 71 import com.sun.jts.utils.LogFormatter; 72 73 89 90 97 class SubCoordinator extends CoordinatorImpl { 98 String name = null; 99 RegisteredResources participants = null; 100 SuperiorInfo superInfo = null; 101 NestingInfo nestingInfo = null; 102 TransactionState tranState = null; 103 CompletionHandler terminator = null; 104 boolean registered = false; 105 boolean root = true; 106 boolean rollbackOnly = false; 107 boolean dying = false; 108 boolean temporary = false; 109 int hash = 0; 110 113 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 114 115 116 130 SubCoordinator(GlobalTID parentGlobalTID, Long parentLocalTID, 131 CoordinatorImpl[] ancestors) throws LogicErrorException { 132 133 137 tranState = new TransactionState(parentLocalTID, parentGlobalTID); 138 139 142 superInfo = new SuperiorInfo(tranState.localTID, 143 tranState.globalTID, null, null); 144 145 147 name = superInfo.globalTID.toString(); 148 149 151 hash = superInfo.globalTID.hashCode(); 152 153 155 nestingInfo = new NestingInfo(ancestors); 156 157 160 participants = null; 161 162 164 root = true; 165 registered = true; 166 rollbackOnly = false; 167 dying = false; 168 temporary = false; 169 terminator = null; 170 171 174 if (!tranState.setState(TransactionState.STATE_ACTIVE)) { 175 LogicErrorException exc = 176 new LogicErrorException( 177 LogFormatter.getLocalizedMessage(_logger, 178 "jts.invalid_state_change")); 179 throw exc; 180 } else { 181 RecoveryManager.addCoordinator(tranState.globalTID, 183 tranState.localTID, this, 0); 184 } 185 } 186 187 207 SubCoordinator(GlobalTID globalTID, Coordinator superior, 208 boolean temporary, CoordinatorImpl[] ancestors) 209 throws LogicErrorException { 210 211 215 tranState = new TransactionState(globalTID,null); 216 217 220 superInfo = new SuperiorInfo(tranState.localTID, 221 globalTID, superior, null); 222 223 225 name = superInfo.globalTID.toString(); 226 227 229 hash = superInfo.globalTID.hashCode(); 230 231 233 nestingInfo = new NestingInfo(ancestors); 234 235 238 participants = null; 239 240 242 root = false; 243 registered = false; 244 rollbackOnly = false; 245 dying = false; 246 this.temporary = temporary; 247 terminator = null; 248 249 252 if (!tranState.setState(TransactionState.STATE_ACTIVE)) { 253 LogicErrorException exc = 254 new LogicErrorException( 255 LogFormatter.getLocalizedMessage(_logger, 256 "jts.invalid_state_change")); 257 throw exc; 258 } else if (!RecoveryManager.addCoordinator(globalTID, 259 tranState.localTID, 260 this, 0)) { 261 LogicErrorException exc = 262 new LogicErrorException( 263 LogFormatter.getLocalizedMessage(_logger, 264 "jts.transaction_id_already_in_use")); 265 throw exc; 266 } 267 } 268 269 278 public void finalize() { 279 280 282 dying = true; 283 284 287 int state = TransactionState.STATE_ROLLED_BACK; 288 if (tranState != null && !temporary) { 289 state = tranState.state; 290 } 291 292 switch (state) { 293 294 298 case TransactionState.STATE_ACTIVE : 299 rollback(true); 300 break; 301 302 304 case TransactionState.STATE_COMMITTED : 305 case TransactionState.STATE_ROLLED_BACK : 306 if( tranState != null ) tranState.finalize(); 307 if( superInfo != null ) superInfo.finalize(); 308 if( nestingInfo != null ) nestingInfo.finalize(); 309 if( participants != null ) participants.finalize(); 310 311 tranState = null; 312 superInfo = null; 313 nestingInfo = null; 314 participants = null; 315 terminator = null; 316 name = null; 317 break; 318 319 322 default : 323 break; 324 } 325 } 326 327 336 synchronized public Status get_status() { 337 338 Status result = Status.StatusUnknown; 339 340 if (tranState != null) { 341 342 switch (tranState.state) { 343 344 347 case TransactionState.STATE_ACTIVE : 348 if (rollbackOnly) { 349 result = Status.StatusMarkedRollback; 350 } else { 351 result = Status.StatusActive; 352 } 353 break; 354 355 358 case TransactionState.STATE_PREPARED_SUCCESS : 359 case TransactionState.STATE_PREPARED_FAIL : 360 case TransactionState.STATE_PREPARED_READONLY : 361 result = Status.StatusPrepared; 362 break; 363 364 367 case TransactionState.STATE_NONE : 368 result = Status.StatusNoTransaction; 369 break; 370 case TransactionState.STATE_PREPARING : 371 result = Status.StatusPreparing; 372 break; 373 case TransactionState.STATE_COMMITTING : 374 result = Status.StatusCommitting; 375 break; 376 case TransactionState.STATE_COMMITTED : 377 result = Status.StatusCommitted; 378 break; 379 case TransactionState.STATE_ROLLING_BACK : 380 result = Status.StatusRollingBack; 381 break; 382 case TransactionState.STATE_ROLLED_BACK : 383 result = Status.StatusRolledBack; 384 break; 385 386 388 default : 389 result = Status.StatusUnknown; 390 break; 391 } 392 } else { 393 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 394 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 395 throw exc; 396 } 397 398 return result; 399 } 400 401 414 synchronized public Status get_parent_status() throws SystemException { 415 416 Status result = Status.StatusNoTransaction; 417 418 421 if (tranState != null) { 422 CoordinatorImpl parent = nestingInfo.getParent(false); 423 if (parent != null) { 424 result = parent.get_status(); 425 } 426 } else { 427 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 428 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 429 throw exc; 430 } 431 432 return result; 433 } 434 435 448 synchronized public Status get_top_level_status() throws SystemException { 449 450 453 Status result = Status.StatusNoTransaction; 454 455 if (tranState != null) { 456 CoordinatorImpl topLevel = nestingInfo.getTopLevel(); 457 if (topLevel != null) { 458 result = topLevel.get_status(); 459 } 460 } else { 461 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 462 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 463 throw exc; 464 } 465 466 return result; 467 } 468 469 487 synchronized public boolean is_same_transaction(Coordinator other) 488 throws SystemException { 489 490 boolean result = false; 491 492 494 if (name != null) { 495 result = name.equals(other.get_transaction_name()); 496 } else { 497 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 498 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 499 throw exc; 500 } 501 502 return result; 503 } 504 505 522 synchronized public boolean is_related_transaction(Coordinator other) 523 throws SystemException { 524 525 528 boolean result = false; 529 if (tranState != null) { 530 CoordinatorImpl topLevel = nestingInfo.getTopLevel(); 531 if (topLevel != null) { 532 result = other.is_descendant_transaction(topLevel.object()); 533 } 534 } else { 535 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 536 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 537 throw exc; 538 } 539 540 return result; 541 } 542 543 557 public boolean is_ancestor_transaction(Coordinator other) 558 throws SystemException { 559 560 boolean result = false; 561 if (tranState != null) { 562 result = other.is_descendant_transaction(this.object()); 563 } else { 564 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 565 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 566 throw exc; 567 } 568 569 return result; 570 } 571 572 586 synchronized public boolean is_descendant_transaction(Coordinator other) 587 throws SystemException { 588 589 592 boolean result = false; 593 if (tranState != null) { 594 if (is_same_transaction(other)) { 595 result = true; 596 } else { 597 result = nestingInfo.isDescendant(other); 600 } 601 } else { 602 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 603 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 604 throw exc; 605 } 606 607 return result; 608 } 609 610 625 public boolean is_top_level_transaction() { 626 627 boolean result = false; 628 if (tranState == null) { 629 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 630 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 631 throw exc; 632 } 633 634 return result; 635 } 636 637 647 synchronized public int hash_transaction() { 648 649 int result = hash; 650 651 if (tranState == null) { 652 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 653 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 654 throw exc; 655 } 656 657 return result; 658 } 659 660 672 synchronized public int hash_top_level_tran() throws SystemException { 673 674 int result = 0; 675 if (tranState != null) { 676 CoordinatorImpl topLevel = nestingInfo.getTopLevel(); 677 if (topLevel != null) { 678 result = topLevel.hash_transaction(); 679 } 680 } else { 681 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 682 MinorCode.Completed, CompletionStatus.COMPLETED_NO); 683 throw exc; 684 } 685 686 return result; 687 } 688 689 712 synchronized public RecoveryCoordinator register_resource(Resource res) 713 throws SystemException, Inactive, TRANSACTION_ROLLEDBACK { 714 715 RecoveryCoordinator result = null; 716 717 720 if (tranState == null || 721 tranState.state != TransactionState.STATE_ACTIVE) { 722 Inactive exc = new Inactive(); 723 throw exc; 724 } 725 726 728 if (rollbackOnly) { 729 TRANSACTION_ROLLEDBACK exc = 730 new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO); 731 throw exc; 732 } 733 734 738 CoordinatorImpl topLevel = nestingInfo.getTopLevel(); 739 740 743 try { 744 result = topLevel.register_resource(res); 745 } catch (SystemException exc) { 746 throw (SystemException) exc.fillInStackTrace(); 747 } catch (Inactive exc) { 748 throw (Inactive) exc.fillInStackTrace(); 749 } 750 751 754 boolean subAwareRes = 755 res._is_a(SubtransactionAwareResourceHelper.id()); 756 757 761 if (subAwareRes) { 762 763 769 if (!registered) { 770 771 775 CoordinatorResourceImpl cImpl = 776 new CoordinatorResourceImpl(superInfo.globalTID, 777 this, true); 778 779 782 try { 783 CoordinatorResource cRes = cImpl.object(); 784 superInfo.superior.register_subtran_aware(cRes); 785 superInfo.setResource(cRes); 786 registered = true; 787 } catch (Throwable exc) { 788 cImpl.destroy(); 791 792 795 if (exc instanceof OBJECT_NOT_EXIST) { 796 TRANSACTION_ROLLEDBACK ex2 = 797 new TRANSACTION_ROLLEDBACK( 798 0, CompletionStatus.COMPLETED_NO); 799 throw ex2; 800 } 801 802 if (exc instanceof Inactive) { 803 throw (Inactive) exc; 804 } 805 806 if (exc instanceof SystemException) { 807 throw (SystemException) exc; 808 } 809 810 812 INTERNAL ex2 = new INTERNAL(MinorCode.NotRegistered, 813 CompletionStatus.COMPLETED_NO); 814 throw ex2; 815 } 816 } 817 818 822 if (participants == null) { 823 participants = new RegisteredResources(null, this); 824 } 825 826 830 participants.addRes((Resource)res._duplicate()); 831 temporary = false; 832 } 833 834 return result; 835 } 836 837 857 synchronized public void register_subtran_aware( 858 SubtransactionAwareResource sares) 859 throws SystemException, Inactive, TRANSACTION_ROLLEDBACK { 860 861 864 if (tranState == null || 865 tranState.state != TransactionState.STATE_ACTIVE) { 866 Inactive exc = new Inactive(); 867 throw exc; 868 } 869 870 872 if (rollbackOnly) { 873 TRANSACTION_ROLLEDBACK exc = 874 new TRANSACTION_ROLLEDBACK(0, CompletionStatus.COMPLETED_NO); 875 throw exc; 876 } 877 878 883 if (!registered) { 884 885 889 CoordinatorResourceImpl cImpl = 890 new CoordinatorResourceImpl(superInfo.globalTID, this, true); 891 892 895 try { 896 CoordinatorResource cRes = cImpl.object(); 897 superInfo.superior.register_subtran_aware(cRes); 898 superInfo.setResource(cRes); 899 registered = true; 900 } catch(Throwable exc) { 901 cImpl.destroy(); 903 904 907 if (exc instanceof OBJECT_NOT_EXIST) { 908 TRANSACTION_ROLLEDBACK ex2 = 909 new TRANSACTION_ROLLEDBACK( 910 0, CompletionStatus.COMPLETED_NO); 911 throw ex2; 912 } 913 914 if (exc instanceof Inactive) { 915 throw (Inactive) exc; 916 } 917 918 if (exc instanceof SystemException) { 919 throw (SystemException) exc; 920 } 921 922 924 INTERNAL ex2 = new INTERNAL(MinorCode.NotRegistered, 925 CompletionStatus.COMPLETED_NO); 926 throw ex2; 927 } 928 } 929 930 933 if (participants == null) { 934 participants = new RegisteredResources(null, this); 935 } 936 937 942 participants.addRes((Resource)sares._duplicate()); 943 temporary = false; 944 } 945 946 958 synchronized public void rollback_only() throws Inactive { 959 960 if (tranState.state != TransactionState.STATE_ACTIVE) { 961 Inactive exc = new Inactive(); 962 throw exc; 963 } else { 964 rollbackOnly = true; 966 } 967 } 968 969 980 synchronized public String get_transaction_name() { 981 982 String result = null; 983 if (tranState != null) { 984 result = new String (name); 985 } else { 986 INVALID_TRANSACTION exc = new INVALID_TRANSACTION( 987 MinorCode.Completed, 988 CompletionStatus.COMPLETED_NO); 989 990 throw exc; 991 } 992 993 return result; 994 } 995 996 1009 synchronized public Control create_subtransaction() throws Inactive { 1010 1011 Control result = null; 1012 1013 1016 if (tranState == null || 1017 tranState.state != TransactionState.STATE_ACTIVE) { 1018 Inactive exc = new Inactive(); 1019 throw exc; 1020 } 1021 1022 1027 CoordinatorImpl[] thisAncestors = nestingInfo.getAncestors(); 1028 CoordinatorImpl[] ancestors = 1029 new CoordinatorImpl[thisAncestors.length + 1]; 1030 System.arraycopy(thisAncestors, 0, ancestors, 1, thisAncestors.length); 1031 ancestors[0] = this; 1032 1033 1039 SubCoordinator child = null; 1040 TerminatorImpl terminator = null; 1041 try { 1042 child = new SubCoordinator(superInfo.globalTID, 1043 superInfo.localTID, ancestors); 1044 1045 1049 terminator = new TerminatorImpl(child, true); 1050 1051 1054 result = new ControlImpl(terminator, child, 1055 new GlobalTID(child.getGlobalTID()), 1056 new Long (child.getLocalTID())).object(); 1057 } catch (Throwable exc) { 1058 Inactive ex2 = new Inactive(); 1059 throw ex2; 1060 } 1061 1062 1065 nestingInfo.addChild(child); 1066 1067 return result; 1068 } 1069 1070 1086 public otid_t getGlobalTID() { 1087 1088 otid_t result = null; 1089 result = superInfo.globalTID.realTID; 1090 1091 return result; 1092 } 1093 1094 1105 public long getLocalTID() { 1106 1107 long result = superInfo.localTID.longValue(); 1108 return result; 1109 } 1110 1111 1129 synchronized CoordinatorImpl replyAction(int[] action) 1130 throws SystemException { 1131 1132 CoordinatorImpl result = null; 1133 action[0] = CoordinatorImpl.doNothing; 1134 1135 1139 if (!root && nestingInfo.replyCheck()) { 1140 action[0] = CoordinatorImpl.activeChildren; 1141 1142 1145 } else { 1146 1147 1150 if (!registered) { 1151 if (participants != null && participants.involved()) { 1152 INTERNAL ex2 = new INTERNAL(MinorCode.NotRegistered, 1153 CompletionStatus.COMPLETED_NO); 1154 throw ex2; 1155 } else { 1156 action[0] = forgetMe; 1157 } 1158 } 1159 1160 1166 if (action[0] == doNothing && !registered) 1167 action[0] = forgetMe; 1168 } 1169 1170 1172 result = null; 1173 1174 return result; 1175 } 1176 1177 1186 synchronized Long setPermanent() { 1187 1188 Long result = superInfo.localTID; 1189 temporary = false; 1190 1191 return result; 1192 } 1193 1194 1203 synchronized public boolean isRollbackOnly() { 1204 1205 boolean result = rollbackOnly; 1206 return result; 1207 } 1208 1209 1218 synchronized boolean isActive() { 1219 1220 boolean result = (tranState.state == TransactionState.STATE_ACTIVE); 1221 return result; 1222 } 1223 1224 1233 synchronized boolean hasRegistered() { 1234 1235 boolean result = registered; 1236 return result; 1237 } 1238 1239 1248 synchronized public TransIdentity[] getAncestors() { 1249 1250 CoordinatorImpl[] coords = nestingInfo.getAncestors(); 1251 1252 TransIdentity[] result = new TransIdentity[coords.length]; 1253 for (int i = 0; i < coords.length; i++) { 1254 try { 1255 result[i] = new TransIdentity(coords[i].object(), null, 1256 coords[i].getGlobalTID()); 1257 } catch (Throwable exc) {} 1258 } 1259 1260 return result; 1261 } 1262 1263 1273 synchronized boolean addChild(CoordinatorImpl child) { 1274 1275 boolean result = nestingInfo.addChild(child); 1276 return result; 1277 } 1278 1279 1291 synchronized boolean removeChild(CoordinatorImpl child) { 1292 1293 boolean result = false; 1294 1295 1299 result = nestingInfo.removeChild(child); 1300 1301 1305 if (temporary && !registered && 1306 !(participants != null && participants.involved()) && 1307 !(nestingInfo != null && nestingInfo.numChildren() > 0)) { 1308 1309 1313 CoordinatorImpl parent = nestingInfo.getParent(true); 1314 cleanUpEmpty(parent); 1315 } 1316 1317 return result; 1318 } 1319 1320 1334 static String [] resultName = { "Commit", "Rollback", "Read-only" }; 1335 1336 synchronized Vote prepare() throws INVALID_TRANSACTION { 1337 1338 Vote result = Vote.VoteRollback; 1339 int newState = TransactionState.STATE_PREPARED_FAIL; 1340 1341 1343 1347 if (root && nestingInfo.numChildren() != 0) { 1348 INVALID_TRANSACTION exc = 1349 new INVALID_TRANSACTION(MinorCode.UnfinishedSubtransactions, 1350 CompletionStatus.COMPLETED_NO); 1351 throw exc; 1352 } 1353 1354 1356 if (!tranState.setState(TransactionState.STATE_PREPARING)) { 1357 return Vote.VoteRollback; 1358 } 1359 1360 1362 if (rollbackOnly) { 1363 1364 1367 if (!tranState.setState(TransactionState.STATE_PREPARED_FAIL)) { 1368 return Vote.VoteRollback; 1369 } 1370 } else { 1371 newState = TransactionState.STATE_PREPARED_SUCCESS; 1372 result = Vote.VoteCommit; 1373 } 1374 1375 1378 if (!tranState.setState(newState)) { 1379 result = Vote.VoteRollback; 1380 } 1381 1382 return result; 1383 } 1384 1385 1395 void commit() { 1396 1397 Coordinator parent = null; 1398 1399 1402 synchronized (this) { 1403 1404 1406 if (!tranState.setState(TransactionState.STATE_COMMITTING)) { 1407 _logger.log(Level.SEVERE,"jts.transaction_wrong_state", 1408 "commit"); 1409 String msg = LogFormatter.getLocalizedMessage(_logger, 1410 "jts.transaction_wrong_state", 1411 new java.lang.Object [] { 1412 "commit"}); 1413 throw new org.omg.CORBA.INTERNAL (msg); 1414 } 1415 1416 1418 parent = nestingInfo.getParent(false).object(); 1419 1420 1422 } 1423 1424 1427 if (participants != null) { 1428 try { 1429 participants.distributeSubcommit(parent); 1430 } catch (Throwable exc) { 1431 _logger.log(Level.SEVERE,"jts.exception_on_resource_operation", 1432 new java.lang.Object [] { exc.toString(), 1433 "commit"}); 1434 String msg = LogFormatter.getLocalizedMessage(_logger, 1435 "jts.exception_on_resource_operation", 1436 new java.lang.Object [] 1437 {exc.toString(), 1438 "commit"}); 1439 throw new org.omg.CORBA.INTERNAL (msg); 1440 } 1441 } 1442 1443 1445 synchronized (this) { 1446 1447 1450 if (!tranState.setState(TransactionState.STATE_COMMITTED)) { 1451 _logger.log(Level.SEVERE,"jts.transaction_wrong_state", 1452 "commit"); 1453 String msg = LogFormatter.getLocalizedMessage(_logger, 1454 "jts.transaction_wrong_state", 1455 new java.lang.Object [] { 1456 "commit"}); 1457 throw new org.omg.CORBA.INTERNAL (msg); 1458 } 1459 1460 1462 nestingInfo.removeFromParent(this); 1463 1464 1478 if (terminator != null) { 1479 terminator.setCompleted(false, false); 1480 } 1481 1482 1486 RecoveryManager.removeCoordinator(superInfo.globalTID, 1487 superInfo.localTID, false); 1488 destroy(); 1489 1490 1491 1492 1493 1494 } 1495 } 1496 1497 1507 void rollback(boolean force) { 1508 1509 1511 synchronized (this) { 1512 1513 1515 if (tranState == null) { 1516 return; 1517 } 1518 1519 1523 if (!force && 1524 ((tranState.state == 1525 TransactionState.STATE_PREPARED_SUCCESS) || 1526 (!tranState.setState(TransactionState.STATE_ROLLING_BACK)) 1527 )) { 1528 return; 1529 } 1530 1531 1536 if (!temporary && 1537 !tranState.setState(TransactionState.STATE_ROLLING_BACK)) { 1538 } 1540 1541 1545 if (nestingInfo != null) { 1546 nestingInfo.rollbackFamily(); 1547 } 1548 1549 1551 } 1552 1553 1556 if (participants != null) { 1557 participants.distributeSubrollback(); 1558 } 1559 1560 1562 synchronized(this) { 1563 1564 1566 if (!temporary && 1568 !tranState.setState(TransactionState.STATE_ROLLED_BACK)) { 1569 } 1571 1572 nestingInfo.removeFromParent(this); 1573 1574 1588 if (terminator != null) { 1589 terminator.setCompleted(true, false); 1590 } 1591 1592 1596 RecoveryManager.removeCoordinator(superInfo.globalTID, 1597 superInfo.localTID, false); 1598 1599 if (!dying) { 1600 destroy(); 1601 } 1602 1603 1604 1605 1606 } 1607 } 1608 1609 1626 synchronized public void register_synchronization(Synchronization sync) 1627 throws Inactive, SynchronizationUnavailable { 1628 1629 1632 if (tranState == null || 1633 tranState.state != TransactionState.STATE_ACTIVE) { 1634 Inactive exc = new Inactive(); 1635 throw exc; 1636 } 1637 1638 1641 CoordinatorImpl topLevel = nestingInfo.getTopLevel(); 1642 topLevel.register_synchronization(sync); 1643 } 1644 1645 1659 synchronized void setTerminator(CompletionHandler term) { 1660 terminator = term; 1661 } 1662 1663 1672 Coordinator getParent() { 1673 1674 Coordinator result = nestingInfo.getParent(false).object(); 1675 return result; 1676 } 1677 1678 1687 Coordinator getSuperior() { 1688 1689 Coordinator result = superInfo.superior; 1690 return result; 1691 } 1692 1693 1703 1724 1725 1735 CompletionHandler getTerminator() { 1736 1737 CompletionHandler result = terminator; 1738 return result; 1739 } 1740 1741 private static Any emptyData = null; 1742 1743 1756 synchronized public PropagationContext get_txcontext() throws Unavailable { 1757 1758 1761 if (tranState == null || 1762 tranState.state != TransactionState.STATE_ACTIVE || 1763 rollbackOnly) { 1764 Unavailable exc = new Unavailable(); 1765 throw exc; 1766 } 1767 1768 1776 long timeLeft = TimeoutManager.timeLeft(superInfo.localTID); 1777 int timeout = 0; 1778 if (timeLeft > 0) { 1779 timeout = (int) timeLeft / 1000; 1780 } else if (timeLeft == 0) { 1781 1785 TimeoutManager.timeoutCoordinator(superInfo.localTID, 1786 TimeoutManager.ACTIVE_TIMEOUT); 1787 TRANSACTION_ROLLEDBACK exc = 1788 new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO); 1789 throw exc; 1790 } 1791 1792 1795 TransIdentity current = new TransIdentity(this.object(), 1796 null, 1797 superInfo.globalTID.realTID); 1798 TransIdentity[] parents = getAncestors(); 1799 1800 1802 if (emptyData == null) { 1803 emptyData = Configuration.getORB().create_any(); 1804 emptyData.insert_boolean(false); 1805 } 1806 1807 PropagationContext result = new PropagationContext(timeout, current, 1808 parents, emptyData); 1809 1810 return result; 1811 } 1812 1813 1822 void cleanUpEmpty(CoordinatorImpl parent) { 1823 1824 1826 try { 1827 rollback(true); 1828 } catch (Throwable exc) {} 1829 1830 1836 if (parent != null) { 1837 parent.removeChild(this); 1838 } 1839 } 1840 1841 1851 boolean commitOnePhase() { 1852 1853 1860 Vote v = this.prepare(); 1861 1862 if (v == Vote.VoteCommit) { 1863 this.commit(); 1864 } else if (v == Vote.VoteReadOnly) { 1865 } else { 1867 this.rollback(true); 1868 } 1869 1870 return true; 1871 } 1872 1873 1884 public int hashCode() { 1885 return hash; 1886 } 1887 1888 1909 public boolean equals(java.lang.Object other) throws INVALID_TRANSACTION { 1910 1911 1913 if (this == other) { 1914 return true; 1915 } 1916 1917 1919 otid_t otherTID = null; 1920 1921 if (other instanceof CoordinatorImpl) { 1922 if (other instanceof SubCoordinator) { 1926 otherTID = ((SubCoordinator)other).superInfo.globalTID.realTID; 1927 } 1928 } else if (other instanceof org.omg.CORBA.Object ) { 1929 1930 1933 try { 1934 JCoordinator jcoord = 1935 JCoordinatorHelper.narrow((org.omg.CORBA.Object ) other); 1936 otherTID = jcoord.getGlobalTID(); 1937 } catch (BAD_PARAM exc) { 1938 1939 1945 try { 1946 Coordinator coord = 1947 CoordinatorHelper.narrow((org.omg.CORBA.Object )other); 1948 PropagationContext pc = coord.get_txcontext(); 1949 otherTID = pc.current.otid; 1950 } catch (BAD_PARAM ex2) { 1951 } catch (Unavailable ex2) { 1954 1959 INVALID_TRANSACTION ex3 = 1960 new INVALID_TRANSACTION(MinorCode.CompareFailed, 1961 CompletionStatus.COMPLETED_NO); 1962 throw ex3; 1963 } 1964 } 1965 } 1966 1967 1969 if (otherTID != null) { 1970 return superInfo.globalTID.equals(otherTID); 1971 } 1972 1973 return false; 1974 } 1975} 1976 | Popular Tags |