[jboss-svn-commits] JBL Code SVN: r37762 - in labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration: examples/classes/com/arjuna/jta/distributed/example/server and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Dec 1 06:34:57 EST 2011
Author: tomjenkinson
Date: 2011-12-01 06:34:57 -0500 (Thu, 01 Dec 2011)
New Revision: 37762
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/server/LocalServer.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LookupProvider.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/RemoteServerImpl.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/server/LocalServer.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/RemoteServerImpl.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java
Log:
JBTM-895 updated the documentation to make the transports requirements clearer
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/ExampleDistributedJTATestCase.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -229,13 +229,12 @@
// that
// it can propagate the transaction completion events to the
// subordinate
- transaction.enlistResource(originalServer.generateProxyXAResource(lookupProvider, nextServerNodeName,
- dataReturnedFromRemoteServer.getRemoteXidCreated()));
+ transaction.enlistResource(originalServer.generateProxyXAResource(nextServerNodeName, dataReturnedFromRemoteServer.getRemoteXidCreated()));
// Register a synchronization that can proxy the
// beforeCompletion
// event to the remote side, after completion events are the
// responsibility of the remote server to initiate
- transaction.registerSynchronization(originalServer.generateProxySynchronization(lookupProvider, nextServerNodeName, currentXid));
+ transaction.registerSynchronization(originalServer.generateProxySynchronization(nextServerNodeName, currentXid));
// Deference the local copy of the current transaction so the GC
// can
@@ -302,7 +301,7 @@
// 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.
- Xid requiresProxyAtPreviousServer = currentServer.getAndResumeTransaction(remainingTimeout, toMigrate);
+ Xid requiresProxyAtPreviousServer = currentServer.locateOrImportTransactionThenResumeIt(remainingTimeout, toMigrate);
{
// Perform work on the migrated transaction
@@ -350,10 +349,9 @@
// to the remote server
if (dataReturnedFromRemoteServer.getRemoteXidCreated() != null) {
// Formally enlist the resource
- transaction.enlistResource(currentServer.generateProxyXAResource(lookupProvider, nextServerNodeName,
- dataReturnedFromRemoteServer.getRemoteXidCreated()));
+ transaction.enlistResource(currentServer.generateProxyXAResource(nextServerNodeName, dataReturnedFromRemoteServer.getRemoteXidCreated()));
// Register a sync
- transaction.registerSynchronization(currentServer.generateProxySynchronization(lookupProvider, nextServerNodeName, toMigrate));
+ transaction.registerSynchronization(currentServer.generateProxySynchronization(nextServerNodeName, toMigrate));
}
// Align the local state with the returning state of the
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LocalServer.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -123,29 +123,29 @@
* @throws SystemException
* @throws IOException
*/
- public Xid getAndResumeTransaction(int remainingTimeout, Xid toImport) throws XAException, InvalidTransactionException, IllegalStateException,
- SystemException, IOException;
+ public Xid locateOrImportTransactionThenResumeIt(int remainingTimeout, Xid toImport) throws XAException, InvalidTransactionException,
+ IllegalStateException, SystemException, IOException;
/**
* Transport specific function to generate a proxy for a remote server.
*
- * @param lookupProvider
* @param remoteServerName
+ *
* @return
* @throws IOException
* @throws SystemException
*/
- public XAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName, Xid migratedTransaction) throws SystemException;
+ public XAResource generateProxyXAResource(String remoteServerName, Xid migratedTransaction) throws SystemException;
/**
* Generate a proxy synchronization
*
- * @param lookupProvider
* @param remoteServerName
* @param toRegisterAgainst
+ *
* @return
*/
- public Synchronization generateProxySynchronization(LookupProvider lookupProvider, String remoteServerName, Xid toRegisterAgainst);
+ public Synchronization generateProxySynchronization(String remoteServerName, Xid toRegisterAgainst);
/**
* Get the current Xid - this is what will be propagated to the remote
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LookupProvider.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LookupProvider.java 2011-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LookupProvider.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -21,6 +21,9 @@
*/
package com.arjuna.jta.distributed.example.server;
+/**
+ * Simulates a JNDI environment. Should be considered a black box.
+ */
public class LookupProvider {
private static LookupProvider instance;
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/RemoteServer.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -21,24 +21,76 @@
*/
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;
+/**
+ * This interface attempts to illustrate the network endpoint requirements of
+ * the remote transaction server with regards subordinate transactions.
+ *
+ * <p>
+ * Many of the methods are required to provide a recover parameter, this is
+ * because when using Serializable ProxyXAResources, the recover method is not
+ * invoked and therfore the remote server will not have had chance to recover
+ * the subordinate transactions.
+ */
public interface RemoteServer {
+ /**
+ * Prepare the subordinate transaction
+ *
+ * @param xid
+ * @param recover
+ * @return
+ * @throws XAException
+ */
public int prepare(Xid xid, boolean recover) throws XAException;
+ /**
+ * Commit the subordinate transaction.
+ *
+ * @param xid
+ * @param onePhase
+ * @param recover
+ * @throws XAException
+ */
public void commit(Xid xid, boolean onePhase, boolean recover) throws XAException;
+ /**
+ * Rollback the subordinate transaction.
+ *
+ * @param xid
+ * @param recover
+ * @throws XAException
+ */
public void rollback(Xid xid, boolean recover) throws XAException;
+ /**
+ * Forget a subordinate transaction.
+ *
+ * @param xid
+ * @param recover
+ * @throws XAException
+ */
public void forget(Xid xid, boolean recover) throws XAException;
- public void beforeCompletion(Xid xid) throws XAException, SystemException;
+ /**
+ * Proxy synchronizations will need to invoke this.
+ *
+ * @param xid
+ * @throws SystemException
+ */
+ public void beforeCompletion(Xid xid) throws SystemException;
+ /**
+ * This is used by the ProxyXAResourceRecovery helper class to detect
+ * orphaned subordinate transactions.
+ *
+ * @param localServerName
+ * @return
+ * @throws XAException
+ */
public Xid[] recoverFor(String localServerName) 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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxySynchronization.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -23,33 +23,39 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
-import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;
import com.arjuna.jta.distributed.example.server.LookupProvider;
+/**
+ * An example to show how the transport can register a proxy synchronization.
+ *
+ * <p>
+ * Note that we do not proxy the afterCompletion, this is left to run locally
+ * per subordinate.
+ */
public class ProxySynchronization implements Synchronization {
private String localServerName;
private String remoteServerName;
private Xid toRegisterAgainst;
- private LookupProvider lookupProvider;
- public ProxySynchronization(LookupProvider lookupProvider, String localServerName, String remoteServerName, Xid toRegisterAgainst) {
- this.lookupProvider = lookupProvider;
+ public ProxySynchronization(String localServerName, String remoteServerName, Xid toRegisterAgainst) {
this.localServerName = localServerName;
this.remoteServerName = remoteServerName;
this.toRegisterAgainst = toRegisterAgainst;
}
+ /**
+ * Propagate the before completion in a transport specific manner.
+ */
@Override
public void beforeCompletion() {
System.out.println("ProxySynchronization (" + localServerName + ":" + remoteServerName + ") beforeCompletion");
try {
- lookupProvider.lookup(remoteServerName).beforeCompletion(toRegisterAgainst);
- } catch (XAException e) {
- e.printStackTrace();
+ LookupProvider.getInstance().lookup(remoteServerName).beforeCompletion(toRegisterAgainst);
} catch (SystemException e) {
+ // Unfortunately we cannot do much else here
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResource.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -34,14 +34,17 @@
/**
* I chose for this class to implement XAResourceWrapper so that I can provide a
* name to the Transaction manager for it to store in its XID.
+ *
+ * <p>
+ * In the normal situation, a ProxyXAResource is Serialized, therefore we do not
+ * get the chance to recover the transactions in a call to
+ * XAResource::recover(), therefore the ProxyXAResource must tell the remote
+ * side when it calls each method, whether or not to attempt to recover the
+ * transaction before invoking its transactional directive, this may be seen in
+ * the prepare, commit, rollback and forget method.
*/
public class ProxyXAResource implements XAResource, XAResourceWrapper, Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
private int transactionTimeout;
private String remoteServerName;
private String localServerName;
@@ -92,9 +95,7 @@
}
/**
- * Prepare the resource, save the XID locally first, the propagate the
- * prepare. This ensures that in recovery we know the XID to ask a remote
- * server about.
+ * This propagates the transaction directive in a transport specific manner.
*/
@Override
public synchronized int prepare(Xid xid) throws XAException {
@@ -106,6 +107,9 @@
return propagatePrepare;
}
+ /**
+ * This propagates the transaction directive in a transport specific manner.
+ */
@Override
public synchronized void commit(Xid xid, boolean onePhase) throws XAException {
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMIT [" + xid + "]");
@@ -115,6 +119,9 @@
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMITED");
}
+ /**
+ * This propagates the transaction directive in a transport specific manner.
+ */
@Override
public synchronized void rollback(Xid xid) throws XAException {
System.out.println(" ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACK[" + xid + "]");
@@ -125,14 +132,9 @@
}
/**
- * This will ensure that the remote server has loaded the subordinate
- * transaction.
- *
- * @return It returns the proxies view of the XID state, returning the
- * remote servers view of the XID would present an XID to the local
- * server that it knows nothing about and indeed potentially the
- * remote server does not have a corresponding record of the XID in
- * case of failure during prepare.
+ * This method is used when the local side is attempting to detect
+ * subordinate transactions that prepared remotely but the local
+ * ProxyXAResource has not prepared and are therefore orphaned.
*/
@Override
public Xid[] recover(int flag) throws XAException {
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResourceRecovery.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -21,7 +21,6 @@
*/
package com.arjuna.jta.distributed.example.server.impl;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -29,11 +28,20 @@
import org.jboss.tm.XAResourceRecovery;
+/**
+ * This class is required by the transaction manager so that it can query the
+ * list of running subordinate transactions which have it as a parent. Typically
+ * we will know about these via the <code>Serializable</code>
+ * <code>ProxyXAResource</code> class. However scenarios exist whereby the
+ * subordinate has a prepared transaction and failed to return to the parent or
+ * the parent failed itself. In this case we need to query these XIDs from the
+ * remote server to detect these orphans.
+ */
public class ProxyXAResourceRecovery implements XAResourceRecovery {
private List<ProxyXAResource> resources = new ArrayList<ProxyXAResource>();
- public ProxyXAResourceRecovery(String nodeName, String[] toRecoverFor) throws IOException {
+ public ProxyXAResourceRecovery(String nodeName, String[] toRecoverFor) {
for (int i = 0; i < toRecoverFor.length; i++) {
resources.add(new ProxyXAResource(nodeName, toRecoverFor[i]));
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/RemoteServerImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/RemoteServerImpl.java 2011-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/RemoteServerImpl.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -39,6 +39,13 @@
* is to remove the classloader behavior as that is purely to allow the test to
* run multiple servers within a single VM. When reading this class, tend to
* ignore the classloader work as that is test scaffolding.
+ *
+ * <p>
+ * In the normal situation, a ProxyXAResource is Serialized, therefore we do not
+ * get the chance to recover the transactions in a call to
+ * XAResource::recover(), therefore the ProxyXAResource must tell us when it
+ * calls each method, whether or not to attempt to recover the transaction
+ * before invoking its transactional directive.
*/
public class RemoteServerImpl implements RemoteServer {
/**
@@ -132,9 +139,10 @@
* @param recover
* Should be set by the clients ProxyXAResource when the client
* knows the remote side needs the transaction loading.
+ * @throws SystemException
*/
@Override
- public void beforeCompletion(Xid xid) throws XAException, SystemException {
+ public void beforeCompletion(Xid xid) throws SystemException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ServerImpl.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -57,6 +57,18 @@
import com.arjuna.jta.distributed.example.server.LookupProvider;
import com.arjuna.jta.distributed.example.server.RemoteServer;
+/**
+ * Most of this class is self explanatory, the main part to take note of is how
+ * <code>locateOrImportTransactionThenResumeIt</code>,
+ * <code>storeRootTransaction</code> and <code>remoteRootTransaction</code>
+ * interact with each other.
+ *
+ * <p>
+ * It is the responsibility of the root transaction manager to cache the root
+ * transaction in a manner that incoming subordinates may be able to resume the
+ * root transaction at that node, rather than creating a subordinate which would
+ * be inefficient.
+ */
public class ServerImpl implements LocalServer {
private String nodeName;
@@ -65,6 +77,9 @@
private Map<SubordinateXidImple, TransactionImple> rootTransactionsAsSubordinate = new HashMap<SubordinateXidImple, TransactionImple>();
private RecoveryManager _recoveryManager;
+ /**
+ * This is typically done by the application server.
+ */
public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset, String[] clusterBuddies) throws CoreEnvironmentBeanException,
IOException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
this.nodeName = nodeName;
@@ -153,12 +168,52 @@
}
@Override
+ public RemoteServer connectTo() {
+ return new RemoteServerImpl();
+ }
+
+ @Override
+ public String getNodeName() {
+ return nodeName;
+ }
+
+ @Override
public TransactionManager getTransactionManager() {
return transactionManagerService.getTransactionManager();
}
@Override
- public Xid getAndResumeTransaction(int remainingTimeout, Xid toResume) throws XAException, IllegalStateException, SystemException, InvalidTransactionException {
+ public Xid getCurrentXid() throws SystemException {
+ TransactionImple transaction = ((TransactionImple) transactionManagerService.getTransactionManager().getTransaction());
+ return transaction.getTxId();
+ }
+
+ /**
+ * This factory method is provided purely for the test purposes to ensure
+ * the correct classloader is used.
+ */
+ @Override
+ public ProxyXAResource generateProxyXAResource(String remoteServerName, Xid migratedXid) throws SystemException {
+ return new ProxyXAResource(nodeName, remoteServerName, migratedXid);
+ }
+
+ /**
+ * This factory method is provided purely for the test purposes to ensure
+ * the correct classloader is used.
+ */
+ @Override
+ public Synchronization generateProxySynchronization(String remoteServerName, Xid toRegisterAgainst) {
+ return new ProxySynchronization(nodeName, remoteServerName, toRegisterAgainst);
+ }
+
+ /**
+ * This method first checks a local <code>Map</code> to ensure that if the
+ * server being flowed to is actually where the root transaction resides
+ * then that transaction is resumed, rather than a subordinate created.
+ */
+ @Override
+ public Xid locateOrImportTransactionThenResumeIt(int remainingTimeout, Xid toResume) throws XAException, IllegalStateException, SystemException,
+ InvalidTransactionException {
Xid toReturn = null;
Transaction transaction = rootTransactionsAsSubordinate.get(new SubordinateXidImple(toResume));
if (transaction == null) {
@@ -172,41 +227,24 @@
return toReturn;
}
+ /**
+ * Cache the root transaction, this is important if the transaction flows
+ * back to this node, then we want to associate resources with the root
+ * transaction, rather than a subordinate.
+ */
@Override
- public String getNodeName() {
- return nodeName;
- }
-
- @Override
public void storeRootTransaction() throws SystemException {
TransactionImple transaction = ((TransactionImple) transactionManagerService.getTransactionManager().getTransaction());
Xid txId = transaction.getTxId();
rootTransactionsAsSubordinate.put(new SubordinateXidImple(txId), transaction);
}
+ /**
+ * After the transaction completes, remove the transaction from the local
+ * cache. This could have been done by a <code>Synchronization</code>.
+ */
@Override
- public Xid getCurrentXid() throws SystemException {
- TransactionImple transaction = ((TransactionImple) transactionManagerService.getTransactionManager().getTransaction());
- return transaction.getTxId();
- }
-
- @Override
public void removeRootTransaction(Xid toMigrate) {
rootTransactionsAsSubordinate.remove(new SubordinateXidImple(toMigrate));
}
-
- @Override
- public ProxyXAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName, Xid migratedXid) throws SystemException {
- return new ProxyXAResource(getNodeName(), remoteServerName, migratedXid);
- }
-
- @Override
- public Synchronization generateProxySynchronization(LookupProvider lookupProvider, String remoteServerName, Xid toRegisterAgainst) {
- return new ProxySynchronization(lookupProvider, nodeName, remoteServerName, toRegisterAgainst);
- }
-
- @Override
- public RemoteServer connectTo() {
- return new RemoteServerImpl();
- }
}
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -152,7 +152,7 @@
DataReturnedFromRemoteServer performTransactionalWork = performTransactionalWork(
new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 2, false, false);
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000", performTransactionalWork.getProxyRequired());
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("2000", performTransactionalWork.getProxyRequired());
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
transactionManager.commit();
@@ -200,7 +200,7 @@
DataReturnedFromRemoteServer performTransactionalWork = performTransactionalWork(
new LinkedList<String>(Arrays.asList(new String[] { "1000" })), remainingTimeout, currentXid, 2, false, false);
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "1000", performTransactionalWork.getProxyRequired());
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("1000", performTransactionalWork.getProxyRequired());
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
transactionManager.commit();
@@ -291,7 +291,7 @@
DataReturnedFromRemoteServer performTransactionalWork = performTransactionalWork(
new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 1, false, false);
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000", performTransactionalWork.getProxyRequired());
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("2000", performTransactionalWork.getProxyRequired());
originalTransaction.enlistResource(proxyXAResource);
// Needs a second resource to make sure we dont get the one
// phase optimization happening
@@ -374,7 +374,7 @@
DataReturnedFromRemoteServer performTransactionalWork = performTransactionalWork(
new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 2, false, false);
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000", performTransactionalWork.getProxyRequired());
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("2000", performTransactionalWork.getProxyRequired());
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
transactionManager.commit();
@@ -457,7 +457,7 @@
DataReturnedFromRemoteServer performTransactionalWork = performTransactionalWork(
new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 2, false, false);
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000", performTransactionalWork.getProxyRequired());
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("2000", performTransactionalWork.getProxyRequired());
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
transactionManager.commit();
@@ -545,7 +545,7 @@
DataReturnedFromRemoteServer performTransactionalWork = performTransactionalWork(
new LinkedList<String>(Arrays.asList(new String[] { "2000" })), remainingTimeout, currentXid, 2, false, false);
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000", performTransactionalWork.getProxyRequired());
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("2000", performTransactionalWork.getProxyRequired());
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
transactionManager.commit();
@@ -661,7 +661,7 @@
DataReturnedFromRemoteServer performTransactionalWork = performTransactionalWork(new LinkedList<String>(Arrays.asList(new String[] { "2000" })),
remainingTimeout, currentXid, 1, false, false);
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000", performTransactionalWork.getProxyRequired());
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("2000", performTransactionalWork.getProxyRequired());
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
transactionManager.commit();
@@ -692,10 +692,9 @@
DataReturnedFromRemoteServer performTransactionalWork = performTransactionalWork(new LinkedList<String>(Arrays.asList(new String[] { "2000" })),
remainingTimeout, currentXid, 1, false, false);
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000", performTransactionalWork.getProxyRequired());
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("2000", performTransactionalWork.getProxyRequired());
originalTransaction.enlistResource(proxyXAResource);
- originalTransaction.registerSynchronization(originalServer.generateProxySynchronization(lookupProvider, originalServer.getNodeName(), "2000",
- currentXid));
+ originalTransaction.registerSynchronization(originalServer.generateProxySynchronization("2000", currentXid));
originalServer.removeRootTransaction(currentXid);
transactionManager.rollback();
Thread.currentThread().setContextClassLoader(classLoader);
@@ -782,14 +781,14 @@
LocalServer currentServer = getLocalServer("2000");
ClassLoader parentsClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(currentServer.getClass().getClassLoader());
- Xid migratedXid = currentServer.getAndResumeTransaction(subordinateTimeout, currentXid);
+ Xid migratedXid = currentServer.locateOrImportTransactionThenResumeIt(subordinateTimeout, currentXid);
currentServer.getTransactionManager().getTransaction().enlistResource(new TestResource(currentServer.getNodeName(), false));
currentServer.getTransactionManager().suspend();
Thread.currentThread().setContextClassLoader(parentsClassLoader);
// Complete the transaction at the original server
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000", migratedXid);
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("2000", migratedXid);
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
Thread.currentThread().sleep((subordinateTimeout + 1) * 1000);
@@ -828,14 +827,14 @@
LocalServer currentServer = getLocalServer("2000");
ClassLoader parentsClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(currentServer.getClass().getClassLoader());
- Xid migratedXid = currentServer.getAndResumeTransaction(subordinateTimeout, currentXid);
+ Xid migratedXid = currentServer.locateOrImportTransactionThenResumeIt(subordinateTimeout, currentXid);
currentServer.getTransactionManager().getTransaction().enlistResource(new TestResource(currentServer.getNodeName(), false));
currentServer.getTransactionManager().suspend();
Thread.currentThread().setContextClassLoader(parentsClassLoader);
// Complete the transaction at the original server
transactionManager.resume(originalTransaction);
- XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, "2000", migratedXid);
+ XAResource proxyXAResource = originalServer.generateProxyXAResource("2000", migratedXid);
originalTransaction.enlistResource(proxyXAResource);
originalServer.removeRootTransaction(currentXid);
transactionManager.commit();
@@ -923,7 +922,7 @@
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(currentServer.getClass().getClassLoader());
- Xid requiresProxyAtPreviousServer = currentServer.getAndResumeTransaction(remainingTimeout, toMigrate);
+ Xid requiresProxyAtPreviousServer = currentServer.locateOrImportTransactionThenResumeIt(remainingTimeout, toMigrate);
// Perform work on the migrated transaction
{
@@ -973,11 +972,9 @@
// performance drain and will result in multiple subordinate
// transactions and performance issues
if (dataReturnedFromRemoteServer.getProxyRequired() != null) {
- XAResource proxyXAResource = currentServer.generateProxyXAResource(lookupProvider, nextServerNodeName,
- dataReturnedFromRemoteServer.getProxyRequired());
+ XAResource proxyXAResource = currentServer.generateProxyXAResource(nextServerNodeName, dataReturnedFromRemoteServer.getProxyRequired());
transaction.enlistResource(proxyXAResource);
- transaction.registerSynchronization(currentServer.generateProxySynchronization(lookupProvider, currentServer.getNodeName(),
- nextServerNodeName, toMigrate));
+ transaction.registerSynchronization(currentServer.generateProxySynchronization(nextServerNodeName, toMigrate));
}
// Align the local state with the returning state of the
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -52,14 +52,14 @@
public void removeRootTransaction(Xid toMigrate);
- public Xid getAndResumeTransaction(int remainingTimeout, Xid toImport) throws XAException, InvalidTransactionException, IllegalStateException,
- SystemException, IOException;
+ public Xid locateOrImportTransactionThenResumeIt(int remainingTimeout, Xid toImport) throws XAException, InvalidTransactionException,
+ IllegalStateException, SystemException, IOException;
public RemoteServer connectTo();
- public XAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName, Xid xid) throws SystemException, IOException;
+ public XAResource generateProxyXAResource(String remoteServerName, Xid xid) throws SystemException, IOException;
- public Synchronization generateProxySynchronization(LookupProvider lookupProvider, String localServerName, String remoteServerName, Xid toRegisterAgainst);
+ public Synchronization generateProxySynchronization(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/RemoteServer.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/RemoteServer.java 2011-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/RemoteServer.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -35,7 +35,7 @@
public void forget(Xid xid, boolean recover) throws XAException;
- public void beforeCompletion(Xid xid) throws XAException, SystemException;
+ public void beforeCompletion(Xid xid) throws SystemException;
public Xid[] recoverFor(String localServerName) throws XAException;
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxySynchronization.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -23,7 +23,6 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
-import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;
import com.arjuna.ats.jta.distributed.server.LookupProvider;
@@ -33,10 +32,8 @@
private String localServerName;
private String remoteServerName;
private Xid toRegisterAgainst;
- private LookupProvider lookupProvider;
- public ProxySynchronization(LookupProvider lookupProvider, String localServerName, String remoteServerName, Xid toRegisterAgainst) {
- this.lookupProvider = lookupProvider;
+ public ProxySynchronization(String localServerName, String remoteServerName, Xid toRegisterAgainst) {
this.localServerName = localServerName;
this.remoteServerName = remoteServerName;
this.toRegisterAgainst = toRegisterAgainst;
@@ -46,10 +43,9 @@
public void beforeCompletion() {
System.out.println("ProxySynchronization (" + localServerName + ":" + remoteServerName + ") beforeCompletion");
try {
- lookupProvider.lookup(remoteServerName).beforeCompletion(toRegisterAgainst);
- } catch (XAException e) {
- e.printStackTrace();
+ LookupProvider.getInstance().lookup(remoteServerName).beforeCompletion(toRegisterAgainst);
} catch (SystemException e) {
+ // Nothing we can really do here
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -35,14 +35,15 @@
/**
* I chose for this class to implement XAResourceWrapper so that I can provide a
* name to the Transaction manager for it to store in its XID.
+ * <p>
+ * In the normal situation, a ProxyXAResource is Serialized, therefore we do not
+ * get the chance to recover the transactions in a call to
+ * XAResource::recover(), therefore the ProxyXAResource must tell the remote
+ * side when it calls each method, whether or not to attempt to recover the
+ * transaction before invoking its transactional directive.
*/
public class ProxyXAResource implements XAResource, XAResourceWrapper, Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
private int transactionTimeout;
private String remoteServerName;
private String localServerName;
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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResourceRecovery.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -21,7 +21,6 @@
*/
package com.arjuna.ats.jta.distributed.server.impl;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +32,7 @@
private List<ProxyXAResource> resources = new ArrayList<ProxyXAResource>();
- public ProxyXAResourceRecovery(String nodeName, String[] toRecoverFor) throws IOException {
+ public ProxyXAResourceRecovery(String nodeName, String[] toRecoverFor) {
for (int i = 0; i < toRecoverFor.length; i++) {
resources.add(new ProxyXAResource(nodeName, toRecoverFor[i]));
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/RemoteServerImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/RemoteServerImpl.java 2011-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/RemoteServerImpl.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -92,7 +92,7 @@
}
@Override
- public void beforeCompletion(Xid xid) throws XAException, SystemException {
+ public void beforeCompletion(Xid xid) throws 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/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-12-01 10:28:12 UTC (rev 37761)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java 2011-12-01 11:34:57 UTC (rev 37762)
@@ -25,11 +25,9 @@
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 java.util.Set;
import javax.transaction.RollbackException;
import javax.transaction.Synchronization;
@@ -56,8 +54,6 @@
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
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.TransactionImporterImple;
-import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple;
import com.arjuna.ats.jbossatx.jta.RecoveryManagerService;
import com.arjuna.ats.jbossatx.jta.TransactionManagerService;
import com.arjuna.ats.jta.common.JTAEnvironmentBean;
@@ -65,7 +61,6 @@
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.XidImple;
public class ServerImpl implements LocalServer {
@@ -210,7 +205,8 @@
}
@Override
- public Xid getAndResumeTransaction(int remainingTimeout, Xid toResume) throws XAException, IllegalStateException, SystemException, IOException {
+ public Xid locateOrImportTransactionThenResumeIt(int remainingTimeout, Xid toResume) throws XAException, IllegalStateException, SystemException,
+ IOException {
Xid toReturn = null;
Transaction transaction = rootTransactionsAsSubordinate.get(new SubordinateXidImple(toResume));
if (transaction == null) {
@@ -253,13 +249,13 @@
}
@Override
- public ProxyXAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName, Xid migratedXid) throws SystemException, IOException {
- return new ProxyXAResource(getNodeName(), remoteServerName, migratedXid);
+ public ProxyXAResource generateProxyXAResource(String remoteServerName, Xid migratedXid) throws SystemException, IOException {
+ return new ProxyXAResource(nodeName, remoteServerName, migratedXid);
}
@Override
- public Synchronization generateProxySynchronization(LookupProvider lookupProvider, String localServerName, String remoteServerName, Xid toRegisterAgainst) {
- return new ProxySynchronization(lookupProvider, localServerName, remoteServerName, toRegisterAgainst);
+ public Synchronization generateProxySynchronization(String remoteServerName, Xid toRegisterAgainst) {
+ return new ProxySynchronization(nodeName, remoteServerName, toRegisterAgainst);
}
@Override
@@ -267,5 +263,4 @@
return new RemoteServerImpl();
}
-
}
More information about the jboss-svn-commits
mailing list