[jboss-svn-commits] JBL Code SVN: r37662 - in labs/jbosstm/branches/JBOSSTS_4_15_0_Final: ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator and 22 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 24 09:45:06 EDT 2011
Author: tomjenkinson
Date: 2011-10-24 09:45:05 -0400 (Mon, 24 Oct 2011)
New Revision: 37662
Removed:
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/DummyRemoteException.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/DummyRemoteException.java
Modified:
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoreEnvironmentBean.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoreEnvironmentBeanMBean.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TxControl.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/logging/arjunaI18NLogger.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/TxControlUnitTest.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/NodeNameXAResourceOrphanFilter.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/SubordinateJTAXAResourceOrphanFilter.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/XATerminatorImple.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/subordinate/jca/SubordinateAtomicAction.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/utils/XAUtils.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/common/JTAEnvironmentBean.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XATxConverter.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XidImple.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/arjuna/ats/jta/xa/XATxConverterTest.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/RecoveryXAResource.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/RecoveryTest.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XAResourceOrphanFilterTest.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/XAUtilsUnitTest.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/xidcheck.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/RecoveryXAResource.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTS/jts/classes/com/arjuna/ats/jts/utils/Utility.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/ExampleDistributedJTATestCase.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResourceRecovery.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestSynchronization.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LocalServer.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/RemoteServer.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxySynchronization.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResource.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResourceRecovery.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ServerImpl.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResource.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestSynchronization.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProvider.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/RemoteServer.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxySynchronization.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResourceRecovery.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/qa/tests/src/org/jboss/jbossts/qa/CrashRecovery13Clients/Test02.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/qa/tests/src/org/jboss/jbossts/qa/CrashRecovery13Impls/RecoveryXAResource.java
Log:
JBTM-895 updated to allow the node name to be encoded as a String
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoreEnvironmentBean.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoreEnvironmentBean.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoreEnvironmentBean.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -42,8 +42,7 @@
private volatile String varDir = System.getProperty("user.dir") + File.separator + "var" + File.separator + "tmp";
@FullPropertyName(name = "com.arjuna.ats.arjuna.nodeIdentifier")
- private volatile int nodeIdentifier = 1;
- private volatile boolean nodeIdentifierSet = false;
+ private volatile String nodeIdentifier = null;
@FullPropertyName(name = "com.arjuna.ats.internal.arjuna.utils.SocketProcessIdPort")
private volatile int socketProcessIdPort = 0;
@@ -92,50 +91,20 @@
*
* @return the Node Identifier.
*/
- public int getNodeIdentifier()
+ public String getNodeIdentifier()
{
return nodeIdentifier;
}
/**
- * Sets the node identifier. Should be uniq amongst all instances that share resource managers or an objectstore.
- *
- * @param nodeIdentifier the Node Identifier.
- * @throws CoreEnvironmentBeanException
- */
- public void setNodeIdentifier(int nodeIdentifier) throws CoreEnvironmentBeanException
- {
- if (nodeIdentifier < 1) {
- throw new CoreEnvironmentBeanException(tsLogger.i18NLogger.get_node_identifier_invalid(nodeIdentifier));
- }
-
- if (this.nodeIdentifierSet) {
- throw new CoreEnvironmentBeanException(tsLogger.i18NLogger.get_node_identifier_reset_attempt());
- }
- this.nodeIdentifier = nodeIdentifier;
- this.nodeIdentifierSet = true;
- }
-
- /**
* Sets the node identifier. Should be uniq amongst all instances that share resource managers or an objectstore. It should be set as the String value of an integer.
*
* @param nodeIdentifier the Node Identifier.
* @throws CoreEnvironmentBeanException
- * @deprecated
*/
public void setNodeIdentifier(String nodeIdentifierAsString)
{
- Integer nodeIdentifier = null;
-
- try {
- nodeIdentifier = Integer.valueOf(nodeIdentifierAsString);
- setNodeIdentifier(nodeIdentifier);
- } catch (NumberFormatException nfe) {
- throw new RuntimeException(tsLogger.i18NLogger.get_node_identifier_invalid(nodeIdentifier));
- } catch (CoreEnvironmentBeanException e) {
- throw new RuntimeException(e);
- }
-
+ this.nodeIdentifier = nodeIdentifierAsString;
}
/**
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoreEnvironmentBeanMBean.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoreEnvironmentBeanMBean.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoreEnvironmentBeanMBean.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -29,7 +29,7 @@
{
String getVarDir();
- int getNodeIdentifier();
+ String getNodeIdentifier();
int getSocketProcessIdPort();
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TxControl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TxControl.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TxControl.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -160,14 +160,14 @@
return readonlyOptimisation;
}
- public static final int getXANodeName()
+ public static final String getXANodeName()
{
return xaNodeName;
}
- public static void setXANodeName(int name)
+ public static void setXANodeName(String name)
{
- if (name < 1) {
+ if (name.getBytes().length > 36) {
tsLogger.i18NLogger.warn_coordinator_toolong();
throw new IllegalArgumentException();
@@ -229,7 +229,7 @@
private static TransactionStatusManager transactionStatusManager = null;
- static int xaNodeName = -1;
+ static String xaNodeName = null;
static int _defaultTimeout = 60; // 60 seconds
@@ -261,9 +261,55 @@
- xaNodeName = arjPropertyManager.getCoreEnvironmentBean().getNodeIdentifier();
+ String env = arjPropertyManager.getCoreEnvironmentBean().getNodeIdentifier();
+ boolean writeNodeName = false;
+ if (env != null)
+ {
+ xaNodeName = env;
+ }
+ else {
+ /*
+ * In the past we used a Uid as the default node name. However, this is too
+ * big for the way in which we use it within Xids now that we also support
+ * ipv6. Hence the need to limit the size of a node name to 10 bytes.
+ */
+ String nodeName = DEFAULT_NODE_NAME + Utility.getpid();
+
+ tsLogger.i18NLogger.warn_coordinator_TxControl_1(nodeName);
+
+ xaNodeName = nodeName;
+
+ writeNodeName = true;
+ }
+
+ if (xaNodeName.getBytes().length > NODE_NAME_SIZE) {
+ String nodeName = DEFAULT_NODE_NAME + Utility.getpid();
+
+ tsLogger.i18NLogger.warn_coordinator_TxControl_2(nodeName);
+
+ xaNodeName = nodeName;
+
+ writeNodeName = true;
+ }
+
+ if ((env != null) && (env.indexOf('-') != -1)) {
+ String nodeName = DEFAULT_NODE_NAME + Utility.getpid();
+
+ tsLogger.i18NLogger.warn_coordinator_TxControl_3(nodeName);
+
+ xaNodeName = nodeName;
+
+ writeNodeName = true;
+ }
+
+ if (writeNodeName)
+ {
+ arjPropertyManager.getCoreEnvironmentBean().setNodeIdentifier( new String(xaNodeName) );
+ }
+
+
_enableTSM = arjPropertyManager.getCoordinatorEnvironmentBean().isTransactionStatusManagerEnable();
// TODO -- add this check to respect the environment setting for Environment.START_DISABLED?
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/logging/arjunaI18NLogger.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/logging/arjunaI18NLogger.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/logging/arjunaI18NLogger.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -578,7 +578,7 @@
@LogMessage(level = WARN)
public void warn_coordinator_notrunning();
- @Message(id = 12138, value = "Node name cannot exceed 64 bytes!", format = MESSAGE_FORMAT)
+ @Message(id = 12138, value = "Node name cannot exceed 36 bytes!", format = MESSAGE_FORMAT)
@LogMessage(level = WARN)
public void warn_coordinator_toolong();
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/TxControlUnitTest.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/TxControlUnitTest.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/TxControlUnitTest.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -64,10 +64,10 @@
assertEquals(TxControl.getMaintainHeuristics(), arjPropertyManager.getCoordinatorEnvironmentBean().isMaintainHeuristics());
- int nodeName = 1;
+ String nodeName = "1";
TxControl.setXANodeName(nodeName);
- assertTrue(TxControl.getXANodeName() == nodeName);
+ assertTrue(TxControl.getXANodeName().equals(nodeName));
}
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/NodeNameXAResourceOrphanFilter.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/NodeNameXAResourceOrphanFilter.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/NodeNameXAResourceOrphanFilter.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -43,12 +43,12 @@
*/
public class NodeNameXAResourceOrphanFilter implements XAResourceOrphanFilter
{
- public static final int RECOVER_ALL_NODES = 0;
+ public static final String RECOVER_ALL_NODES = "*";
@Override
public Vote checkXid(Xid xid)
{
- List<Integer> _xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodesImpl();
+ List<String> _xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
if(_xaRecoveryNodes == null || _xaRecoveryNodes.size() == 0) {
doWarning();
@@ -64,7 +64,7 @@
return Vote.ROLLBACK;
}
- int nodeName = XAUtils.getXANodeName(xid);
+ String nodeName = XAUtils.getXANodeName(xid);
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("node name of " + xid + " is " + nodeName);
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/SubordinateJTAXAResourceOrphanFilter.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/SubordinateJTAXAResourceOrphanFilter.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/SubordinateJTAXAResourceOrphanFilter.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -21,7 +21,6 @@
package com.arjuna.ats.internal.jta.recovery.arjunacore;
import java.io.IOException;
-import java.util.List;
import java.util.Stack;
import javax.transaction.xa.Xid;
@@ -33,7 +32,6 @@
import com.arjuna.ats.arjuna.state.InputObjectState;
import com.arjuna.ats.internal.arjuna.common.UidHelper;
import com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction;
-import com.arjuna.ats.jta.common.jtaPropertyManager;
import com.arjuna.ats.jta.logging.jtaLogger;
import com.arjuna.ats.jta.recovery.XAResourceOrphanFilter;
import com.arjuna.ats.jta.utils.XAHelper;
@@ -49,21 +47,15 @@
@Override
public Vote checkXid(Xid xid) {
- List<Integer> _xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodesImpl();
+ Integer nodeName = XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID());
- if (_xaRecoveryNodes == null || _xaRecoveryNodes.size() == 0) {
- jtaLogger.i18NLogger.info_recovery_noxanodes();
- return Vote.ABSTAIN;
- }
-
- int nodeName = XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID());
-
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("subordinate node name of " + xid + " is " + nodeName);
}
- if (_xaRecoveryNodes.contains(nodeName)) {
- if (transactionLog(xid)) {
+ // It does have an XID
+ if (nodeName > 0) {
+ if (transactionLog(xid, nodeName)) {
// it's owned by a logged transaction which
// will recover it top down in due course
return Vote.LEAVE_ALONE;
@@ -78,15 +70,15 @@
/**
* Is there a log file for this transaction?
*
- * @param xid
+ * @param recoveredResourceXid
* the transaction to check.
*
* @return <code>boolean</code>true if there is a log file,
* <code>false</code> if there isn't.
*/
- private boolean transactionLog(Xid xid) {
+ private boolean transactionLog(Xid recoveredResourceXid, Integer recoveredResourceNodeName) {
- XidImple theXid = new XidImple(xid);
+ XidImple theXid = new XidImple(recoveredResourceXid);
Uid u = theXid.getTransactionUid();
if (jtaLogger.logger.isDebugEnabled()) {
@@ -120,7 +112,9 @@
if (uid.notEquals(Uid.nullUid())) {
SubordinateAtomicAction tx = new SubordinateAtomicAction(uid, true);
- if (((XidImple) tx.getXid()).isSameTransaction(xid)) {
+ XidImple transactionXid = (XidImple) tx.getXid();
+ if (transactionXid.isSameTransaction(recoveredResourceXid)
+ && recoveredResourceNodeName == XATxConverter.getSubordinateNodeName(transactionXid.getXID())) {
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Found record for " + theXid);
}
@@ -134,7 +128,7 @@
jtaLogger.logger.debug("No record found for " + theXid);
}
} else {
- jtaLogger.i18NLogger.info_recovery_notaxid(XAHelper.xidToString(xid));
+ jtaLogger.i18NLogger.info_recovery_notaxid(XAHelper.xidToString(recoveredResourceXid));
}
} catch (ObjectStoreException e) {
// TODO Auto-generated catch block
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/XATerminatorImple.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/XATerminatorImple.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/XATerminatorImple.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -32,6 +32,7 @@
package com.arjuna.ats.internal.jta.transaction.arjunacore.jca;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.Set;
import java.util.Stack;
@@ -55,6 +56,7 @@
import com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions;
import com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction;
import com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple;
+import com.arjuna.ats.internal.jta.xa.XID;
import com.arjuna.ats.jta.exceptions.UnexpectedConditionException;
import com.arjuna.ats.jta.logging.jtaLogger;
import com.arjuna.ats.jta.xa.XATxConverter;
@@ -335,7 +337,7 @@
}
// if we are here, then check the object store
- return doRecover(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES, false);
+ return doRecover(null);
}
/**
@@ -350,7 +352,7 @@
* @return a list of potentially indoubt transactions or <code>null</code>.
*/
- public synchronized Xid[] doRecover (Integer parentNodeName, boolean recoverInflightTransactionsUnpreparedTransactions) throws XAException
+ public synchronized Xid[] doRecover (XidImple toRecover) throws XAException
{
/*
* Requires going through the objectstore for the states of imported
@@ -390,38 +392,37 @@
if (uid.notEquals(Uid.nullUid()))
{
-
- SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
- if (parentNodeName.equals(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES)
- || parentNodeName.equals(XATxConverter.getParentNodeName(((XidImple) saa.getXid()).getXID()))) {
- if (jtaLogger.logger.isDebugEnabled()) {
- jtaLogger.logger.debug("Found record for " + saa);
- }
- TransactionImple tx = (TransactionImple)SubordinationManager.getTransactionImporter().recoverTransaction(uid);
+ if (toRecover == null) {
+ TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
if (tx != null)
values.push(tx.baseXid());
+ } else {
+ SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
+ XidImple loadedXid = (XidImple) saa.getXid();
+ if (loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
+ Integer loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
+ if (XATxConverter.getSubordinateNodeName(toRecover.getXID()) == loadedXidSubordinateNodeName) {
+ if (Arrays.equals(loadedXid.getGlobalTransactionId(), toRecover.getGlobalTransactionId())) {
+ if (jtaLogger.logger.isDebugEnabled()) {
+ jtaLogger.logger.debug("Found record for " + saa);
+ }
+ TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
+
+ if (tx != null)
+ values.push(tx.baseXid());
+ }
+ }
+ }
}
+
}
else
finished = true;
}
while (!finished);
-
- if (recoverInflightTransactionsUnpreparedTransactions) {
- Set<SubordinateXidImple> inflightXids = ((TransactionImporterImple) SubordinationManager.getTransactionImporter()).getInflightXids();
- Iterator<SubordinateXidImple> iterator = inflightXids.iterator();
- while (iterator.hasNext()) {
- SubordinateXidImple next = iterator.next();
- if (parentNodeName.equals(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES)
- || parentNodeName.equals(XATxConverter.getParentNodeName(next.getXID()))) {
- values.push(next);
- }
- }
- }
-
if (values.size() > 0)
{
int index = 0;
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/subordinate/jca/SubordinateAtomicAction.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/subordinate/jca/SubordinateAtomicAction.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/subordinate/jca/SubordinateAtomicAction.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -52,6 +52,9 @@
com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.SubordinateAtomicAction
{
+ /**
+ * @deprecated This is only used by test code
+ */
public SubordinateAtomicAction ()
{
super(); // does start for us
@@ -87,7 +90,7 @@
{
super(timeout); // implicit start (done in base class)
- _theXid = new XidImple(xid, true);
+ _theXid = new XidImple(xid);
_activated = true;
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/utils/XAUtils.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/utils/XAUtils.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/utils/XAUtils.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -76,7 +76,7 @@
return optimize;
}
- public static final int getXANodeName (Xid xid)
+ public static final String getXANodeName (Xid xid)
{
XidImple xidImple;
if(xid instanceof XidImple) {
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/common/JTAEnvironmentBean.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/common/JTAEnvironmentBean.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/common/JTAEnvironmentBean.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -58,7 +58,7 @@
private volatile TransactionSynchronizationRegistry transactionSynchronizationRegistry = null;
@ConcatenationPrefix(prefix = "com.arjuna.ats.jta.xaRecoveryNode")
- private volatile List<Integer> xaRecoveryNodes = new ArrayList<Integer>();
+ private volatile List<String> xaRecoveryNodes = new ArrayList<String>();
@ConcatenationPrefix(prefix = "com.arjuna.ats.jta.recovery.XAResourceRecovery")
private volatile List<String> xaResourceRecoveryClassNames = new ArrayList<String>();
@@ -366,72 +366,25 @@
*
* @return the set of node identifiers for which to perform recovery.
*/
- public List<Integer> getXaRecoveryNodesImpl()
+ public List<String> getXaRecoveryNodes()
{
- return new ArrayList<Integer>(xaRecoveryNodes);
+ return new ArrayList<String>(xaRecoveryNodes);
}
- /**
- * Sets the node identifiers for which recovery will be performed.
- * The provided list will be copied, not retained.
- *
- * @param xaRecoveryNodes the set of node identifiers for which to perform recovery.
- * @deprecated
- */
- public void setXaRecoveryNodes(List<String> xaRecoveryNodes) {
- ArrayList<Integer> arrayList = new ArrayList<Integer>();
- if (xaRecoveryNodes != null) {
- Iterator<String> iterator = xaRecoveryNodes.iterator();
- while (iterator.hasNext()) {
- Integer nodeIdentifier = null;
- try {
- nodeIdentifier = Integer.valueOf(iterator.next());
- } catch (NumberFormatException nfe) {
- throw new RuntimeException(tsLogger.i18NLogger.get_node_identifier_invalid(nodeIdentifier));
- }
- if (nodeIdentifier < 1) {
- throw new RuntimeException(tsLogger.i18NLogger.get_node_identifier_invalid(nodeIdentifier));
- }
- arrayList.add(Integer.valueOf(nodeIdentifier));
- }
- }
- setXaRecoveryNodesImpl(arrayList);
- }
- /**
- * Returns the set of node identifiers for which recovery will be performed.
- * The returned list is a copy. May return an empty list, will not return null.
- *
- * Default: empty list.
- * Equivalent deprecated property prefix: com.arjuna.ats.jta.xaRecoveryNode
- *
- * @return the set of node identifiers for which to perform recovery.
- * @deprecated
- */
- public List<String> getXaRecoveryNodes()
- {
- List<String> toReturn = new ArrayList<String>();
- Iterator<Integer> iterator = xaRecoveryNodes.iterator();
- while (iterator.hasNext()) {
- toReturn.add(String.valueOf(iterator.next()));
- }
- return toReturn;
- }
-
-
/**
* Sets the node identifiers for which recovery will be performed.
* The provided list will be copied, not retained.
*
* @param xaRecoveryNodes the set of node identifiers for which to perform recovery.
*/
- public void setXaRecoveryNodesImpl(List<Integer> xaRecoveryNodes)
+ public void setXaRecoveryNodes(List<String> xaRecoveryNodes)
{
if(xaRecoveryNodes == null) {
- this.xaRecoveryNodes = new ArrayList<Integer>();
+ this.xaRecoveryNodes = new ArrayList<String>();
} else {
- this.xaRecoveryNodes = new ArrayList<Integer>(xaRecoveryNodes);
+ this.xaRecoveryNodes = new ArrayList<String>(xaRecoveryNodes);
}
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XATxConverter.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XATxConverter.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XATxConverter.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -85,21 +85,16 @@
throw new IllegalStateException(); // Uid is too long!!!!
}
- int nodeName = TxControl.getXANodeName();
- int nodeNameLengthToUse = 4;
+ String nodeName = TxControl.getXANodeName();
+ int nodeNameLengthToUse = nodeName.getBytes().length;
xid.gtrid_length = gtridUid.length+nodeNameLengthToUse;
// src, srcPos, dest, destPos, length
System.arraycopy(gtridUid, 0, xid.data, 0, gtridUid.length);
+ System.arraycopy(nodeName.getBytes(), 0, xid.data, gtridUid.length, nodeNameLengthToUse);
- int offset = gtridUid.length;
- xid.data[offset + 0] = (byte) (nodeName >>> 24);
- xid.data[offset + 1] = (byte) (nodeName >>> 16);
- xid.data[offset + 2] = (byte) (nodeName >>> 8);
- xid.data[offset + 3] = (byte) (nodeName >>> 0);
- offset = offset + 4;
-
+
if (branch.notEquals(Uid.nullUid()))
{
// bqual is uid byte form plus EIS name.
@@ -109,7 +104,7 @@
throw new IllegalStateException(); // Uid is too long!!!!
}
- int spareBqualBytes = XID.MAXBQUALSIZE - (bqualUid.length + 4 + 4);
+ int spareBqualBytes = XID.MAXBQUALSIZE - (bqualUid.length + 4);
byte[] eisName;
try {
// caution: we may truncate the byte[] to fit, so double byte encodings are best avoided.
@@ -121,12 +116,12 @@
if( eisName.length > spareBqualBytes) {
eisNameLengthToUse = spareBqualBytes;
}
- xid.bqual_length = bqualUid.length+4+4+eisNameLengthToUse;
+ xid.bqual_length = bqualUid.length+4+eisNameLengthToUse;
// src, srcPos, dest, destPos, length
+ int offset = xid.gtrid_length;
System.arraycopy (bqualUid, 0, xid.data, offset, bqualUid.length);
offset = offset + bqualUid.length;
- offset = offset + 4; // Reserve space for parent node name
offset = offset + 4; // Reserve space for subordinate node name
System.arraycopy (eisName, 0, xid.data, offset, eisNameLengthToUse);
}
@@ -158,22 +153,19 @@
return tx;
}
- public static Integer getNodeName(XID xid) {
+ public static String getNodeName(XID xid) {
// Arjuna.XID()
// don't check the formatId - it may differ e.g. JTA vs. JTS.
if (xid.formatID != FORMAT_ID && xid.formatID != 131072
&& xid.formatID != 131080) {
- return -1;
+ return null;
}
// the node name follows the Uid with no separator, so the only
// way to tell where it starts is to figure out how long the Uid is.
int offset = Uid.UID_SIZE;
- return (xid.data[offset + 0] << 24)
- + ((xid.data[offset + 1] & 0xFF) << 16)
- + ((xid.data[offset + 2] & 0xFF) << 8)
- + (xid.data[offset + 3] & 0xFF);
+ return new String(Arrays.copyOfRange(xid.data, offset, xid.gtrid_length));
}
public static void setSubordinateNodeName(XID theXid, Integer xaNodeName) {
@@ -186,8 +178,7 @@
public static Integer getSubordinateNodeName(XID xid) {
// Arjuna.XID()
// don't check the formatId - it may differ e.g. JTA vs. JTS.
- if (xid.formatID != FORMAT_ID && xid.formatID != 131072
- && xid.formatID != 131080) {
+ if (xid.formatID != FORMAT_ID) {
return -1;
}
@@ -202,34 +193,6 @@
}
-
- public static void setParentNodeName(XID theXid, Integer parentNodeName) {
- int offset = theXid.gtrid_length + Uid.UID_SIZE + 4;
- theXid.data[offset + 0] = (byte) (parentNodeName >>> 24);
- theXid.data[offset + 1] = (byte) (parentNodeName >>> 16);
- theXid.data[offset + 2] = (byte) (parentNodeName >>> 8);
- theXid.data[offset + 3] = (byte) (parentNodeName >>> 0);
-
- }
- public static Integer getParentNodeName(XID xid) {
- // Arjuna.XID()
- // don't check the formatId - it may differ e.g. JTA vs. JTS.
- if (xid.formatID != FORMAT_ID && xid.formatID != 131072
- && xid.formatID != 131080) {
- return -1;
- }
-
- // the node name follows the Uid with no separator, so the only
- // way to tell where it starts is to figure out how long the Uid is.
- int offset = Uid.UID_SIZE + 4 + Uid.UID_SIZE + 4;
-
- return (xid.data[offset + 0] << 24)
- + ((xid.data[offset + 1] & 0xFF) << 16)
- + ((xid.data[offset + 2] & 0xFF) << 8)
- + (xid.data[offset + 3] & 0xFF);
- }
-
-
public static void setBranchUID(XID xid, Uid uid) {
if (xid == null || xid.formatID != FORMAT_ID) {
return;
@@ -260,23 +223,23 @@
return;
}
- int remainingNameLength = Xid.MAXBQUALSIZE - (Uid.UID_SIZE + 4 + 4);
+ int remainingNameLength = Xid.MAXBQUALSIZE - (Uid.UID_SIZE + 4);
byte[] toWrite = new byte[0];
if (eisName == null) {
toWrite = Arrays.copyOf(toWrite, remainingNameLength);
- xid.bqual_length = Uid.UID_SIZE + 4 + 4;
+ xid.bqual_length = Uid.UID_SIZE + 4;
} else {
if (eisName.length() > remainingNameLength) {
eisName = "eis name too long";
}
toWrite = Arrays.copyOf(eisName.getBytes(), remainingNameLength);
- xid.bqual_length = Uid.UID_SIZE + 4 + 4 + eisName.length();
+ xid.bqual_length = Uid.UID_SIZE + 4 + eisName.length();
}
- int eisNamePosition = xid.gtrid_length + Uid.UID_SIZE + 4 + 4;
+ int eisNamePosition = xid.gtrid_length + Uid.UID_SIZE + 4;
System.arraycopy(toWrite, 0, xid.data, eisNamePosition, remainingNameLength);
}
@@ -288,14 +251,14 @@
Uid uid = getUid(xid);
int uidLength = uid.getBytes().length;
- int nameLength = xid.bqual_length-(uidLength+4+4);
+ int nameLength = xid.bqual_length-(uidLength+4);
if(nameLength == 0) {
return "unknown eis name";
}
byte[] eisName = new byte[nameLength];
- System.arraycopy(xid.data, xid.gtrid_length+uidLength+4+4, eisName, 0, eisName.length);
+ System.arraycopy(xid.data, xid.gtrid_length+uidLength+4, eisName, 0, eisName.length);
try {
return new String(eisName, "US-ASCII");
@@ -323,9 +286,7 @@
stringBuilder.append(", branch_uid=");
stringBuilder.append(getBranchUid(xid));;
stringBuilder.append(", subordinatenodename=");
- stringBuilder.append(getSubordinateNodeName(xid));;
- stringBuilder.append(", parentnodename=");
- stringBuilder.append(getParentNodeName(xid));
+ stringBuilder.append(getSubordinateNodeName(xid));
stringBuilder.append(", eis_name=");
stringBuilder.append(getEISName(xid));
stringBuilder.append(" >");
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XidImple.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XidImple.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XidImple.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -62,24 +62,10 @@
}
public XidImple(Xid xid) {
- this(xid, false);
- }
-
- public XidImple (Xid xid, boolean subordinate)
- {
_theXid = null;
copy(xid);
- // If this is a subordinate transaction and it is one of ours, bump up the parent node name
- if (subordinate && _theXid.formatID == XATxConverter.FORMAT_ID) {
- int parentNodeName = XATxConverter.getSubordinateNodeName(_theXid);
- if (parentNodeName == 0) {
- parentNodeName = XATxConverter.getNodeName(_theXid);
- }
- XATxConverter.setParentNodeName(_theXid, parentNodeName);
- XATxConverter.setSubordinateNodeName(_theXid, TxControl.getXANodeName());
- }
hashCode = getHash(_theXid) ;
}
@@ -92,13 +78,16 @@
}
public XidImple(Xid xid, boolean branch, String eisName) {
- this(xid, false);
+ this(xid);
if (branch) {
XATxConverter.setBranchUID(_theXid, new Uid());
}
XATxConverter.setEisName(_theXid, eisName);
}
+ /**
+ * @deprecated This is only used by test code
+ */
public XidImple(Uid id) {
this(id, false, null);
}
@@ -108,6 +97,7 @@
_theXid = XATxConverter.getXid(id, branch, eisName);
} catch (Exception e) {
_theXid = null;
+ e.printStackTrace();
// abort or throw exception?
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/arjuna/ats/jta/xa/XATxConverterTest.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/arjuna/ats/jta/xa/XATxConverterTest.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/arjuna/ats/jta/xa/XATxConverterTest.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -18,23 +18,22 @@
Uid uid = new Uid();
boolean branch = true;
String eisName = "foo";
- arjPropertyManager.getCoreEnvironmentBean().setNodeIdentifier(1);
+ arjPropertyManager.getCoreEnvironmentBean().setNodeIdentifier("1");
XidImple rootXid = new XidImple(uid, branch, eisName);
{
- assertEquals(XATxConverter.getNodeName(rootXid.getXID()), new Integer(1));
+ assertEquals(XATxConverter.getNodeName(rootXid.getXID()), "1");
assertEquals(XATxConverter.getEISName(rootXid.getXID()), eisName);
assertEquals(XATxConverter.getSubordinateNodeName(rootXid.getXID()), new Integer(0));
- assertEquals(XATxConverter.getParentNodeName(rootXid.getXID()), new Integer(0));
}
- TxControl.setXANodeName(2);
- XidImple subordinateXid = new XidImple(rootXid, true);
+// TxControl.setXANodeName(2);
+ XATxConverter.setSubordinateNodeName(rootXid.getXID(), 1);
+ XidImple subordinateXid = new XidImple(rootXid);
{
- assertEquals(XATxConverter.getNodeName(subordinateXid.getXID()), new Integer(1));
+ assertEquals(XATxConverter.getNodeName(subordinateXid.getXID()), "1");
assertEquals(XATxConverter.getEISName(subordinateXid.getXID()), eisName);
- assertEquals(XATxConverter.getSubordinateNodeName(subordinateXid.getXID()), new Integer(2));
- assertEquals(XATxConverter.getParentNodeName(subordinateXid.getXID()), new Integer(1));
+ assertEquals(XATxConverter.getSubordinateNodeName(subordinateXid.getXID()), new Integer(1));
}
}
@@ -42,10 +41,9 @@
public void testForeignXID() {
XidImple foreignXidImple = new XidImple(new MyForeignXID());
- assertEquals(XATxConverter.getNodeName(foreignXidImple.getXID()), new Integer(-1));
+ assertEquals(XATxConverter.getNodeName(foreignXidImple.getXID()), null);
assertEquals(XATxConverter.getEISName(foreignXidImple.getXID()), "unknown eis name");
assertEquals(XATxConverter.getSubordinateNodeName(foreignXidImple.getXID()), new Integer(-1));
- assertEquals(XATxConverter.getParentNodeName(foreignXidImple.getXID()), new Integer(-1));
}
private class MyForeignXID implements Xid {
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/RecoveryXAResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/RecoveryXAResource.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/RecoveryXAResource.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -51,9 +51,9 @@
xids[0] = new XidImple(a);
- int c = com.arjuna.ats.arjuna.coordinator.TxControl.getXANodeName();
+ String c = com.arjuna.ats.arjuna.coordinator.TxControl.getXANodeName();
- int b = 2;
+ String b = "2";
com.arjuna.ats.arjuna.coordinator.TxControl.setXANodeName(b);
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/RecoveryTest.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/RecoveryTest.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/RecoveryTest.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -48,12 +48,12 @@
public void test()
{
Vector xaRecoveryNodes = new Vector();
- xaRecoveryNodes.add(2);
+ xaRecoveryNodes.add("2");
- System.err.println("Bogus XA node name: "+2);
+ System.err.println("Bogus XA node name: "+"2");
XidImple xid = new XidImple(new Uid());
- int nodeName = XAUtils.getXANodeName(xid);
+ String nodeName = XAUtils.getXANodeName(xid);
// should fail.
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XAResourceOrphanFilterTest.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XAResourceOrphanFilterTest.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XAResourceOrphanFilterTest.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -53,17 +53,17 @@
Xid notJTAFormatId = XATxConverter.getXid(new Uid(), false, 0);
assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(notJTAFormatId));
- List<Integer> recoveryNodes = new LinkedList<Integer>();
- recoveryNodes.add(1);
- jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodesImpl(recoveryNodes);
+ List<String> recoveryNodes = new LinkedList<String>();
+ recoveryNodes.add("1");
+ jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(recoveryNodes);
- int notRecoverableNodeName =2;
+ String notRecoverableNodeName ="2";
TxControl.setXANodeName(notRecoverableNodeName);
Xid jtaNotRecoverableNodeName = XATxConverter.getXid(new Uid(), false, XATxConverter.FORMAT_ID);
assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(jtaNotRecoverableNodeName));
- int recoverableNodeName =1;
+ String recoverableNodeName ="1";
TxControl.setXANodeName(recoverableNodeName);
Xid jtaRecoverableNodeName = XATxConverter.getXid(new Uid(), false, XATxConverter.FORMAT_ID);
@@ -71,7 +71,7 @@
recoveryNodes.clear();
recoveryNodes.add(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES);
- jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodesImpl(recoveryNodes);
+ jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(recoveryNodes);
assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(jtaNotRecoverableNodeName));
assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(jtaRecoverableNodeName));
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/XAUtilsUnitTest.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/XAUtilsUnitTest.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/XAUtilsUnitTest.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -39,6 +39,7 @@
import org.junit.Test;
import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.TxControl;
import com.arjuna.ats.internal.jta.resources.XAResourceErrorHandler;
import com.arjuna.ats.internal.jta.utils.XAUtils;
import com.arjuna.ats.jta.common.jtaPropertyManager;
@@ -72,7 +73,7 @@
assertFalse(XAUtils.mustEndSuspendedRMs(xa));
assertTrue(XAUtils.canOptimizeDelist(xa));
- assertTrue(XAUtils.getXANodeName(new XidImple(new Uid())) == 1);
+ assertEquals(XAUtils.getXANodeName(new XidImple(new Uid())), TxControl.getXANodeName());
}
@Test
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/xidcheck.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/xidcheck.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/xidcheck.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -33,6 +33,7 @@
import com.arjuna.ats.arjuna.AtomicAction;
import com.arjuna.ats.arjuna.common.*;
+import com.arjuna.ats.arjuna.coordinator.TxControl;
import com.arjuna.ats.arjuna.state.InputObjectState;
import com.arjuna.ats.arjuna.state.OutputObjectState;
import com.arjuna.ats.internal.jta.xa.XID;
@@ -83,7 +84,7 @@
assertEquals(xid1.getTransactionUid(), A.get_uid());
- assertTrue(XATxConverter.getNodeName(xid1.getXID()) == 1);
+ assertTrue(XATxConverter.getNodeName(xid1.getXID()).equals(TxControl.getXANodeName()));
assertTrue(xid1.getXID() != null);
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/RecoveryXAResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/RecoveryXAResource.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/RecoveryXAResource.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -51,9 +51,9 @@
xids[0] = new XidImple(a);
- int c = com.arjuna.ats.arjuna.coordinator.TxControl.getXANodeName();
+ String c = com.arjuna.ats.arjuna.coordinator.TxControl.getXANodeName();
- int b = 2;
+ String b = "2";
com.arjuna.ats.arjuna.coordinator.TxControl.setXANodeName(b);
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTS/jts/classes/com/arjuna/ats/jts/utils/Utility.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTS/jts/classes/com/arjuna/ats/jts/utils/Utility.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTS/jts/classes/com/arjuna/ats/jts/utils/Utility.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -175,11 +175,11 @@
otid_t otid = new otid_t();
byte[] b = theUid.getBytes();
- int nodeName = TxControl.getXANodeName();
+ byte[] nodeName = TxControl.getXANodeName().getBytes();
otid.formatID = 0;
- otid.tid = new byte[b.length+4];
- otid.bqual_length = 4;
+ otid.tid = new byte[b.length+nodeName.length];
+ otid.bqual_length = nodeName.length;
/*
* gtrid must be first then immediately followed by bqual.
@@ -187,13 +187,8 @@
*/
System.arraycopy(b, 0, otid.tid, 0, b.length);
+ System.arraycopy(nodeName, 0, otid.tid, b.length, nodeName.length);
- int offset = b.length;
- otid.tid[offset + 0] = (byte) (nodeName >>> 24);
- otid.tid[offset + 1] = (byte) (nodeName >>> 16);
- otid.tid[offset + 2] = (byte) (nodeName >>> 8);
- otid.tid[offset + 3] = (byte) (nodeName >>> 0);
-
b = null;
return otid;
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/ExampleDistributedJTATestCase.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/ExampleDistributedJTATestCase.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/ExampleDistributedJTATestCase.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -110,7 +110,7 @@
IsolatableServersClassLoader classLoader = new IsolatableServersClassLoader("com.arjuna.jta.distributed.example.server", contextClassLoader);
localServers[i] = (LocalServer) classLoader.loadClass("com.arjuna.jta.distributed.example.server.impl.ServerImpl").newInstance();
Thread.currentThread().setContextClassLoader(localServers[i].getClass().getClassLoader());
- localServers[i].initialise(lookupProvider, (i + 1) * 1000);
+ localServers[i].initialise(lookupProvider, String.valueOf((i + 1) * 1000), (i + 1) * 1000);
// This is a short cut, normally remote servers would not be the
// same as the local servers and would be a tranport layer
// abstraction
@@ -213,7 +213,7 @@
transactionManager.suspend();
// WE CAN NOW PROPAGATE THE TRANSACTION
- DataReturnedFromRemoteServer dataReturnedFromRemoteServer = propagateTransaction(nodesToFlowTo, remainingTimeout, currentXid);
+ DataReturnedFromRemoteServer dataReturnedFromRemoteServer = propagateTransaction(nodesToFlowTo, remainingTimeout, currentXid, 1);
// After the call retuns, resume the local transaction
transactionManager.resume(transaction);
@@ -277,7 +277,7 @@
* @throws NotSupportedException
* @throws IOException
*/
- private DataReturnedFromRemoteServer propagateTransaction(List<String> nodesToFlowTo, int remainingTimeout, Xid toMigrate) throws RollbackException,
+ private DataReturnedFromRemoteServer propagateTransaction(List<String> nodesToFlowTo, int remainingTimeout, Xid toMigrate, Integer nextAvailableSubordinateName) throws RollbackException,
IllegalStateException, XAException, SystemException, NotSupportedException, IOException {
// Do some test setup to initialize this method as it if was being
// invoked in a remote server
@@ -293,7 +293,10 @@
// Check if this server has seen this transaction before - this is
// crucial to ensure that calling servers will only lay down a proxy if
// they are the first visitor to this server.
- boolean requiresProxyAtPreviousServer = !currentServer.getAndResumeTransaction(remainingTimeout, toMigrate);
+ boolean requiresProxyAtPreviousServer = !currentServer.getAndResumeTransaction(remainingTimeout, toMigrate, nextAvailableSubordinateName);
+ if (requiresProxyAtPreviousServer) {
+ nextAvailableSubordinateName++;
+ }
{
// Perform work on the migrated transaction
@@ -339,7 +342,7 @@
// indicate whether this caller is the first client to establish
// the
// subordinate transaction at the remote node
- DataReturnedFromRemoteServer dataReturnedFromRemoteServer = propagateTransaction(nodesToFlowTo, remainingTimeout, currentXid);
+ DataReturnedFromRemoteServer dataReturnedFromRemoteServer = propagateTransaction(nodesToFlowTo, remainingTimeout, currentXid, nextAvailableSubordinateName);
// Resume the transaction locally, ready for any more local work
// and
// to add the proxy resource and sync if needed
@@ -352,6 +355,7 @@
transaction.enlistResource(proxyXAResource);
// Register a sync
transaction.registerSynchronization(currentServer.generateProxySynchronization(lookupProvider, nextServerNodeName, toMigrate));
+ nextAvailableSubordinateName = dataReturnedFromRemoteServer.getNextAvailableSubordinateName();
} else {
// This will discard the state of this resource, i.e. the
// file
@@ -386,7 +390,7 @@
// Return to the previous caller back over the transport/classloader
// boundary in this case
Thread.currentThread().setContextClassLoader(classLoader);
- return new DataReturnedFromRemoteServer(requiresProxyAtPreviousServer, transactionState);
+ return new DataReturnedFromRemoteServer(requiresProxyAtPreviousServer, transactionState, nextAvailableSubordinateName);
}
/**
@@ -412,9 +416,12 @@
private int transactionState;
- public DataReturnedFromRemoteServer(boolean proxyRequired, int transactionState) {
+ private Integer nextAvailableSubordinateName;
+
+ public DataReturnedFromRemoteServer(boolean proxyRequired, int transactionState, Integer nextAvailableSubordinateName) {
this.proxyRequired = proxyRequired;
this.transactionState = transactionState;
+ this.nextAvailableSubordinateName = nextAvailableSubordinateName;
}
public boolean isProxyRequired() {
@@ -424,5 +431,9 @@
public int getTransactionState() {
return transactionState;
}
+
+ public Integer getNextAvailableSubordinateName() {
+ return nextAvailableSubordinateName;
+ }
}
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -46,13 +46,13 @@
private File file;
- private Integer localServerName;
+ private String localServerName;
- public TestResource(Integer localServerName) {
+ public TestResource(String localServerName) {
this.localServerName = localServerName;
}
- public TestResource(Integer localServerName, File file) throws IOException {
+ public TestResource(String localServerName, File file) throws IOException {
this.localServerName = localServerName;
this.file = file;
DataInputStream fis = new DataInputStream(new FileInputStream(file));
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResourceRecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResourceRecovery.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResourceRecovery.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -39,7 +39,7 @@
private List<TestResource> resources = new ArrayList<TestResource>();
- public TestResourceRecovery(Integer nodeName) throws IOException {
+ public TestResourceRecovery(String nodeName) throws IOException {
File file = new File(System.getProperty("user.dir") + "/distributedjta-example/TestResource/" + nodeName + "/");
if (file.exists() && file.isDirectory()) {
File[] listFiles = file.listFiles();
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestSynchronization.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestSynchronization.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestSynchronization.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -29,9 +29,9 @@
* considered a black box.
*/
public class TestSynchronization implements Synchronization {
- private int localServerName;
+ private String localServerName;
- public TestSynchronization(Integer localServerName) {
+ public TestSynchronization(String localServerName) {
this.localServerName = localServerName;
}
Deleted: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/DummyRemoteException.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/DummyRemoteException.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/DummyRemoteException.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -1,29 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package com.arjuna.jta.distributed.example.server;
-
-/**
- * This is a dummy exception - it is not used in the example but is to reinforce
- * the idea that this example can be considered a simulation of a transport.
- */
-public class DummyRemoteException extends Exception {
-}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LocalServer.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LocalServer.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LocalServer.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -56,13 +56,13 @@
* @throws IllegalArgumentException
* @throws IllegalAccessException
*/
- public void initialise(LookupProvider lookupProvider, Integer nodeName) throws CoreEnvironmentBeanException, IOException, SecurityException,
+ public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset) throws CoreEnvironmentBeanException, IOException, SecurityException,
NoSuchFieldException, IllegalArgumentException, IllegalAccessException;
/**
* Get the local transaction managers node name.
*/
- public Integer getNodeName();
+ public String getNodeName();
/**
* Get a reference on the local transaction manager.
@@ -111,9 +111,10 @@
* @throws InvalidTransactionException
* @throws IllegalStateException
* @throws SystemException
+ * @throws IOException
*/
- public boolean getAndResumeTransaction(int remainingTimeout, Xid toImport) throws XAException, InvalidTransactionException, IllegalStateException,
- SystemException;
+ public boolean getAndResumeTransaction(int remainingTimeout, Xid toImport, Integer nextAvailableSubordinateName) throws XAException, InvalidTransactionException, IllegalStateException,
+ SystemException, IOException;
/**
* Transport specific function to generate a proxy for a remote server.
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/RemoteServer.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/RemoteServer.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/RemoteServer.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -21,6 +21,8 @@
*/
package com.arjuna.jta.distributed.example.server;
+import java.io.IOException;
+
import javax.transaction.SystemException;
import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;
@@ -41,20 +43,6 @@
public interface RemoteServer {
/**
- * Atypical for a recover call we need to pass over the node name of the
- * caller. This will ensure that all Xids for the caller coordinated
- * Subordinates are returned. Also this method should pass true to the
- * XATerminator::recover method so that it will recover the inflight
- * transactions for this node
- *
- * @param callingServerNodeName
- * @return
- * @throws XAException
- * @throws DummyRemoteException
- */
- public Xid[] recoverFor(Integer callingServerNodeName) throws XAException, DummyRemoteException;
-
- /**
* Relay the propagate completion.
*
* @param xid
@@ -62,7 +50,7 @@
* @throws SystemException
* @throws DummyRemoteException
*/
- public void beforeCompletion(Xid xid) throws XAException, SystemException, DummyRemoteException;
+ public void beforeCompletion(Xid xid) throws XAException, SystemException;
/**
* Relay a prepare to the remote side for a specific Xid.
@@ -72,26 +60,36 @@
* @throws XAException
* @throws DummyRemoteException
*/
- public int prepare(Xid xid) throws XAException, DummyRemoteException;
+ public int prepare(Xid xid) throws XAException;
/**
* Relay the commit.
*
+ * If this call is coming from a recover scan on a ProxyXAResource, then
+ * pass the recover flag in so the remote server knows it needs to recover
+ * the transaction.
+ *
* @param xid
* @param onePhase
* @throws XAException
+ * @throws IOException
* @throws DummyRemoteException
*/
- public void commit(Xid xid, boolean onePhase) throws XAException, DummyRemoteException;
+ public void commit(Xid xid, boolean onePhase, boolean recover) throws XAException, IOException;
/**
- * Relay the rollback
+ * Relay the rollback.
*
+ * If this call is coming from a recover scan on a ProxyXAResource, then
+ * pass the recover flag in so the remote server knows it needs to recover
+ * the transaction.
+ *
* @param xid
* @throws XAException
+ * @throws IOException
* @throws DummyRemoteException
*/
- public void rollback(Xid xid) throws XAException, DummyRemoteException;
+ public void rollback(Xid xid, boolean recover) throws XAException, IOException;
/**
* Relay the forget.
@@ -100,6 +98,6 @@
* @throws XAException
* @throws DummyRemoteException
*/
- public void forget(Xid xid) throws XAException, DummyRemoteException;
+ public void forget(Xid xid) throws XAException;
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxySynchronization.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxySynchronization.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxySynchronization.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -26,7 +26,6 @@
import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;
-import com.arjuna.jta.distributed.example.server.DummyRemoteException;
import com.arjuna.jta.distributed.example.server.LookupProvider;
/**
@@ -36,12 +35,12 @@
*/
public class ProxySynchronization implements Synchronization {
- private int localServerName;
+ private String localServerName;
private String remoteServerName;
private Xid toRegisterAgainst;
private LookupProvider lookupProvider;
- public ProxySynchronization(LookupProvider lookupProvider, Integer localServerName, String remoteServerName, Xid toRegisterAgainst) {
+ public ProxySynchronization(LookupProvider lookupProvider, String localServerName, String remoteServerName, Xid toRegisterAgainst) {
this.lookupProvider = lookupProvider;
this.localServerName = localServerName;
this.remoteServerName = remoteServerName;
@@ -57,8 +56,6 @@
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
- } catch (DummyRemoteException e) {
- e.printStackTrace();
}
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResource.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResource.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -25,11 +25,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import javax.transaction.xa.XAException;
@@ -37,7 +33,6 @@
import javax.transaction.xa.Xid;
import com.arjuna.ats.arjuna.common.Uid;
-import com.arjuna.jta.distributed.example.server.DummyRemoteException;
import com.arjuna.jta.distributed.example.server.LookupProvider;
/**
@@ -86,9 +81,10 @@
private int transactionTimeout;
private String remoteServerName = null;
private Map<Xid, File> map;
- private Integer localServerName;
+ private String localServerName;
private LookupProvider lookupProvider;
private File file;
+ private boolean recover;
/**
* Create a new proxy to the remote server.
@@ -97,7 +93,7 @@
* @param localServerName
* @param remoteServerName
*/
- public ProxyXAResource(LookupProvider lookupProvider, Integer localServerName, String remoteServerName, File file) {
+ public ProxyXAResource(LookupProvider lookupProvider, String localServerName, String remoteServerName, File file) {
this.lookupProvider = lookupProvider;
this.localServerName = localServerName;
this.remoteServerName = remoteServerName;
@@ -115,11 +111,12 @@
* @param file
* @throws IOException
*/
- public ProxyXAResource(LookupProvider lookupProvider, Integer localServerName, String remoteServerName, Map<Xid, File> map) throws IOException {
+ public ProxyXAResource(LookupProvider lookupProvider, String localServerName, String remoteServerName, Map<Xid, File> map) throws IOException {
this.lookupProvider = lookupProvider;
this.localServerName = localServerName;
this.remoteServerName = remoteServerName;
this.map = map;
+ this.recover = true;
}
public void deleteTemporaryFile() {
@@ -184,13 +181,9 @@
throw new XAException(XAException.XAER_RMERR);
}
- try {
- int propagatePrepare = lookupProvider.lookup(remoteServerName).prepare(xid);
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_PREPARED");
- return propagatePrepare;
- } catch (DummyRemoteException ce) {
- throw new XAException(XAException.XA_RETRY);
- }
+ int propagatePrepare = lookupProvider.lookup(remoteServerName).prepare(xid);
+ System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_PREPARED");
+ return propagatePrepare;
}
@Override
@@ -198,11 +191,13 @@
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMIT [" + xid + "]");
try {
- lookupProvider.lookup(remoteServerName).commit(xid, onePhase);
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMITED");
- } catch (DummyRemoteException ce) {
+ lookupProvider.lookup(remoteServerName).commit(xid, onePhase, recover);
+ } catch (IOException e) {
+ e.printStackTrace();
throw new XAException(XAException.XA_RETRY);
}
+
+ System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMITED");
if (map.get(xid) != null) {
map.get(xid).delete();
@@ -220,16 +215,17 @@
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACK[" + xid + "]");
try {
- lookupProvider.lookup(remoteServerName).rollback(xid);
+ lookupProvider.lookup(remoteServerName).rollback(xid, recover);
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACKED");
- } catch (DummyRemoteException ce) {
- throw new XAException(XAException.XA_RETRY);
} catch (XAException e) {
// We know the remote side must have done a JBTM-917
if (e.errorCode == XAException.XAER_INVAL) {
// We know that this means that the transaction is not known at
// the remote side
}
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new XAException(XAException.XA_RETRY);
}
if (map.get(xid) != null) {
@@ -264,41 +260,6 @@
+ remoteServerName);
}
- List<Xid> toReturn = new ArrayList<Xid>();
- Xid[] recovered = null;
- try {
- recovered = lookupProvider.lookup(remoteServerName).recoverFor(localServerName);
- } catch (DummyRemoteException ce) {
- throw new XAException(XAException.XA_RETRY);
- }
-
- List<Xid> arrayList = new ArrayList<Xid>();
- arrayList.addAll(map.keySet());
- if (recovered != null) {
- for (int i = 0; i < recovered.length; i++) {
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") recovered: " + recovered[i]);
- Iterator<Xid> iterator = map.keySet().iterator();
- while (iterator.hasNext()) {
- Xid next = iterator.next();
- if (Arrays.equals(next.getGlobalTransactionId(), recovered[i].getGlobalTransactionId())) {
- toReturn.add(next);
- } else if (!iterator.hasNext()) {
- toReturn.add(recovered[i]);
- }
- arrayList.remove(next);
- }
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") added: " + toReturn.get(toReturn.size() - 1));
- }
- }
-
- // We now know the remote server didn't know about these Xids
- List<Xid> knownNoneKnownXids = new ArrayList<Xid>();
- knownNoneKnownXids.addAll(arrayList);
- Iterator<Xid> iterator = knownNoneKnownXids.iterator();
- while (iterator.hasNext()) {
- Xid next = iterator.next();
- map.remove(next).delete();
- }
if ((flag & XAResource.TMSTARTRSCAN) == XAResource.TMSTARTRSCAN) {
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVERD[XAResource.TMSTARTRSCAN]: "
+ remoteServerName);
@@ -307,18 +268,14 @@
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVERD[XAResource.TMENDRSCAN]: "
+ remoteServerName);
}
- return toReturn.toArray(new Xid[0]);
+ return map.keySet().toArray(new Xid[0]);
}
@Override
public void forget(Xid xid) throws XAException {
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_FORGET [" + xid + "]");
- try {
- lookupProvider.lookup(remoteServerName).forget(xid);
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_FORGETED[" + xid + "]");
- } catch (DummyRemoteException ce) {
- throw new XAException(XAException.XA_RETRY);
- }
+ lookupProvider.lookup(remoteServerName).forget(xid);
+ System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_FORGETED[" + xid + "]");
}
@Override
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResourceRecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResourceRecovery.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResourceRecovery.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -43,8 +43,8 @@
private List<ProxyXAResource> resources = new ArrayList<ProxyXAResource>();
- public ProxyXAResourceRecovery(LookupProvider lookupProvider, Integer id) throws IOException {
- File directory = new File(System.getProperty("user.dir") + "/distributedjta-example/ProxyXAResource/" + id + "/");
+ public ProxyXAResourceRecovery(LookupProvider lookupProvider, String nodeName) throws IOException {
+ File directory = new File(System.getProperty("user.dir") + "/distributedjta-example/ProxyXAResource/" + nodeName + "/");
Map<String, Map<Xid, File>> savedData = new HashMap<String, Map<Xid, File>>();
if (directory.exists() && directory.isDirectory()) {
File[] listFiles = directory.listFiles();
@@ -92,7 +92,7 @@
while (iterator.hasNext()) {
String remoteServerName = iterator.next();
Map<Xid, File> map = savedData.get(remoteServerName);
- resources.add(new ProxyXAResource(lookupProvider, id, remoteServerName, map));
+ resources.add(new ProxyXAResource(lookupProvider, nodeName, remoteServerName, map));
}
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ServerImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ServerImpl.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ServerImpl.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -21,17 +21,19 @@
*/
package com.arjuna.jta.distributed.example.server.impl;
+import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.transaction.InvalidTransactionException;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
@@ -47,7 +49,6 @@
import com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean;
import com.arjuna.ats.arjuna.common.Uid;
import com.arjuna.ats.arjuna.coordinator.TxControl;
-import com.arjuna.ats.arjuna.recovery.RecoveryManager;
import com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser;
import com.arjuna.ats.internal.jbossatx.jta.XAResourceRecordWrappingPluginImpl;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
@@ -57,8 +58,9 @@
import com.arjuna.ats.jbossatx.jta.RecoveryManagerService;
import com.arjuna.ats.jbossatx.jta.TransactionManagerService;
import com.arjuna.ats.jta.common.JTAEnvironmentBean;
+import com.arjuna.ats.jta.xa.XATxConverter;
+import com.arjuna.ats.jta.xa.XidImple;
import com.arjuna.jta.distributed.example.TestResourceRecovery;
-import com.arjuna.jta.distributed.example.server.DummyRemoteException;
import com.arjuna.jta.distributed.example.server.LocalServer;
import com.arjuna.jta.distributed.example.server.LookupProvider;
import com.arjuna.jta.distributed.example.server.RemoteServer;
@@ -68,17 +70,19 @@
private RecoveryManagerService recoveryManagerService;
private TransactionManagerService transactionManagerService;
private Map<SubordinateXidImple, TransactionImple> transactions = new HashMap<SubordinateXidImple, TransactionImple>();
- private RecoveryManager _recoveryManager;
+ private String nodeName;
+ private Map<SubordinateXidImple, File> subordinateOrphanDetection = new HashMap<SubordinateXidImple, File>();
- public void initialise(LookupProvider lookupProvider, Integer nodeName) throws CoreEnvironmentBeanException, IOException, SecurityException,
+ public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset) throws CoreEnvironmentBeanException, IOException, SecurityException,
NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
+ this.nodeName = nodeName;
RecoveryEnvironmentBean recoveryEnvironmentBean = com.arjuna.ats.arjuna.common.recoveryPropertyManager.getRecoveryEnvironmentBean();
recoveryEnvironmentBean.setRecoveryBackoffPeriod(1);
recoveryEnvironmentBean.setRecoveryInetAddress(InetAddress.getByName("localhost"));
- recoveryEnvironmentBean.setRecoveryPort(4712 + nodeName);
+ recoveryEnvironmentBean.setRecoveryPort(4712 + portOffset);
recoveryEnvironmentBean.setTransactionStatusManagerInetAddress(InetAddress.getByName("localhost"));
- recoveryEnvironmentBean.setTransactionStatusManagerPort(4713 + nodeName);
+ recoveryEnvironmentBean.setTransactionStatusManagerPort(4713 + portOffset);
List<String> recoveryModuleClassNames = new ArrayList<String>();
recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
@@ -91,7 +95,7 @@
recoveryEnvironmentBean.setRecoveryActivators(null);
CoreEnvironmentBean coreEnvironmentBean = com.arjuna.ats.arjuna.common.arjPropertyManager.getCoreEnvironmentBean();
- coreEnvironmentBean.setSocketProcessIdPort(4714 + nodeName);
+ coreEnvironmentBean.setSocketProcessIdPort(4714 + portOffset);
coreEnvironmentBean.setNodeIdentifier(nodeName);
coreEnvironmentBean.setSocketProcessIdMaxPorts(1);
@@ -124,9 +128,9 @@
jTAEnvironmentBean.setUserTransactionClassName("com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple");
jTAEnvironmentBean
.setTransactionSynchronizationRegistryClassName("com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple");
- List<Integer> xaRecoveryNodes = new ArrayList<Integer>();
+ List<String> xaRecoveryNodes = new ArrayList<String>();
xaRecoveryNodes.add(nodeName);
- jTAEnvironmentBean.setXaRecoveryNodesImpl(xaRecoveryNodes);
+ jTAEnvironmentBean.setXaRecoveryNodes(xaRecoveryNodes);
List<String> xaResourceOrphanFilterClassNames = new ArrayList<String>();
@@ -163,16 +167,36 @@
* stage of the flow!!!
*
* NOTE: CMT would not allow you do this anyway
+ *
+ * @throws IOException
*/
@Override
- public boolean getAndResumeTransaction(int remainingTimeout, Xid toResume) throws XAException, InvalidTransactionException, IllegalStateException,
- SystemException {
+ public boolean getAndResumeTransaction(int remainingTimeout, Xid toResume, Integer nextAvailableSubordinateName) throws XAException, IllegalStateException,
+ SystemException, IOException {
boolean existed = true;
Transaction transaction = transactions.get(new SubordinateXidImple(toResume));
if (transaction == null) {
transaction = SubordinationManager.getTransactionImporter().getImportedTransaction(toResume);
if (transaction == null) {
- transaction = SubordinationManager.getTransactionImporter().importTransaction(toResume, remainingTimeout);
+
+ File dir = new File(System.getProperty("user.dir") + "/distributedjta-example/SubordinateNameXANodeNameMap/" + TxControl.getXANodeName());
+ dir.mkdirs();
+ File file = new File(dir, new Uid().fileStringForm());
+ file.createNewFile();
+ DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
+ byte[] nodeName = TxControl.getXANodeName().getBytes();
+ fos.writeInt(nodeName.length);
+ fos.write(nodeName);
+ fos.writeInt(nextAvailableSubordinateName);
+ fos.writeInt(toResume.getGlobalTransactionId().length);
+ fos.write(toResume.getGlobalTransactionId());
+
+ subordinateOrphanDetection.put(new SubordinateXidImple(toResume), file);
+
+ XidImple toImport = new XidImple(toResume);
+ XATxConverter.setSubordinateNodeName(toImport.getXID(), nextAvailableSubordinateName);
+
+ transaction = SubordinationManager.getTransactionImporter().importTransaction(toImport, remainingTimeout);
existed = false;
}
}
@@ -181,7 +205,7 @@
}
@Override
- public Integer getNodeName() {
+ public String getNodeName() {
return TxControl.getXANodeName();
}
@@ -230,7 +254,7 @@
fos.writeInt(currentXid.getBranchQualifier().length);
fos.write(currentXid.getBranchQualifier());
- return new ProxyXAResource(lookupProvider, TxControl.getXANodeName(), remoteServerName, file);
+ return new ProxyXAResource(lookupProvider, nodeName, remoteServerName, file);
}
@Override
@@ -240,7 +264,7 @@
@Override
public Synchronization generateProxySynchronization(LookupProvider lookupProvider, String remoteServerName, Xid toRegisterAgainst) {
- return new ProxySynchronization(lookupProvider, TxControl.getXANodeName(), remoteServerName, toRegisterAgainst);
+ return new ProxySynchronization(lookupProvider, nodeName, remoteServerName, toRegisterAgainst);
}
@Override
@@ -249,7 +273,7 @@
}
@Override
- public int prepare(Xid xid) throws XAException, DummyRemoteException {
+ public int prepare(Xid xid) throws XAException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
@@ -260,55 +284,96 @@
}
@Override
- public void commit(Xid xid, boolean onePhase) throws XAException, DummyRemoteException {
+ public void commit(Xid xid, boolean onePhase, boolean recover) throws XAException, IOException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if (recover) {
+ recover(xid);
+ }
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
SubordinationManager.getXATerminator().commit(xid, onePhase);
+ subordinateOrphanDetection.remove(new SubordinateXidImple(xid)).delete();
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
@Override
- public void rollback(Xid xid) throws XAException, DummyRemoteException {
+ public void rollback(Xid xid, boolean recover) throws XAException, IOException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if (recover) {
+ recover(xid);
+ }
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
SubordinationManager.getXATerminator().rollback(xid);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
+
+ subordinateOrphanDetection.remove(new SubordinateXidImple(xid)).delete();
}
}
- @Override
- public Xid[] recoverFor(Integer parentNodeName) throws XAException, DummyRemoteException {
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
- // Pass in true so we can recover the inflight transactions for this
- // node
- Xid[] recovered = ((XATerminatorImple) SubordinationManager.getXATerminator()).doRecover(parentNodeName, true);
- return recovered;
- } finally {
- Thread.currentThread().setContextClassLoader(contextClassLoader);
+ public void recover(Xid toRecover) throws XAException, IOException {
+ // Work out what the subordinate name would be for these transaction
+ // for this server
+ XidImple recoverable = null;
+
+ // Look at the list of subordinate name to XA node name map
+ File directory = new File(System.getProperty("user.dir") + "/distributedjta-example/SubordinateNameXANodeNameMap/" + nodeName + "/");
+ if (directory.exists() && directory.isDirectory()) {
+ File[] listFiles = directory.listFiles();
+ for (int i = 0; i < listFiles.length; i++) {
+ File file = listFiles[i];
+ DataInputStream fis = new DataInputStream(new FileInputStream(file));
+ int nodeNameLength = fis.readInt();
+ final byte[] nodeNameBytes = new byte[nodeNameLength];
+ fis.read(nodeNameBytes, 0, nodeNameLength);
+ String nodeName = new String(nodeNameBytes);
+
+ // Is the node name this servers node name
+ if (nodeName.equals(TxControl.getXANodeName())) {
+ // Read in the subordinate name for the encapsulated
+ // transaction
+ Integer subordinateNodeName = fis.readInt();
+ int gtridLength = fis.readInt();
+ byte[] gtrid = new byte[gtridLength];
+ fis.read(gtrid, 0, gtridLength);
+
+ // Check if the transaction in the list the client is
+ // requesting
+ byte[] requestedGtrid = toRecover.getGlobalTransactionId();
+ if (Arrays.equals(gtrid, requestedGtrid)) {
+ // Set the subordinate name
+ recoverable = new XidImple(toRecover);
+ XATxConverter.setSubordinateNodeName(recoverable.getXID(), subordinateNodeName);
+ subordinateOrphanDetection.put(new SubordinateXidImple(recoverable), file);
+ }
+ }
+ }
+
}
+
+ if (recoverable != null) {
+ ((XATerminatorImple) SubordinationManager.getXATerminator()).doRecover(recoverable);
+ }
}
@Override
- public void forget(Xid xid) throws XAException, DummyRemoteException {
+ public void forget(Xid xid) throws XAException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
SubordinationManager.getXATerminator().forget(xid);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
+ subordinateOrphanDetection.remove(new SubordinateXidImple(xid)).delete();
}
}
@Override
- public void beforeCompletion(Xid xid) throws XAException, SystemException, DummyRemoteException {
+ public void beforeCompletion(Xid xid) throws XAException, SystemException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -49,7 +49,6 @@
import com.arjuna.ats.arjuna.common.CoreEnvironmentBeanException;
import com.arjuna.ats.jta.distributed.server.CompletionCounter;
-import com.arjuna.ats.jta.distributed.server.DummyRemoteException;
import com.arjuna.ats.jta.distributed.server.IsolatableServersClassLoader;
import com.arjuna.ats.jta.distributed.server.LocalServer;
import com.arjuna.ats.jta.distributed.server.LookupProvider;
@@ -69,7 +68,7 @@
IsolatableServersClassLoader classLoader = new IsolatableServersClassLoader("com.arjuna.ats.jta.distributed.server", contextClassLoader);
localServers[i] = (LocalServer) classLoader.loadClass("com.arjuna.ats.jta.distributed.server.impl.ServerImpl").newInstance();
Thread.currentThread().setContextClassLoader(localServers[i].getClass().getClassLoader());
- localServers[i].initialise(lookupProvider, (i + 1) * 1000);
+ localServers[i].initialise(lookupProvider, String.valueOf((i + 1) * 1000), (i + 1) * 1000);
remoteServers[i] = localServers[i].connectTo();
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
@@ -85,8 +84,8 @@
}
}
- private static void reboot(Integer serverName) throws Exception {
- int index = (serverName / 1000) - 1;
+ private static void reboot(String serverName) throws Exception {
+ int index = (Integer.valueOf(serverName) / 1000) - 1;
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(localServers[index].getClass().getClassLoader());
localServers[index].shutdown();
@@ -95,7 +94,7 @@
IsolatableServersClassLoader classLoader = new IsolatableServersClassLoader("com.arjuna.ats.jta.distributed.server", contextClassLoader);
localServers[index] = (LocalServer) classLoader.loadClass("com.arjuna.ats.jta.distributed.server.impl.ServerImpl").newInstance();
Thread.currentThread().setContextClassLoader(localServers[index].getClass().getClassLoader());
- localServers[index].initialise(lookupProvider, (index + 1) * 1000);
+ localServers[index].initialise(lookupProvider, String.valueOf((index + 1) * 1000), (index + 1) * 1000);
remoteServers[index] = localServers[index].connectTo();
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
@@ -108,33 +107,139 @@
* distributed JTA.
*
* @throws XAException
+ * @throws IOException
* @throws DummyRemoteException
*/
@Test
- public void testSimultaneousRecover() throws XAException, DummyRemoteException {
- // Simulates different servers attempting to recover the XIDs from the
- // same server basically XATerminator::recover doesn't allow two calls
- // at once this used to fail, but after I changed XATerminatorImple, it
- // can't fail now doesn't matter if there are Xids or not you see it
- // used to be done in two passes with a different flag
- // recover(TMSTARTSCAN)/recover(TMENDSCAN)
- // but that is for JCA, not us, we have some knowledge of the state of
- // transactions so we pass in our node name instead and call recover in
- // a single scan
- // to put it another way, the test used to say:
- // lookupProvider.lookup(2000).recoverFor(1000, TMSTARTSCAN);
- // lookupProvider.lookup(2000).recoverFor(3000, TMSTARTSCAN);
- // lookupProvider.lookup(2000).recoverFor(3000, TMENDSCAN);
- // lookupProvider.lookup(2000).recoverFor(1000, TMENDSCAN);
- // That second call to TMSTARTSCAN would fail
+ @BMScript("leave-subordinate-orphan")
+ public void testSimultaneousRecover() throws Exception {
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ final Phase2CommitAborted phase2CommitAborted = new Phase2CommitAborted();
{
- // Simulates a remote call *from* node 1000 *to* node 2000
- lookupProvider.lookup(2000).recoverFor(1000);
+ Thread thread = new Thread(new Runnable() {
+ public void run() {
+ int startingTimeout = 0;
+ try {
+ LocalServer originalServer = getLocalServer("1000");
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
+ TransactionManager transactionManager = originalServer.getTransactionManager();
+ transactionManager.setTransactionTimeout(startingTimeout);
+ transactionManager.begin();
+ Transaction originalTransaction = transactionManager.getTransaction();
+ int remainingTimeout = (int) (originalServer.getTimeLeftBeforeTransactionTimeout() / 1000);
+ Xid currentXid = originalServer.getCurrentXid();
+ originalServer.storeRootTransaction();
+ XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000");
+ transactionManager.suspend();
+ performTransactionalWork(null, new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 2, false,
+ false, 1);
+ transactionManager.resume(originalTransaction);
+ originalTransaction.enlistResource(proxyXAResource);
+ originalServer.removeRootTransaction(currentXid);
+ transactionManager.commit();
+ Thread.currentThread().setContextClassLoader(classLoader);
+ } catch (ExecuteException e) {
+ System.err.println("Should be a thread death but cest la vie");
+ synchronized (phase2CommitAborted) {
+ phase2CommitAborted.incrementPhase2CommitAborted();
+ phase2CommitAborted.notify();
+ }
+ } catch (LinkageError t) {
+ System.err.println("Should be a thread death but cest la vie");
+ synchronized (phase2CommitAborted) {
+ phase2CommitAborted.incrementPhase2CommitAborted();
+ phase2CommitAborted.notify();
+ }
+ } catch (Throwable t) {
+ System.err.println("Should be a thread death but cest la vie");
+ synchronized (phase2CommitAborted) {
+ phase2CommitAborted.incrementPhase2CommitAborted();
+ phase2CommitAborted.notify();
+ }
+ }
+ }
+ }, "Orphan-creator");
+ thread.start();
}
+
{
- // Simulates a remote call *from* node 3000 *to* node 2000
- lookupProvider.lookup(2000).recoverFor(3000);
+ Thread thread = new Thread(new Runnable() {
+ public void run() {
+ int startingTimeout = 0;
+ try {
+ LocalServer originalServer = getLocalServer("2000");
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
+ TransactionManager transactionManager = originalServer.getTransactionManager();
+ transactionManager.setTransactionTimeout(startingTimeout);
+ transactionManager.begin();
+ Transaction originalTransaction = transactionManager.getTransaction();
+ int remainingTimeout = (int) (originalServer.getTimeLeftBeforeTransactionTimeout() / 1000);
+ Xid currentXid = originalServer.getCurrentXid();
+ originalServer.storeRootTransaction();
+ XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "1000");
+ transactionManager.suspend();
+ performTransactionalWork(null, new LinkedList<String>(Arrays.asList(new String[] { "1000" })), remainingTimeout, currentXid, 2, false,
+ false, 1);
+ transactionManager.resume(originalTransaction);
+ originalTransaction.enlistResource(proxyXAResource);
+ originalServer.removeRootTransaction(currentXid);
+ transactionManager.commit();
+ Thread.currentThread().setContextClassLoader(classLoader);
+ } catch (ExecuteException e) {
+ System.err.println("Should be a thread death but cest la vie");
+ synchronized (phase2CommitAborted) {
+ phase2CommitAborted.incrementPhase2CommitAborted();
+ phase2CommitAborted.notify();
+ }
+ } catch (LinkageError t) {
+ System.err.println("Should be a thread death but cest la vie");
+ synchronized (phase2CommitAborted) {
+ phase2CommitAborted.incrementPhase2CommitAborted();
+ phase2CommitAborted.notify();
+ }
+ } catch (Throwable t) {
+ System.err.println("Should be a thread death but cest la vie");
+ synchronized (phase2CommitAborted) {
+ phase2CommitAborted.incrementPhase2CommitAborted();
+ phase2CommitAborted.notify();
+ }
+ }
+ }
+ }, "Orphan-creator");
+ thread.start();
}
+ synchronized (phase2CommitAborted) {
+ if (phase2CommitAborted.getPhase2CommitAbortedCount() < 2) {
+ phase2CommitAborted.wait();
+ }
+ }
+ tearDown();
+ setup();
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 0);
+ getLocalServer("2000").doRecoveryManagerScan(true);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 2);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 1);
+
+ tearDown();
+ setup();
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 0);
+ getLocalServer("1000").doRecoveryManagerScan(true);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 1);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 2);
+
}
/**
@@ -144,16 +249,15 @@
@Test
@BMScript("leaveorphan")
public void testTwoPhaseXAResourceOrphan() throws Exception {
- assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("3000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
final Phase2CommitAborted phase2CommitAborted = new Phase2CommitAborted();
Thread thread = new Thread(new Runnable() {
public void run() {
int startingTimeout = 0;
try {
- int startingServer = 1000;
- LocalServer originalServer = getLocalServer(startingServer);
+ LocalServer originalServer = getLocalServer("1000");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
TransactionManager transactionManager = originalServer.getTransactionManager();
@@ -162,11 +266,11 @@
Transaction originalTransaction = transactionManager.getTransaction();
int remainingTimeout = (int) (originalServer.getTimeLeftBeforeTransactionTimeout() / 1000);
Xid currentXid = originalServer.getCurrentXid();
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, 2000);
+ XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000");
originalServer.storeRootTransaction();
transactionManager.suspend();
- performTransactionalWork(null, new LinkedList<Integer>(Arrays.asList(new Integer[] { 2000 })), remainingTimeout, currentXid, 1, false,
- false);
+ performTransactionalWork(null, new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 1, false,
+ false, 1);
transactionManager.resume(originalTransaction);
originalTransaction.enlistResource(proxyXAResource);
// Needs a second resource to make sure we dont get the one
@@ -178,13 +282,13 @@
} catch (ExecuteException e) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
} catch (LinkageError t) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
} catch (Throwable t) {
@@ -194,7 +298,7 @@
}, "Orphan-creator");
thread.start();
synchronized (phase2CommitAborted) {
- if (!phase2CommitAborted.isPhase2CommitAborted()) {
+ if (phase2CommitAborted.getPhase2CommitAbortedCount() < 1) {
phase2CommitAborted.wait();
}
}
@@ -202,7 +306,7 @@
setup();
{
- LocalServer server = getLocalServer(2000);
+ LocalServer server = getLocalServer("2000");
assertTrue(server.getCompletionCounter().getCommitCount() == 0);
assertTrue(server.getCompletionCounter().getRollbackCount() == 0);
server.doRecoveryManagerScan(true);
@@ -210,12 +314,12 @@
assertTrue(server.getCompletionCounter().getRollbackCount() == 1);
}
{
- LocalServer server = getLocalServer(1000);
+ LocalServer server = getLocalServer("1000");
assertTrue(server.getCompletionCounter().getCommitCount() == 0);
assertTrue(server.getCompletionCounter().getRollbackCount() == 0);
server.doRecoveryManagerScan(true);
assertTrue(server.getCompletionCounter().getCommitCount() == 0);
- assertTrue(server.getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(server.getCompletionCounter().getRollbackCount() == 1);
}
}
@@ -226,16 +330,15 @@
@Test
@BMScript("leaveorphan")
public void testOnePhaseXAResourceOrphan() throws Exception {
- assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("3000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
final Phase2CommitAborted phase2CommitAborted = new Phase2CommitAborted();
Thread thread = new Thread(new Runnable() {
public void run() {
int startingTimeout = 0;
try {
- int startingServer = 1000;
- LocalServer originalServer = getLocalServer(startingServer);
+ LocalServer originalServer = getLocalServer("1000");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
TransactionManager transactionManager = originalServer.getTransactionManager();
@@ -245,10 +348,10 @@
int remainingTimeout = (int) (originalServer.getTimeLeftBeforeTransactionTimeout() / 1000);
Xid currentXid = originalServer.getCurrentXid();
originalServer.storeRootTransaction();
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, 2000);
+ XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000");
transactionManager.suspend();
- performTransactionalWork(null, new LinkedList<Integer>(Arrays.asList(new Integer[] { 2000 })), remainingTimeout, currentXid, 2, false,
- false);
+ performTransactionalWork(null, new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 2, false,
+ false, 1);
transactionManager.resume(originalTransaction);
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
@@ -257,19 +360,19 @@
} catch (ExecuteException e) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
} catch (LinkageError t) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
} catch (Throwable t) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
}
@@ -277,7 +380,7 @@
}, "Orphan-creator");
thread.start();
synchronized (phase2CommitAborted) {
- if (!phase2CommitAborted.isPhase2CommitAborted()) {
+ if (phase2CommitAborted.getPhase2CommitAbortedCount() < 1) {
phase2CommitAborted.wait();
}
}
@@ -285,7 +388,7 @@
setup();
{
- LocalServer server = getLocalServer(2000);
+ LocalServer server = getLocalServer("2000");
assertTrue(server.getCompletionCounter().getCommitCount() == 0);
assertTrue(server.getCompletionCounter().getRollbackCount() == 0);
server.doRecoveryManagerScan(true);
@@ -293,12 +396,12 @@
assertTrue(server.getCompletionCounter().getRollbackCount() == 1);
}
{
- LocalServer server = getLocalServer(1000);
+ LocalServer server = getLocalServer("1000");
assertTrue(server.getCompletionCounter().getCommitCount() == 0);
assertTrue(server.getCompletionCounter().getRollbackCount() == 0);
server.doRecoveryManagerScan(true);
assertTrue(server.getCompletionCounter().getCommitCount() == 0);
- assertTrue(server.getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(server.getCompletionCounter().getRollbackCount() == 1);
}
}
@@ -309,16 +412,15 @@
@Test
@BMScript("leave-subordinate-orphan")
public void testOnePhaseSubordinateOrphan() throws Exception {
- assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("3000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
final Phase2CommitAborted phase2CommitAborted = new Phase2CommitAborted();
Thread thread = new Thread(new Runnable() {
public void run() {
int startingTimeout = 0;
try {
- int startingServer = 1000;
- LocalServer originalServer = getLocalServer(startingServer);
+ LocalServer originalServer = getLocalServer("1000");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
TransactionManager transactionManager = originalServer.getTransactionManager();
@@ -328,10 +430,10 @@
int remainingTimeout = (int) (originalServer.getTimeLeftBeforeTransactionTimeout() / 1000);
Xid currentXid = originalServer.getCurrentXid();
originalServer.storeRootTransaction();
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, 2000);
+ XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000");
transactionManager.suspend();
- performTransactionalWork(null, new LinkedList<Integer>(Arrays.asList(new Integer[] { 2000 })), remainingTimeout, currentXid, 2, false,
- false);
+ performTransactionalWork(null, new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 2, false,
+ false, 1);
transactionManager.resume(originalTransaction);
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
@@ -340,19 +442,19 @@
} catch (ExecuteException e) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
} catch (LinkageError t) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
} catch (Throwable t) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
}
@@ -360,21 +462,21 @@
}, "Orphan-creator");
thread.start();
synchronized (phase2CommitAborted) {
- if (!phase2CommitAborted.isPhase2CommitAborted()) {
+ if (phase2CommitAborted.getPhase2CommitAbortedCount() < 1) {
phase2CommitAborted.wait();
}
}
tearDown();
setup();
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getRollbackCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 0);
- getLocalServer(1000).doRecoveryManagerScan(true);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 1);
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getRollbackCount() == 2);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 0);
+ getLocalServer("1000").doRecoveryManagerScan(true);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 1);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 2);
}
@@ -426,16 +528,15 @@
}
};
- assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("3000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
final Phase2CommitAborted phase2CommitAborted = new Phase2CommitAborted();
Thread thread = new Thread(new Runnable() {
public void run() {
int startingTimeout = 0;
try {
- int startingServer = 1000;
- LocalServer originalServer = getLocalServer(startingServer);
+ LocalServer originalServer = getLocalServer("1000");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
TransactionManager transactionManager = originalServer.getTransactionManager();
@@ -445,10 +546,10 @@
int remainingTimeout = (int) (originalServer.getTimeLeftBeforeTransactionTimeout() / 1000);
Xid currentXid = originalServer.getCurrentXid();
originalServer.storeRootTransaction();
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, 2000);
+ XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000");
transactionManager.suspend();
- performTransactionalWork(counter, new LinkedList<Integer>(Arrays.asList(new Integer[] { 2000 })), remainingTimeout, currentXid, 2, false,
- false);
+ performTransactionalWork(counter, new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 2, false,
+ false, 1);
transactionManager.resume(originalTransaction);
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
@@ -457,19 +558,19 @@
} catch (ExecuteException e) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
} catch (LinkageError t) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
} catch (Throwable t) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
}
@@ -477,18 +578,18 @@
}, "Orphan-creator");
thread.start();
synchronized (phase2CommitAborted) {
- if (!phase2CommitAborted.isPhase2CommitAborted()) {
+ if (phase2CommitAborted.getPhase2CommitAbortedCount() < 1) {
phase2CommitAborted.wait();
}
}
- reboot(1000);
+ reboot("1000");
assertTrue(counter.getCommitCount() == 0);
assertTrue(counter.getRollbackCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 0);
- getLocalServer(1000).doRecoveryManagerScan(true);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 1);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 0);
+ getLocalServer("1000").doRecoveryManagerScan(true);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 1);
assertTrue(counter.getCommitCount() == 0);
assertTrue(counter.getRollbackCount() == 2);
}
@@ -501,23 +602,24 @@
public void testRecovery() throws Exception {
tearDown();
setup();
- assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(3000).getCompletionCounter().getRollbackCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getRollbackCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("3000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("3000").getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 0);
final Phase2CommitAborted phase2CommitAborted = new Phase2CommitAborted();
Thread thread = new Thread(new Runnable() {
public void run() {
int startingTimeout = 0;
- List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
+ List<String> nodesToFlowTo = new LinkedList<String>(Arrays.asList(new String[] { "1000", "2000", "3000", "2000", "1000", "2000", "3000",
+ "1000", "3000" }));
try {
doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true, false);
} catch (ExecuteException e) {
System.err.println("Should be a thread death but cest la vie");
synchronized (phase2CommitAborted) {
- phase2CommitAborted.setPhase2CommitAborted(true);
+ phase2CommitAborted.incrementPhase2CommitAborted();
phase2CommitAborted.notify();
}
} catch (Exception e) {
@@ -528,28 +630,27 @@
});
thread.start();
synchronized (phase2CommitAborted) {
- if (!phase2CommitAborted.isPhase2CommitAborted()) {
+ if (phase2CommitAborted.getPhase2CommitAbortedCount() < 1) {
phase2CommitAborted.wait();
}
}
tearDown();
setup();
- getLocalServer(1000).doRecoveryManagerScan(false);
+ getLocalServer("1000").doRecoveryManagerScan(false);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 4);
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 4);
- assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 3);
- assertTrue(getLocalServer(3000).getCompletionCounter().getRollbackCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getRollbackCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 4);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 4);
+ assertTrue(getLocalServer("3000").getCompletionCounter().getCommitCount() == 3);
+ assertTrue(getLocalServer("3000").getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 0);
}
@Test
public void testOnePhaseCommit() throws Exception {
tearDown();
setup();
- int startingServer = 1000;
- LocalServer originalServer = getLocalServer(startingServer);
+ LocalServer originalServer = getLocalServer("1000");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
TransactionManager transactionManager = originalServer.getTransactionManager();
@@ -559,28 +660,27 @@
int remainingTimeout = (int) (originalServer.getTimeLeftBeforeTransactionTimeout() / 1000);
Xid currentXid = originalServer.getCurrentXid();
originalServer.storeRootTransaction();
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, 2000);
+ XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000");
transactionManager.suspend();
- performTransactionalWork(getLocalServer(2000).getCompletionCounter(), new LinkedList<Integer>(Arrays.asList(new Integer[] { 2000 })), remainingTimeout,
- currentXid, 1, false, false);
+ performTransactionalWork(getLocalServer("2000").getCompletionCounter(), new LinkedList<String>(Arrays.asList(new String[] { "2000" })),
+ remainingTimeout, currentXid, 1, false, false, 1);
transactionManager.resume(originalTransaction);
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
transactionManager.commit();
Thread.currentThread().setContextClassLoader(classLoader);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 1);
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 1);
- assertTrue(getLocalServer(2000).getCompletionCounter().getRollbackCount() == 0);
- assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 1);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 1);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 0);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 0);
}
@Test
public void testUnPreparedRollback() throws Exception {
tearDown();
setup();
- int startingServer = 1000;
- LocalServer originalServer = getLocalServer(startingServer);
+ LocalServer originalServer = getLocalServer("1000");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
TransactionManager transactionManager = originalServer.getTransactionManager();
@@ -590,42 +690,45 @@
int remainingTimeout = (int) (originalServer.getTimeLeftBeforeTransactionTimeout() / 1000);
Xid currentXid = originalServer.getCurrentXid();
originalServer.storeRootTransaction();
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, 2000);
+ XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000");
transactionManager.suspend();
- performTransactionalWork(getLocalServer(2000).getCompletionCounter(), new LinkedList<Integer>(Arrays.asList(new Integer[] { 2000 })), remainingTimeout,
- currentXid, 1, false, false);
+ performTransactionalWork(getLocalServer("2000").getCompletionCounter(), new LinkedList<String>(Arrays.asList(new String[] { "2000" })),
+ remainingTimeout, currentXid, 1, false, false, 1);
transactionManager.resume(originalTransaction);
originalTransaction.enlistResource(proxyXAResource);
- originalTransaction
- .registerSynchronization(originalServer.generateProxySynchronization(lookupProvider, originalServer.getNodeName(), 2000, currentXid));
+ originalTransaction.registerSynchronization(originalServer.generateProxySynchronization(lookupProvider, originalServer.getNodeName(), "2000",
+ currentXid));
originalServer.removeRootTransaction(currentXid);
transactionManager.rollback();
Thread.currentThread().setContextClassLoader(classLoader);
- assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
- assertTrue(getLocalServer(2000).getCompletionCounter().getRollbackCount() == 1);
- assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 1);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getCommitCount() == 0);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 1);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 1);
}
@Test
public void testMigrateTransactionRollbackOnlyCommit() throws Exception {
int startingTimeout = 0;
- List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
+ List<String> nodesToFlowTo = new LinkedList<String>(
+ Arrays.asList(new String[] { "1000", "2000", "3000", "2000", "1000", "2000", "3000", "1000", "3000" }));
doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true, true);
}
@Test
public void testMigrateTransactionRollbackOnlyRollback() throws Exception {
int startingTimeout = 0;
- List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
+ List<String> nodesToFlowTo = new LinkedList<String>(
+ Arrays.asList(new String[] { "1000", "2000", "3000", "2000", "1000", "2000", "3000", "1000", "3000" }));
doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, false, true);
}
@Test
public void testMigrateTransactionCommit() throws Exception {
int startingTimeout = 0;
- List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
+ List<String> nodesToFlowTo = new LinkedList<String>(
+ Arrays.asList(new String[] { "1000", "2000", "3000", "2000", "1000", "2000", "3000", "1000", "3000" }));
doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true, false);
}
@@ -633,21 +736,22 @@
public void testMigrateTransactionCommitDiamond() throws Exception {
int startingTimeout = 0;
- List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 1000, 3000, 1000, 2000, 3000 }));
+ List<String> nodesToFlowTo = new LinkedList<String>(Arrays.asList(new String[] { "1000", "2000", "1000", "3000", "1000", "2000", "3000" }));
doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true, false);
}
@Test
public void testMigrateTransactionRollback() throws Exception {
int startingTimeout = 0;
- List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
+ List<String> nodesToFlowTo = new LinkedList<String>(
+ Arrays.asList(new String[] { "1000", "2000", "3000", "2000", "1000", "2000", "3000", "1000", "3000" }));
doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, false, false);
}
@Test
public void testMigrateTransactionRollbackDiamond() throws Exception {
int startingTimeout = 0;
- List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 1000, 3000, 1000, 2000, 3000 }));
+ List<String> nodesToFlowTo = new LinkedList<String>(Arrays.asList(new String[] { "1000", "2000", "1000", "3000", "1000", "2000", "3000" }));
doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, false, false);
}
@@ -657,7 +761,7 @@
setup();
int rootTimeout = 10000;
int subordinateTimeout = 1;
- LocalServer originalServer = getLocalServer(1000);
+ LocalServer originalServer = getLocalServer("1000");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
TransactionManager transactionManager = originalServer.getTransactionManager();
@@ -667,14 +771,14 @@
Xid currentXid = originalServer.getCurrentXid();
originalServer.storeRootTransaction();
originalTransaction.enlistResource(new TestResource(originalServer.getCompletionCounter(), originalServer.getNodeName(), false));
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, 2000);
+ XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000");
transactionManager.suspend();
// Migrate a transaction
- LocalServer currentServer = getLocalServer(2000);
+ LocalServer currentServer = getLocalServer("2000");
ClassLoader parentsClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(currentServer.getClass().getClassLoader());
- currentServer.getAndResumeTransaction(subordinateTimeout, currentXid);
+ currentServer.getAndResumeTransaction(subordinateTimeout, currentXid, 2000);
currentServer.getTransactionManager().getTransaction()
.enlistResource(new TestResource(currentServer.getCompletionCounter(), currentServer.getNodeName(), false));
currentServer.getTransactionManager().suspend();
@@ -693,12 +797,11 @@
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
- assertTrue(getLocalServer(2000).getCompletionCounter().getRollbackCount() == 1);
- assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 2);
+ assertTrue(getLocalServer("2000").getCompletionCounter().getRollbackCount() == 1);
+ assertTrue(getLocalServer("1000").getCompletionCounter().getRollbackCount() == 2);
}
- private void doRecursiveTransactionalWork(int startingTimeout, List<Integer> nodesToFlowTo, boolean commit, boolean rollbackOnlyOnLastNode)
- throws Exception {
+ private void doRecursiveTransactionalWork(int startingTimeout, List<String> nodesToFlowTo, boolean commit, boolean rollbackOnlyOnLastNode) throws Exception {
tearDown();
setup();
@@ -735,7 +838,7 @@
}
};
int totalNodeCount = nodesToFlowTo.size();
- int startingServer = nodesToFlowTo.get(0);
+ String startingServer = nodesToFlowTo.get(0);
LocalServer originalServer = getLocalServer(startingServer);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
@@ -748,7 +851,7 @@
originalServer.storeRootTransaction();
transactionManager.suspend();
DataReturnedFromRemoteServer dataReturnedFromRemoteServer = performTransactionalWork(counter, nodesToFlowTo, remainingTimeout, currentXid, 1, true,
- rollbackOnlyOnLastNode);
+ rollbackOnlyOnLastNode, 1);
transactionManager.resume(transaction);
originalServer.removeRootTransaction(currentXid);
@@ -786,16 +889,19 @@
Thread.currentThread().setContextClassLoader(classLoader);
}
- private DataReturnedFromRemoteServer performTransactionalWork(CompletionCounter counter, List<Integer> nodesToFlowTo, int remainingTimeout, Xid toMigrate,
- int numberOfResourcesToRegister, boolean addSynchronization, boolean rollbackOnlyOnLastNode) throws RollbackException, IllegalStateException,
- XAException, SystemException, NotSupportedException, IOException {
- Integer currentServerName = nodesToFlowTo.remove(0);
+ private DataReturnedFromRemoteServer performTransactionalWork(CompletionCounter counter, List<String> nodesToFlowTo, int remainingTimeout, Xid toMigrate,
+ int numberOfResourcesToRegister, boolean addSynchronization, boolean rollbackOnlyOnLastNode, int nextAvailableSubordinateName)
+ throws RollbackException, IllegalStateException, XAException, SystemException, NotSupportedException, IOException {
+ String currentServerName = nodesToFlowTo.remove(0);
LocalServer currentServer = getLocalServer(currentServerName);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(currentServer.getClass().getClassLoader());
- boolean requiresProxyAtPreviousServer = !currentServer.getAndResumeTransaction(remainingTimeout, toMigrate);
+ boolean requiresProxyAtPreviousServer = !currentServer.getAndResumeTransaction(remainingTimeout, toMigrate, nextAvailableSubordinateName);
+ if (requiresProxyAtPreviousServer) {
+ nextAvailableSubordinateName++;
+ }
// Perform work on the migrated transaction
{
@@ -823,7 +929,7 @@
// user code (rollback/setRollbackOnly) or it may be inactive due to
// the transaction reaper
if (status == Status.STATUS_ACTIVE) {
- Integer nextServerNodeName = nodesToFlowTo.get(0);
+ String nextServerNodeName = nodesToFlowTo.get(0);
// FLOW THE TRANSACTION
remainingTimeout = (int) (currentServer.getTimeLeftBeforeTransactionTimeout() / 1000);
@@ -834,7 +940,7 @@
transactionManager.suspend();
DataReturnedFromRemoteServer dataReturnedFromRemoteServer = performTransactionalWork(counter, nodesToFlowTo, remainingTimeout, currentXid,
- numberOfResourcesToRegister, addSynchronization, rollbackOnlyOnLastNode);
+ numberOfResourcesToRegister, addSynchronization, rollbackOnlyOnLastNode, nextAvailableSubordinateName);
transactionManager.resume(transaction);
// Create a proxy for the new server if necessary, this can
@@ -849,6 +955,7 @@
transaction.enlistResource(proxyXAResource);
transaction.registerSynchronization(currentServer.generateProxySynchronization(lookupProvider, currentServer.getNodeName(),
nextServerNodeName, toMigrate));
+ nextAvailableSubordinateName = dataReturnedFromRemoteServer.getNextAvailableSubordinateName();
} else {
currentServer.cleanupProxyXAResource(proxyXAResource);
}
@@ -879,44 +986,51 @@
// Return to the previous caller back over the transport/classloader
// boundary in this case
Thread.currentThread().setContextClassLoader(classLoader);
- return new DataReturnedFromRemoteServer(requiresProxyAtPreviousServer, transactionState);
+ return new DataReturnedFromRemoteServer(requiresProxyAtPreviousServer, transactionState, nextAvailableSubordinateName);
}
- private static LocalServer getLocalServer(Integer jndiName) {
- int index = (jndiName / 1000) - 1;
+ private static LocalServer getLocalServer(String jndiName) {
+ int index = (Integer.valueOf(jndiName) / 1000) - 1;
return localServers[index];
}
private static class MyLookupProvider implements LookupProvider {
@Override
- public RemoteServer lookup(Integer jndiName) {
- int index = (jndiName / 1000) - 1;
+ public RemoteServer lookup(String jndiName) {
+ int index = (Integer.valueOf(jndiName) / 1000) - 1;
return remoteServers[index];
}
}
private class Phase2CommitAborted {
- private boolean phase2CommitAborted;
+ private int phase2CommitAborted;
- public boolean isPhase2CommitAborted() {
+ public int getPhase2CommitAbortedCount() {
return phase2CommitAborted;
}
- public void setPhase2CommitAborted(boolean phase2CommitAborted) {
- this.phase2CommitAborted = phase2CommitAborted;
+ public void incrementPhase2CommitAborted() {
+ this.phase2CommitAborted++;
}
}
+ /**
+ * This is the transactional data the transport needs to return from remote
+ * instances.
+ */
private class DataReturnedFromRemoteServer {
private boolean proxyRequired;
private int transactionState;
- public DataReturnedFromRemoteServer(boolean proxyRequired, int transactionState) {
+ private Integer nextAvailableSubordinateName;
+
+ public DataReturnedFromRemoteServer(boolean proxyRequired, int transactionState, Integer nextAvailableSubordinateName) {
this.proxyRequired = proxyRequired;
this.transactionState = transactionState;
+ this.nextAvailableSubordinateName = nextAvailableSubordinateName;
}
public boolean isProxyRequired() {
@@ -926,6 +1040,9 @@
public int getTransactionState() {
return transactionState;
}
+
+ public Integer getNextAvailableSubordinateName() {
+ return nextAvailableSubordinateName;
+ }
}
-
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResource.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResource.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -45,17 +45,17 @@
private File file;
- private int serverId;
+ private String serverId;
private CompletionCounter completionCounter;
- public TestResource(CompletionCounter completionCounter, int serverId, boolean readonly) {
+ public TestResource(CompletionCounter completionCounter, String serverId, boolean readonly) {
this.completionCounter = completionCounter;
this.serverId = serverId;
this.readonly = readonly;
}
- public TestResource(CompletionCounter completionCounter, int serverId, File file) throws IOException {
+ public TestResource(CompletionCounter completionCounter, String serverId, File file) throws IOException {
this.completionCounter = completionCounter;
this.serverId = serverId;
this.file = file;
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -36,7 +36,7 @@
private List<TestResource> resources = new ArrayList<TestResource>();
- public TestResourceRecovery(CompletionCounter counter, Integer nodeName) throws IOException {
+ public TestResourceRecovery(CompletionCounter counter, String nodeName) throws IOException {
File file = new File(System.getProperty("user.dir") + "/distributedjta/TestResource/" + nodeName + "/");
if (file.exists() && file.isDirectory()) {
File[] listFiles = file.listFiles();
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestSynchronization.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestSynchronization.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestSynchronization.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -24,9 +24,9 @@
import javax.transaction.Synchronization;
public class TestSynchronization implements Synchronization {
- private int serverId;
+ private String serverId;
- public TestSynchronization(int serverId) {
+ public TestSynchronization(String serverId) {
this.serverId = serverId;
}
Deleted: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/DummyRemoteException.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/DummyRemoteException.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/DummyRemoteException.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -1,28 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package com.arjuna.ats.jta.distributed.server;
-
-public class DummyRemoteException extends Exception {
- public DummyRemoteException(String message) {
- super(message);
- }
-}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -38,10 +38,10 @@
public interface LocalServer {
- public void initialise(LookupProvider lookupProvider, Integer nodeName) throws CoreEnvironmentBeanException, IOException, SecurityException,
+ public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset) throws CoreEnvironmentBeanException, IOException, SecurityException,
NoSuchFieldException, IllegalArgumentException, IllegalAccessException;
- public Integer getNodeName();
+ public String getNodeName();
public TransactionManager getTransactionManager() throws NotSupportedException, SystemException;
@@ -53,16 +53,16 @@
public void removeRootTransaction(Xid toMigrate);
- public boolean getAndResumeTransaction(int remainingTimeout, Xid toImport) throws XAException, InvalidTransactionException, IllegalStateException,
- SystemException;
+ public boolean getAndResumeTransaction(int remainingTimeout, Xid toImport, Integer nextAvailableSubordinateName) throws XAException, InvalidTransactionException, IllegalStateException,
+ SystemException, IOException;
public RemoteServer connectTo();
- public XAResource generateProxyXAResource(LookupProvider lookupProvider, Integer remoteServerName) throws SystemException, IOException;
+ public XAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName) throws SystemException, IOException;
public void cleanupProxyXAResource(XAResource proxyXAResource);
- public Synchronization generateProxySynchronization(LookupProvider lookupProvider, Integer localServerName, Integer remoteServerName, Xid toRegisterAgainst);
+ public Synchronization generateProxySynchronization(LookupProvider lookupProvider, String localServerName, String remoteServerName, Xid toRegisterAgainst);
public Xid getCurrentXid() throws SystemException;
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProvider.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProvider.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProvider.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -22,5 +22,5 @@
package com.arjuna.ats.jta.distributed.server;
public interface LookupProvider {
- public RemoteServer lookup(Integer jndiName);
+ public RemoteServer lookup(String jndiName);
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/RemoteServer.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/RemoteServer.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/RemoteServer.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -21,6 +21,8 @@
*/
package com.arjuna.ats.jta.distributed.server;
+import java.io.IOException;
+
import javax.transaction.SystemException;
import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;
@@ -29,16 +31,14 @@
public void setOffline(boolean offline);
- public int prepare(Xid xid) throws XAException, DummyRemoteException;
+ public int prepare(Xid xid) throws XAException;
- public void commit(Xid xid, boolean onePhase) throws XAException, DummyRemoteException;
+ public void commit(Xid xid, boolean onePhase, boolean recover) throws XAException, IOException;
- public void rollback(Xid xid) throws XAException, DummyRemoteException;
+ public void rollback(Xid xid, boolean recover) throws XAException, IOException;
- public Xid[] recoverFor(Integer parentNodeName) throws XAException, DummyRemoteException;
+ public void forget(Xid xid) throws XAException, IOException;
- public void forget(Xid xid) throws XAException, DummyRemoteException;
+ public void beforeCompletion(Xid xid) throws XAException, SystemException;
- public void beforeCompletion(Xid xid) throws XAException, SystemException, DummyRemoteException;
-
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxySynchronization.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxySynchronization.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxySynchronization.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -26,17 +26,16 @@
import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;
-import com.arjuna.ats.jta.distributed.server.DummyRemoteException;
import com.arjuna.ats.jta.distributed.server.LookupProvider;
public class ProxySynchronization implements Synchronization {
- private int localServerName;
- private int remoteServerName;
+ private String localServerName;
+ private String remoteServerName;
private Xid toRegisterAgainst;
private LookupProvider lookupProvider;
- public ProxySynchronization(LookupProvider lookupProvider, int localServerName, int remoteServerName, Xid toRegisterAgainst) {
+ public ProxySynchronization(LookupProvider lookupProvider, String localServerName, String remoteServerName, Xid toRegisterAgainst) {
this.lookupProvider = lookupProvider;
this.localServerName = localServerName;
this.remoteServerName = remoteServerName;
@@ -52,8 +51,6 @@
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
- } catch (DummyRemoteException e) {
- e.printStackTrace();
}
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -25,11 +25,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import javax.transaction.xa.XAException;
@@ -40,7 +36,6 @@
import com.arjuna.ats.arjuna.common.Uid;
import com.arjuna.ats.jta.distributed.server.CompletionCounter;
-import com.arjuna.ats.jta.distributed.server.DummyRemoteException;
import com.arjuna.ats.jta.distributed.server.LookupProvider;
/**
@@ -50,12 +45,13 @@
public class ProxyXAResource implements XAResource, XAResourceWrapper {
private int transactionTimeout;
- private Integer remoteServerName = -1;
+ private String remoteServerName;
private Map<Xid, File> map;
- private Integer localServerName;
+ private String localServerName;
private LookupProvider lookupProvider;
private CompletionCounter completionCounter;
private File file;
+ private boolean recover;
/**
* Create a new proxy to the remote server.
@@ -64,7 +60,7 @@
* @param localServerName
* @param remoteServerName
*/
- public ProxyXAResource(CompletionCounter completionCounter, LookupProvider lookupProvider, Integer localServerName, Integer remoteServerName, File file) {
+ public ProxyXAResource(CompletionCounter completionCounter, LookupProvider lookupProvider, String localServerName, String remoteServerName, File file) {
this.completionCounter = completionCounter;
this.lookupProvider = lookupProvider;
this.localServerName = localServerName;
@@ -83,13 +79,14 @@
* @param file
* @throws IOException
*/
- public ProxyXAResource(CompletionCounter completionCounter, LookupProvider lookupProvider, Integer localServerName, Integer remoteServerName,
+ public ProxyXAResource(CompletionCounter completionCounter, LookupProvider lookupProvider, String localServerName, String remoteServerName,
Map<Xid, File> map) throws IOException {
this.completionCounter = completionCounter;
this.lookupProvider = lookupProvider;
this.localServerName = localServerName;
this.remoteServerName = remoteServerName;
this.map = map;
+ this.recover = true;
}
public void deleteTemporaryFile() {
@@ -131,7 +128,9 @@
File file = new File(dir, new Uid().fileStringForm());
file.createNewFile();
DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
- fos.writeInt(remoteServerName);
+ byte[] remoteServerNameBytes = remoteServerName.getBytes();
+ fos.writeInt(remoteServerNameBytes.length);
+ fos.write(remoteServerNameBytes);
fos.writeInt(xid.getFormatId());
fos.writeInt(xid.getGlobalTransactionId().length);
fos.write(xid.getGlobalTransactionId());
@@ -152,13 +151,9 @@
throw new XAException(XAException.XAER_RMERR);
}
- try {
- int propagatePrepare = lookupProvider.lookup(remoteServerName).prepare(xid);
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_PREPARED");
- return propagatePrepare;
- } catch (DummyRemoteException ce) {
- throw new XAException(XAException.XA_RETRY);
- }
+ int propagatePrepare = lookupProvider.lookup(remoteServerName).prepare(xid);
+ System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_PREPARED");
+ return propagatePrepare;
}
@Override
@@ -166,11 +161,12 @@
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMIT [" + xid + "]");
try {
- lookupProvider.lookup(remoteServerName).commit(xid, onePhase);
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMITED");
- } catch (DummyRemoteException ce) {
+ lookupProvider.lookup(remoteServerName).commit(xid, onePhase, recover);
+ } catch (IOException e) {
+ e.printStackTrace();
throw new XAException(XAException.XA_RETRY);
}
+ System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMITED");
if (map.get(xid) != null) {
map.get(xid).delete();
@@ -191,16 +187,17 @@
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACK[" + xid + "]");
try {
- lookupProvider.lookup(remoteServerName).rollback(xid);
+ lookupProvider.lookup(remoteServerName).rollback(xid, recover);
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACKED");
- } catch (DummyRemoteException ce) {
- throw new XAException(XAException.XA_RETRY);
} catch (XAException e) {
// We know the remote side must have done a JBTM-917
if (e.errorCode == XAException.XAER_INVAL) {
// We know that this means that the transaction is not known at
// the remote side
}
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new XAException(XAException.XA_RETRY);
}
if (map.get(xid) != null) {
@@ -238,41 +235,14 @@
+ remoteServerName);
}
- List<Xid> toReturn = new ArrayList<Xid>();
- Xid[] recovered = null;
- try {
- recovered = lookupProvider.lookup(remoteServerName).recoverFor(localServerName);
- } catch (DummyRemoteException ce) {
- throw new XAException(XAException.XA_RETRY);
- }
+ // Only done to wake up the other side - wonder what will happen
+ // try {
+ // lookupProvider.lookup(remoteServerName).recover(map.keySet().toArray(new
+ // Xid[0]));
+ // } catch (IOException e) {
+ // throw new XAException(XAException.XA_RETRY);
+ // }
- List<Xid> arrayList = new ArrayList<Xid>();
- arrayList.addAll(map.keySet());
- if (recovered != null) {
- for (int i = 0; i < recovered.length; i++) {
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") recovered: " + recovered[i]);
- Iterator<Xid> iterator = map.keySet().iterator();
- while (iterator.hasNext()) {
- Xid next = iterator.next();
- if (Arrays.equals(next.getGlobalTransactionId(), recovered[i].getGlobalTransactionId())) {
- toReturn.add(next);
- } else if (!iterator.hasNext()) {
- toReturn.add(recovered[i]);
- }
- arrayList.remove(next);
- }
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") added: " + toReturn.get(toReturn.size() - 1));
- }
- }
-
- // We now know the remote server didn't know about these Xids
- List<Xid> knownNoneKnownXids = new ArrayList<Xid>();
- knownNoneKnownXids.addAll(arrayList);
- Iterator<Xid> iterator = knownNoneKnownXids.iterator();
- while (iterator.hasNext()) {
- Xid next = iterator.next();
- map.remove(next).delete();
- }
if ((flag & XAResource.TMSTARTRSCAN) == XAResource.TMSTARTRSCAN) {
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVERD[XAResource.TMSTARTRSCAN]: "
+ remoteServerName);
@@ -281,7 +251,7 @@
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVERD[XAResource.TMENDRSCAN]: "
+ remoteServerName);
}
- return toReturn.toArray(new Xid[0]);
+ return map.keySet().toArray(new Xid[0]);
}
@Override
@@ -289,10 +259,11 @@
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_FORGET [" + xid + "]");
try {
lookupProvider.lookup(remoteServerName).forget(xid);
- System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_FORGETED[" + xid + "]");
- } catch (DummyRemoteException ce) {
+ } catch (IOException e) {
+ e.printStackTrace();
throw new XAException(XAException.XA_RETRY);
}
+ System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_FORGETED[" + xid + "]");
}
@Override
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResourceRecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResourceRecovery.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResourceRecovery.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -44,15 +44,19 @@
private List<ProxyXAResource> resources = new ArrayList<ProxyXAResource>();
- public ProxyXAResourceRecovery(CompletionCounter counter, LookupProvider lookupProvider, Integer id) throws IOException {
- File directory = new File(System.getProperty("user.dir") + "/distributedjta/ProxyXAResource/" + id + "/");
- Map<Integer, Map<Xid, File>> savedData = new HashMap<Integer, Map<Xid, File>>();
+ public ProxyXAResourceRecovery(CompletionCounter counter, LookupProvider lookupProvider, String nodeName) throws IOException {
+ File directory = new File(System.getProperty("user.dir") + "/distributedjta/ProxyXAResource/" + nodeName + "/");
+ Map<String, Map<Xid, File>> savedData = new HashMap<String, Map<Xid, File>>();
if (directory.exists() && directory.isDirectory()) {
File[] listFiles = directory.listFiles();
for (int i = 0; i < listFiles.length; i++) {
File file = listFiles[i];
DataInputStream fis = new DataInputStream(new FileInputStream(file));
- int remoteServerName = fis.readInt();
+ int remoteServerNameLength = fis.readInt();
+ final byte[] remoteServerNameBytes = new byte[remoteServerNameLength];
+ fis.read(remoteServerNameBytes, 0, remoteServerNameLength);
+ String remoteServerName = new String(remoteServerNameBytes);
+
Map<Xid, File> map = savedData.get(remoteServerName);
if (map == null) {
@@ -86,11 +90,11 @@
map.put(xid, file);
}
}
- Iterator<Integer> iterator = savedData.keySet().iterator();
+ Iterator<String> iterator = savedData.keySet().iterator();
while (iterator.hasNext()) {
- Integer remoteServerName = iterator.next();
+ String remoteServerName = iterator.next();
Map<Xid, File> map = savedData.get(remoteServerName);
- resources.add(new ProxyXAResource(counter, lookupProvider, id, remoteServerName, map));
+ resources.add(new ProxyXAResource(counter, lookupProvider, nodeName, remoteServerName, map));
}
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -21,18 +21,20 @@
*/
package com.arjuna.ats.jta.distributed.server.impl;
+import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.transaction.InvalidTransactionException;
import javax.transaction.RollbackException;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
@@ -58,7 +60,6 @@
import com.arjuna.ats.internal.jbossatx.jta.XAResourceRecordWrappingPluginImpl;
import com.arjuna.ats.internal.jta.recovery.arjunacore.RecoveryXids;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
-import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction;
import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateXidImple;
import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinationManager;
import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple;
@@ -67,25 +68,25 @@
import com.arjuna.ats.jta.common.JTAEnvironmentBean;
import com.arjuna.ats.jta.distributed.TestResourceRecovery;
import com.arjuna.ats.jta.distributed.server.CompletionCounter;
-import com.arjuna.ats.jta.distributed.server.DummyRemoteException;
import com.arjuna.ats.jta.distributed.server.LocalServer;
import com.arjuna.ats.jta.distributed.server.LookupProvider;
import com.arjuna.ats.jta.distributed.server.RemoteServer;
+import com.arjuna.ats.jta.xa.XATxConverter;
+import com.arjuna.ats.jta.xa.XidImple;
public class ServerImpl implements LocalServer, RemoteServer {
- private int nodeName;
+ private String nodeName;
private RecoveryManagerService recoveryManagerService;
private TransactionManagerService transactionManagerService;
private boolean offline;
- private LookupProvider lookupProvider;
private Map<SubordinateXidImple, TransactionImple> transactions = new HashMap<SubordinateXidImple, TransactionImple>();
private RecoveryManager _recoveryManager;
private CompletionCounter counter;
+ private Map<SubordinateXidImple, File> subordinateOrphanDetection = new HashMap<SubordinateXidImple, File>();
- public void initialise(LookupProvider lookupProvider, Integer nodeName) throws CoreEnvironmentBeanException, IOException, SecurityException,
+ public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset) throws CoreEnvironmentBeanException, IOException, SecurityException,
NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
- this.lookupProvider = lookupProvider;
this.nodeName = nodeName;
this.counter = new CompletionCounter() {
private int commitCount = 0;
@@ -123,9 +124,9 @@
recoveryEnvironmentBean.setRecoveryBackoffPeriod(1);
recoveryEnvironmentBean.setRecoveryInetAddress(InetAddress.getByName("localhost"));
- recoveryEnvironmentBean.setRecoveryPort(4712 + nodeName);
+ recoveryEnvironmentBean.setRecoveryPort(4712 + portOffset);
recoveryEnvironmentBean.setTransactionStatusManagerInetAddress(InetAddress.getByName("localhost"));
- recoveryEnvironmentBean.setTransactionStatusManagerPort(4713 + nodeName);
+ recoveryEnvironmentBean.setTransactionStatusManagerPort(4713 + portOffset);
List<String> recoveryModuleClassNames = new ArrayList<String>();
recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
@@ -142,7 +143,7 @@
coreEnvironmentBean.setNodeIdentifier(nodeName);
// coreEnvironmentBean.setSocketProcessIdMaxPorts(1);
coreEnvironmentBean.setProcessImplementationClassName(ManualProcessId.class.getName());
- coreEnvironmentBean.setPid(coreEnvironmentBean.getNodeIdentifier());
+ coreEnvironmentBean.setPid(portOffset);
CoordinatorEnvironmentBean coordinatorEnvironmentBean = com.arjuna.ats.arjuna.common.arjPropertyManager.getCoordinatorEnvironmentBean();
coordinatorEnvironmentBean.setEnableStatistics(false);
@@ -173,9 +174,9 @@
jTAEnvironmentBean.setUserTransactionClassName("com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple");
jTAEnvironmentBean
.setTransactionSynchronizationRegistryClassName("com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple");
- List<Integer> xaRecoveryNodes = new ArrayList<Integer>();
+ List<String> xaRecoveryNodes = new ArrayList<String>();
xaRecoveryNodes.add(nodeName);
- jTAEnvironmentBean.setXaRecoveryNodesImpl(xaRecoveryNodes);
+ jTAEnvironmentBean.setXaRecoveryNodes(xaRecoveryNodes);
List<String> xaResourceOrphanFilterClassNames = new ArrayList<String>();
@@ -250,14 +251,32 @@
}
@Override
- public boolean getAndResumeTransaction(int remainingTimeout, Xid toResume) throws XAException, InvalidTransactionException, IllegalStateException,
- SystemException {
+ public boolean getAndResumeTransaction(int remainingTimeout, Xid toResume, Integer nextAvailableSubordinateName) throws XAException, IllegalStateException,
+ SystemException, IOException {
boolean existed = true;
Transaction transaction = transactions.get(new SubordinateXidImple(toResume));
if (transaction == null) {
transaction = SubordinationManager.getTransactionImporter().getImportedTransaction(toResume);
if (transaction == null) {
- transaction = SubordinationManager.getTransactionImporter().importTransaction(toResume, remainingTimeout);
+
+ File dir = new File(System.getProperty("user.dir") + "/distributedjta/SubordinateNameXANodeNameMap/" + TxControl.getXANodeName());
+ dir.mkdirs();
+ File file = new File(dir, new Uid().fileStringForm());
+ file.createNewFile();
+ DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
+ byte[] nodeName = TxControl.getXANodeName().getBytes();
+ fos.writeInt(nodeName.length);
+ fos.write(nodeName);
+ fos.writeInt(nextAvailableSubordinateName);
+ fos.writeInt(toResume.getGlobalTransactionId().length);
+ fos.write(toResume.getGlobalTransactionId());
+
+ subordinateOrphanDetection.put(new SubordinateXidImple(toResume), file);
+
+ XidImple toImport = new XidImple(toResume);
+ XATxConverter.setSubordinateNodeName(toImport.getXID(), nextAvailableSubordinateName);
+
+ transaction = SubordinationManager.getTransactionImporter().importTransaction(toImport, remainingTimeout);
existed = false;
}
}
@@ -266,7 +285,7 @@
}
@Override
- public Integer getNodeName() {
+ public String getNodeName() {
return nodeName;
}
@@ -299,7 +318,7 @@
}
@Override
- public ProxyXAResource generateProxyXAResource(LookupProvider lookupProvider, Integer remoteServerName) throws SystemException, IOException {
+ public ProxyXAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName) throws SystemException, IOException {
// Persist a proxy for the remote server this can mean we try to recover
// transactions at a remote server that did not get chance to
@@ -311,7 +330,9 @@
File file = new File(dir, new Uid().fileStringForm());
file.createNewFile();
DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
- fos.writeInt(remoteServerName);
+ byte[] remoteServerNameBytes = remoteServerName.getBytes();
+ fos.writeInt(remoteServerNameBytes.length);
+ fos.write(remoteServerNameBytes);
fos.writeInt(currentXid.getFormatId());
fos.writeInt(currentXid.getGlobalTransactionId().length);
fos.write(currentXid.getGlobalTransactionId());
@@ -327,7 +348,7 @@
}
@Override
- public Synchronization generateProxySynchronization(LookupProvider lookupProvider, Integer localServerName, Integer remoteServerName, Xid toRegisterAgainst) {
+ public Synchronization generateProxySynchronization(LookupProvider lookupProvider, String localServerName, String remoteServerName, Xid toRegisterAgainst) {
return new ProxySynchronization(lookupProvider, localServerName, remoteServerName, toRegisterAgainst);
}
@@ -346,7 +367,7 @@
}
@Override
- public int prepare(Xid xid) throws XAException, DummyRemoteException {
+ public int prepare(Xid xid) throws XAException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
@@ -357,53 +378,98 @@
}
@Override
- public void commit(Xid xid, boolean onePhase) throws XAException, DummyRemoteException {
+ public void commit(Xid xid, boolean onePhase, boolean recover) throws XAException, IOException {
+ if (recover) {
+ recover(new Xid[] { xid });
+ }
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
SubordinationManager.getXATerminator().commit(xid, onePhase);
+ subordinateOrphanDetection.remove(new SubordinateXidImple(xid)).delete();
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
@Override
- public void rollback(Xid xid) throws XAException, DummyRemoteException {
+ public void rollback(Xid xid, boolean recover) throws XAException, IOException {
+ if (recover) {
+ recover(new Xid[] { xid });
+ }
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
SubordinationManager.getXATerminator().rollback(xid);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
+ subordinateOrphanDetection.remove(new SubordinateXidImple(xid)).delete();
}
}
- @Override
- public Xid[] recoverFor(Integer parentNodeName) throws XAException, DummyRemoteException {
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
- Xid[] recovered = ((XATerminatorImple) SubordinationManager.getXATerminator()).doRecover(parentNodeName, true);
- return recovered;
- } finally {
- Thread.currentThread().setContextClassLoader(contextClassLoader);
+ public void recover(Xid[] toRecover) throws XAException, IOException {
+ // Work out what the subordinate name would be for these transaction
+ // for this server
+ XidImple recoverable = null;
+
+ // Look at the list of subordinate name to XA node name map
+ File directory = new File(System.getProperty("user.dir") + "/distributedjta/SubordinateNameXANodeNameMap/" + nodeName + "/");
+ if (directory.exists() && directory.isDirectory()) {
+ File[] listFiles = directory.listFiles();
+ for (int i = 0; i < listFiles.length; i++) {
+ File file = listFiles[i];
+ DataInputStream fis = new DataInputStream(new FileInputStream(file));
+ int nodeNameLength = fis.readInt();
+ final byte[] nodeNameBytes = new byte[nodeNameLength];
+ fis.read(nodeNameBytes, 0, nodeNameLength);
+ String nodeName = new String(nodeNameBytes);
+
+ // Is the node name this servers node name
+ if (nodeName.equals(TxControl.getXANodeName())) {
+ // Read in the subordinate name for the encapsulated
+ // transaction
+ Integer subordinateNodeName = fis.readInt();
+ int gtridLength = fis.readInt();
+ byte[] gtrid = new byte[gtridLength];
+ fis.read(gtrid, 0, gtridLength);
+
+ // Check if the transaction in the list the client is
+ // requesting
+ for (int j = 0; j < toRecover.length; j++) {
+ Xid toCheck = toRecover[j];
+ byte[] requestedGtrid = toCheck.getGlobalTransactionId();
+ if (Arrays.equals(gtrid, requestedGtrid)) {
+ // Set the subordinate name
+ recoverable = new XidImple(toCheck);
+ XATxConverter.setSubordinateNodeName(recoverable.getXID(), subordinateNodeName);
+ subordinateOrphanDetection.put(new SubordinateXidImple(recoverable), file);
+ }
+ }
+ }
+
+ }
}
+ if (recoverable != null) {
+ ((XATerminatorImple) SubordinationManager.getXATerminator()).doRecover(recoverable);
+ }
}
@Override
- public void forget(Xid xid) throws XAException, DummyRemoteException {
+ public void forget(Xid xid) throws XAException, IOException {
+ recover(new Xid[] { xid });
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
SubordinationManager.getXATerminator().forget(xid);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
+ subordinateOrphanDetection.remove(new SubordinateXidImple(xid)).delete();
}
}
@Override
- public void beforeCompletion(Xid xid) throws XAException, SystemException, DummyRemoteException {
+ public void beforeCompletion(Xid xid) throws XAException, SystemException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/qa/tests/src/org/jboss/jbossts/qa/CrashRecovery13Clients/Test02.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/qa/tests/src/org/jboss/jbossts/qa/CrashRecovery13Clients/Test02.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/qa/tests/src/org/jboss/jbossts/qa/CrashRecovery13Clients/Test02.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -45,12 +45,12 @@
boolean passed = false;
Uid bogusNodeName = new Uid();
- xaRecoveryNodes.add(2);
+ xaRecoveryNodes.add("2");
System.err.println("Bogus XA node name: " + bogusNodeName);
XidImple xid = new XidImple(new Uid());
- int nodeName = XAUtils.getXANodeName(xid);
+ String nodeName = XAUtils.getXANodeName(xid);
// should fail.
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/qa/tests/src/org/jboss/jbossts/qa/CrashRecovery13Impls/RecoveryXAResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/qa/tests/src/org/jboss/jbossts/qa/CrashRecovery13Impls/RecoveryXAResource.java 2011-10-24 08:49:58 UTC (rev 37661)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/qa/tests/src/org/jboss/jbossts/qa/CrashRecovery13Impls/RecoveryXAResource.java 2011-10-24 13:45:05 UTC (rev 37662)
@@ -52,9 +52,9 @@
xids[0] = new XidImple(a);
- int c = com.arjuna.ats.arjuna.coordinator.TxControl.getXANodeName();
+ String c = com.arjuna.ats.arjuna.coordinator.TxControl.getXANodeName();
- int b = 2;
+ String b = "2";
com.arjuna.ats.arjuna.coordinator.TxControl.setXANodeName(b);
More information about the jboss-svn-commits
mailing list