[jboss-svn-commits] JBL Code SVN: r37599 - in labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna: ats/jta/distributed and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Oct 19 04:37:37 EDT 2011


Author: tomjenkinson
Date: 2011-10-19 04:37:36 -0400 (Wed, 19 Oct 2011)
New Revision: 37599

Added:
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/SimpleIsolatedServers.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
Removed:
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResource.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestSynchronization.java
Modified:
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java
Log:
JBTM-895 renamed to make it clear it is an example

Deleted: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java	2011-10-19 08:35:16 UTC (rev 37598)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java	2011-10-19 08:37:36 UTC (rev 37599)
@@ -1,344 +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;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.InvalidTransactionException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.xa.XAException;
-import javax.transaction.xa.XAResource;
-import javax.transaction.xa.Xid;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.arjuna.ats.arjuna.common.CoreEnvironmentBeanException;
-import com.arjuna.ats.jta.distributed.server.CompletionCounter;
-import com.arjuna.ats.jta.distributed.server.IsolatableServersClassLoader;
-import com.arjuna.ats.jta.distributed.server.LocalServer;
-import com.arjuna.ats.jta.distributed.server.LookupProvider;
-import com.arjuna.ats.jta.distributed.server.RemoteServer;
-
-public class SimpleIsolatedServers {
-	private static LookupProvider lookupProvider = new MyLookupProvider();
-	private static LocalServer[] localServers = new LocalServer[3];
-	private static RemoteServer[] remoteServers = new RemoteServer[3];
-
-	@BeforeClass
-	public static void setup() throws SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, ClassNotFoundException,
-			CoreEnvironmentBeanException, IOException, IllegalArgumentException, NoSuchFieldException {
-		for (int i = 0; i < localServers.length; i++) {
-			ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-			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);
-			remoteServers[i] = localServers[i].connectTo();
-			Thread.currentThread().setContextClassLoader(contextClassLoader);
-		}
-	}
-
-	@Test
-	public void testRecovery() throws IOException {
-		assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 0);
-		assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
-		assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
-		// Start out at the first server
-		// getLocalServer(3000).doRecoveryManagerScan();
-		// getLocalServer(2000).doRecoveryManagerScan();
-		getLocalServer(1000).doRecoveryManagerScan();
-
-		assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 3);
-		assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 3);
-		assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 3);
-	}
-
-	@Test
-	public void testMigrateTransactionCommit() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
-			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
-
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
-		int startingTimeout = 0;
-		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
-		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true);
-	}
-
-	@Test
-	public void testMigrateTransactionCommitDiamond() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
-			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
-
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
-		int startingTimeout = 0;
-		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 1000, 3000, 1000, 2000, 3000 }));
-		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true);
-	}
-
-	@Test
-	public void testMigrateTransactionRollback() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
-			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
-
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
-		int startingTimeout = 0;
-		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
-		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, false);
-	}
-
-	@Test
-	public void testMigrateTransactionRollbackDiamond() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
-			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
-
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
-		int startingTimeout = 0;
-		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 1000, 3000, 1000, 2000, 3000 }));
-		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, false);
-	}
-
-	@Test
-	public void testMigrateTransactionSubordinateTimeout() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
-			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException, InterruptedException {
-
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
-		int rootTimeout = 10000;
-		int subordinateTimeout = 1;
-
-		// Start out at the first server
-		CompletionCounter counter = new CompletionCounter() {
-			private int commitCount = 0;
-			private int rollbackCount = 0;
-
-			@Override
-			public void incrementCommit() {
-				commitCount++;
-
-			}
-
-			@Override
-			public void incrementRollback() {
-				rollbackCount++;
-			}
-
-			@Override
-			public int getCommitCount() {
-				return commitCount;
-			}
-
-			@Override
-			public int getRollbackCount() {
-				return rollbackCount;
-			}
-
-			@Override
-			public void resetCounters() {
-				commitCount = 0;
-				rollbackCount = 0;
-			}
-		};
-		LocalServer originalServer = getLocalServer(1000);
-		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-		Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
-		TransactionManager transactionManager = originalServer.getTransactionManager();
-		transactionManager.setTransactionTimeout(rootTimeout);
-		transactionManager.begin();
-		Transaction originalTransaction = transactionManager.getTransaction();
-		Xid toMigrate = originalServer.getCurrentXid();
-		originalServer.storeRootTransaction();
-		originalTransaction.enlistResource(new TestResource(counter, originalServer.getNodeName(), false));
-		transactionManager.suspend();
-
-		// Migrate a transaction
-		LocalServer currentServer = getLocalServer(2000);
-		ClassLoader parentsClassLoader = Thread.currentThread().getContextClassLoader();
-		Thread.currentThread().setContextClassLoader(currentServer.getClass().getClassLoader());
-		currentServer.getAndResumeTransaction(subordinateTimeout, toMigrate);
-		currentServer.getTransactionManager().getTransaction().enlistResource(new TestResource(counter, 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, originalServer.getNodeName(), 2000);
-		originalTransaction.enlistResource(proxyXAResource);
-		originalServer.removeRootTransaction(toMigrate);
-		Thread.currentThread().sleep((subordinateTimeout + 1) * 1000);
-		try {
-			transactionManager.commit();
-		} catch (RollbackException rbe) {
-			// GOOD!
-			assertTrue(counter.getRollbackCount() == 2);
-		} finally {
-			Thread.currentThread().setContextClassLoader(classLoader);
-		}
-	}
-
-	private void doRecursiveTransactionalWork(int startingTimeout, List<Integer> nodesToFlowTo, boolean commit) throws NotSupportedException, SystemException,
-			RollbackException, InvalidTransactionException, IllegalStateException, XAException, SecurityException, HeuristicMixedException,
-			HeuristicRollbackException {
-
-		// Start out at the first server
-		CompletionCounter counter = new CompletionCounter() {
-			private int commitCount = 0;
-			private int rollbackCount = 0;
-
-			@Override
-			public void incrementCommit() {
-				commitCount++;
-
-			}
-
-			@Override
-			public void incrementRollback() {
-				rollbackCount++;
-			}
-
-			@Override
-			public int getCommitCount() {
-				return commitCount;
-			}
-
-			@Override
-			public int getRollbackCount() {
-				return rollbackCount;
-			}
-
-			@Override
-			public void resetCounters() {
-				commitCount = 0;
-				rollbackCount = 0;
-			}
-		};
-		int totalNodeCount = nodesToFlowTo.size();
-		int startingServer = nodesToFlowTo.get(0);
-		LocalServer originalServer = getLocalServer(startingServer);
-		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();
-		transactionManager.suspend();
-		performTransactionalWork(counter, nodesToFlowTo, remainingTimeout, currentXid);
-		transactionManager.resume(originalTransaction);
-		originalServer.removeRootTransaction(currentXid);
-		if (commit) {
-			transactionManager.commit();
-			assertTrue(counter.getCommitCount() == totalNodeCount);
-		} else {
-			transactionManager.rollback();
-			assertTrue(counter.getRollbackCount() == totalNodeCount);
-		}
-		Thread.currentThread().setContextClassLoader(classLoader);
-	}
-
-	private boolean performTransactionalWork(CompletionCounter counter, List<Integer> nodesToFlowTo, int remainingTimeout, Xid toMigrate)
-			throws RollbackException, InvalidTransactionException, IllegalStateException, XAException, SystemException, NotSupportedException {
-		Integer 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);
-		// Perform work on the migrated transaction
-		TransactionManager transactionManager = currentServer.getTransactionManager();
-		Transaction transaction = transactionManager.getTransaction();
-		transaction.registerSynchronization(new TestSynchronization(currentServer.getNodeName()));
-		transaction.enlistResource(new TestResource(counter, currentServer.getNodeName(), false));
-
-		if (!nodesToFlowTo.isEmpty()) {
-			Integer nextServerNodeName = nodesToFlowTo.get(0);
-
-			// FLOW THE TRANSACTION
-			remainingTimeout = (int) (currentServer.getTimeLeftBeforeTransactionTimeout() / 1000);
-
-			// SUSPEND THE TRANSACTION
-			Xid currentXid = currentServer.getCurrentXid();
-			transactionManager.suspend();
-			boolean proxyRequired = performTransactionalWork(counter, nodesToFlowTo, remainingTimeout, currentXid);
-			transactionManager.resume(transaction);
-
-			// Create a proxy for the new server if necessary, this can orphan
-			// the remote server but XA recovery will handle that on the remote
-			// server
-			// The alternative is to always create a proxy but this is a
-			// performance drain and will result in multiple subordinate
-			// transactions and performance issues
-			if (proxyRequired) {
-				XAResource proxyXAResource = currentServer.generateProxyXAResource(lookupProvider, currentServer.getNodeName(), nextServerNodeName);
-				transaction.enlistResource(proxyXAResource);
-				transaction.registerSynchronization(currentServer.generateProxySynchronization(lookupProvider, currentServer.getNodeName(), nextServerNodeName,
-						toMigrate));
-			}
-		}
-
-		// SUSPEND THE TRANSACTION WHEN YOU ARE READY TO RETURN TO YOUR CALLER
-		transactionManager.suspend();
-
-		Thread.currentThread().setContextClassLoader(classLoader);
-		return requiresProxyAtPreviousServer;
-	}
-
-	private static LocalServer getLocalServer(Integer jndiName) {
-		int index = (jndiName / 1000) - 1;
-		return localServers[index];
-	}
-
-	private static class MyLookupProvider implements LookupProvider {
-
-		@Override
-		public RemoteServer lookup(Integer jndiName) {
-			int index = (jndiName / 1000) - 1;
-			return remoteServers[index];
-		}
-
-	}
-}

Deleted: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResource.java	2011-10-19 08:35:16 UTC (rev 37598)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResource.java	2011-10-19 08:37:36 UTC (rev 37599)
@@ -1,202 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors 
- * as indicated by the @author tags. 
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors. 
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A 
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
- * MA  02110-1301, USA.
- * 
- * (C) 2005-2006,
- * @author JBoss Inc.
- */
-
-package com.arjuna.ats.jta.distributed;
-
-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.util.Arrays;
-
-import javax.transaction.xa.XAException;
-import javax.transaction.xa.XAResource;
-import javax.transaction.xa.Xid;
-
-import com.arjuna.ats.arjuna.common.Uid;
-import com.arjuna.ats.jta.distributed.server.CompletionCounter;
-
-public class TestResource implements XAResource {
-	private Xid xid;
-
-	protected int timeout = 0;
-
-	private boolean readonly = false;
-
-	private File file;
-
-	private int serverId;
-
-	private CompletionCounter completionCounter;
-
-	public TestResource(CompletionCounter completionCounter, int serverId, boolean readonly) {
-		this.completionCounter = completionCounter;
-		this.serverId = serverId;
-		this.readonly = readonly;
-	}
-
-	public TestResource(CompletionCounter completionCounter, int serverId, File file) throws IOException {
-		this.completionCounter = completionCounter;
-		this.serverId = serverId;
-		this.file = file;
-		DataInputStream fis = new DataInputStream(new FileInputStream(file));
-		final int formatId = fis.readInt();
-		final int gtrid_length = fis.readInt();
-		final byte[] gtrid = new byte[gtrid_length];
-		fis.read(gtrid, 0, gtrid_length);
-		final int bqual_length = fis.readInt();
-		final byte[] bqual = new byte[bqual_length];
-		fis.read(bqual, 0, bqual_length);
-		this.xid = new Xid() {
-
-			@Override
-			public byte[] getGlobalTransactionId() {
-				return gtrid;
-			}
-
-			@Override
-			public int getFormatId() {
-				return formatId;
-			}
-
-			@Override
-			public byte[] getBranchQualifier() {
-				return bqual;
-			}
-		};
-	}
-
-	public synchronized int prepare(Xid xid) throws XAException {
-		System.out.println("        TestResource (" + serverId + ")      XA_PREPARE [" + xid + "]");
-
-		if (readonly)
-			return XA_RDONLY;
-		else {
-			File dir = new File(System.getProperty("user.dir") + "/tmp/TestResource/" + serverId + "/");
-			dir.mkdirs();
-			file = new File(dir, new Uid().fileStringForm() + "_");
-			try {
-				file.createNewFile();
-				final int formatId = xid.getFormatId();
-				final byte[] gtrid = xid.getGlobalTransactionId();
-				final int gtrid_length = gtrid.length;
-				final byte[] bqual = xid.getBranchQualifier();
-				final int bqual_length = bqual.length;
-
-				DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
-				fos.writeInt(formatId);
-				fos.writeInt(gtrid_length);
-				fos.write(gtrid, 0, gtrid_length);
-				fos.writeInt(bqual_length);
-				fos.write(bqual, 0, bqual_length);
-			} catch (IOException e) {
-				e.printStackTrace();
-				throw new XAException(XAException.XAER_RMERR);
-			}
-			return XA_OK;
-		}
-
-		// throw new XAException();
-	}
-
-	public synchronized void commit(Xid id, boolean onePhase) throws XAException {
-		System.out.println("        TestResource (" + serverId + ")      XA_COMMIT  [" + id + "]");
-		if (completionCounter != null) {
-			completionCounter.incrementCommit();
-		}
-		// String absoluteFile = file.getAbsolutePath();
-		// String newName = absoluteFile.substring(0, absoluteFile.length() -
-		// 1);
-		// File file2 = new File(newName);
-		// file.renameTo(file2);
-		if (file != null) {
-			file.delete();
-		}
-		this.xid = null;
-	}
-
-	public synchronized void rollback(Xid xid) throws XAException {
-		System.out.println("        TestResource (" + serverId + ")      XA_ROLLBACK[" + xid + "]");
-		if (completionCounter != null) {
-			completionCounter.incrementRollback();
-		}
-		if (file != null) {
-			file.delete();
-		}
-		this.xid = null;
-	}
-
-	public void end(Xid xid, int flags) throws XAException {
-		System.out.println("        TestResource (" + serverId + ")      XA_END     [" + xid + "] Flags=" + flags);
-	}
-
-	public void forget(Xid xid) throws XAException {
-		System.out.println("        TestResource (" + serverId + ")      XA_FORGET[" + xid + "]");
-	}
-
-	public int getTransactionTimeout() throws XAException {
-		return (timeout);
-	}
-
-	public boolean isSameRM(XAResource xares) throws XAException {
-		if (xares instanceof TestResource) {
-			TestResource other = (TestResource) xares;
-			if ((this.xid != null && other.xid != null)) {
-				if (this.xid.getFormatId() == other.xid.getFormatId()) {
-					if (Arrays.equals(this.xid.getGlobalTransactionId(), other.xid.getGlobalTransactionId())) {
-						if (Arrays.equals(this.xid.getBranchQualifier(), other.xid.getBranchQualifier())) {
-							return true;
-						}
-					}
-				}
-			}
-		}
-		return false;
-	}
-
-	public Xid[] recover(int flag) throws XAException {
-		Xid[] toReturn = null;
-		if ((flag & XAResource.TMSTARTRSCAN) == XAResource.TMSTARTRSCAN) {
-			System.out.println("        TestResource (" + serverId + ")      RECOVER[XAResource.TMSTARTRSCAN]: " + serverId);
-			if (xid != null) {
-				toReturn = new Xid[] { xid };
-			}
-		}
-		if ((flag & XAResource.TMENDRSCAN) == XAResource.TMENDRSCAN) {
-			System.out.println("        TestResource (" + serverId + ")      RECOVER[XAResource.TMENDRSCAN]: " + serverId);
-		}
-		if (flag == XAResource.TMNOFLAGS) {
-			System.out.println("        TestResource (" + serverId + ")      RECOVER[XAResource.TMENDRSCAN]: " + serverId);
-		}
-		return toReturn;
-	}
-
-	public boolean setTransactionTimeout(int seconds) throws XAException {
-		timeout = seconds;
-		return (true);
-	}
-
-	public void start(Xid xid, int flags) throws XAException {
-		System.out.println("        TestResource (" + serverId + ")      XA_START   [" + xid + "] Flags=" + flags);
-	}
-}

Deleted: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java	2011-10-19 08:35:16 UTC (rev 37598)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java	2011-10-19 08:37:36 UTC (rev 37599)
@@ -1,57 +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;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.transaction.xa.XAResource;
-
-import org.jboss.tm.XAResourceRecovery;
-
-import com.arjuna.ats.jta.distributed.server.CompletionCounter;
-
-public class TestResourceRecovery implements XAResourceRecovery {
-
-	private List<TestResource> resources = new ArrayList<TestResource>();
-
-	public TestResourceRecovery(CompletionCounter counter, Integer nodeName) throws IOException {
-		File file = new File(System.getProperty("user.dir") + "/tmp/TestResource/" + nodeName + "/");
-		if (file.exists() && file.isDirectory()) {
-			File[] listFiles = file.listFiles();
-			for (int i = 0; i < listFiles.length; i++) {
-				File currentFile = listFiles[i];
-				if (currentFile.getAbsolutePath().endsWith("_")) {
-					resources.add(new TestResource(counter, nodeName, currentFile));
-				}
-			}
-		}
-	}
-
-	@Override
-	public XAResource[] getXAResources() {
-		return resources.toArray(new XAResource[] {});
-	}
-
-}

Deleted: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestSynchronization.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestSynchronization.java	2011-10-19 08:35:16 UTC (rev 37598)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestSynchronization.java	2011-10-19 08:37:36 UTC (rev 37599)
@@ -1,42 +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;
-
-import javax.transaction.Synchronization;
-
-public class TestSynchronization implements Synchronization {
-	private int serverId;
-
-	public TestSynchronization(int serverId) {
-		this.serverId = serverId;
-	}
-
-	@Override
-	public void beforeCompletion() {
-		System.out.println(" TestSynchronization (" + serverId + ")      beforeCompletion");
-	}
-
-	@Override
-	public void afterCompletion(int status) {
-		System.out.println(" TestSynchronization (" + serverId + ")      afterCompletion");
-	}
-}

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java	2011-10-19 08:35:16 UTC (rev 37598)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java	2011-10-19 08:37:36 UTC (rev 37599)
@@ -58,12 +58,12 @@
 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.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.jta.distributed.example.TestResourceRecovery;
 
 public class ServerImpl implements LocalServer, RemoteServer {
 

Copied: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/SimpleIsolatedServers.java (from rev 37596, labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java)
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/SimpleIsolatedServers.java	                        (rev 0)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/SimpleIsolatedServers.java	2011-10-19 08:37:36 UTC (rev 37599)
@@ -0,0 +1,344 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.common.CoreEnvironmentBeanException;
+import com.arjuna.ats.jta.distributed.server.CompletionCounter;
+import com.arjuna.ats.jta.distributed.server.IsolatableServersClassLoader;
+import com.arjuna.ats.jta.distributed.server.LocalServer;
+import com.arjuna.ats.jta.distributed.server.LookupProvider;
+import com.arjuna.ats.jta.distributed.server.RemoteServer;
+
+public class SimpleIsolatedServers {
+	private static LookupProvider lookupProvider = new MyLookupProvider();
+	private static LocalServer[] localServers = new LocalServer[3];
+	private static RemoteServer[] remoteServers = new RemoteServer[3];
+
+	@BeforeClass
+	public static void setup() throws SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, ClassNotFoundException,
+			CoreEnvironmentBeanException, IOException, IllegalArgumentException, NoSuchFieldException {
+		for (int i = 0; i < localServers.length; i++) {
+			ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+			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);
+			remoteServers[i] = localServers[i].connectTo();
+			Thread.currentThread().setContextClassLoader(contextClassLoader);
+		}
+	}
+
+	@Test
+	public void testRecovery() throws IOException {
+		assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 0);
+		assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
+		assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
+		// Start out at the first server
+		// getLocalServer(3000).doRecoveryManagerScan();
+		// getLocalServer(2000).doRecoveryManagerScan();
+		getLocalServer(1000).doRecoveryManagerScan();
+
+		assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 3);
+		assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 3);
+		assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 3);
+	}
+
+	@Test
+	public void testMigrateTransactionCommit() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
+			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
+
+		File file = new File(System.getProperty("user.dir") + "/tmp/");
+		if (file.exists()) {
+			file.delete();
+		}
+		int startingTimeout = 0;
+		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
+		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true);
+	}
+
+	@Test
+	public void testMigrateTransactionCommitDiamond() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
+			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
+
+		File file = new File(System.getProperty("user.dir") + "/tmp/");
+		if (file.exists()) {
+			file.delete();
+		}
+		int startingTimeout = 0;
+		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 1000, 3000, 1000, 2000, 3000 }));
+		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true);
+	}
+
+	@Test
+	public void testMigrateTransactionRollback() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
+			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
+
+		File file = new File(System.getProperty("user.dir") + "/tmp/");
+		if (file.exists()) {
+			file.delete();
+		}
+		int startingTimeout = 0;
+		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
+		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, false);
+	}
+
+	@Test
+	public void testMigrateTransactionRollbackDiamond() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
+			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
+
+		File file = new File(System.getProperty("user.dir") + "/tmp/");
+		if (file.exists()) {
+			file.delete();
+		}
+		int startingTimeout = 0;
+		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 1000, 3000, 1000, 2000, 3000 }));
+		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, false);
+	}
+
+	@Test
+	public void testMigrateTransactionSubordinateTimeout() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
+			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException, InterruptedException {
+
+		File file = new File(System.getProperty("user.dir") + "/tmp/");
+		if (file.exists()) {
+			file.delete();
+		}
+		int rootTimeout = 10000;
+		int subordinateTimeout = 1;
+
+		// Start out at the first server
+		CompletionCounter counter = new CompletionCounter() {
+			private int commitCount = 0;
+			private int rollbackCount = 0;
+
+			@Override
+			public void incrementCommit() {
+				commitCount++;
+
+			}
+
+			@Override
+			public void incrementRollback() {
+				rollbackCount++;
+			}
+
+			@Override
+			public int getCommitCount() {
+				return commitCount;
+			}
+
+			@Override
+			public int getRollbackCount() {
+				return rollbackCount;
+			}
+
+			@Override
+			public void resetCounters() {
+				commitCount = 0;
+				rollbackCount = 0;
+			}
+		};
+		LocalServer originalServer = getLocalServer(1000);
+		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+		Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
+		TransactionManager transactionManager = originalServer.getTransactionManager();
+		transactionManager.setTransactionTimeout(rootTimeout);
+		transactionManager.begin();
+		Transaction originalTransaction = transactionManager.getTransaction();
+		Xid toMigrate = originalServer.getCurrentXid();
+		originalServer.storeRootTransaction();
+		originalTransaction.enlistResource(new TestResource(counter, originalServer.getNodeName(), false));
+		transactionManager.suspend();
+
+		// Migrate a transaction
+		LocalServer currentServer = getLocalServer(2000);
+		ClassLoader parentsClassLoader = Thread.currentThread().getContextClassLoader();
+		Thread.currentThread().setContextClassLoader(currentServer.getClass().getClassLoader());
+		currentServer.getAndResumeTransaction(subordinateTimeout, toMigrate);
+		currentServer.getTransactionManager().getTransaction().enlistResource(new TestResource(counter, 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, originalServer.getNodeName(), 2000);
+		originalTransaction.enlistResource(proxyXAResource);
+		originalServer.removeRootTransaction(toMigrate);
+		Thread.currentThread().sleep((subordinateTimeout + 1) * 1000);
+		try {
+			transactionManager.commit();
+		} catch (RollbackException rbe) {
+			// GOOD!
+			assertTrue(counter.getRollbackCount() == 2);
+		} finally {
+			Thread.currentThread().setContextClassLoader(classLoader);
+		}
+	}
+
+	private void doRecursiveTransactionalWork(int startingTimeout, List<Integer> nodesToFlowTo, boolean commit) throws NotSupportedException, SystemException,
+			RollbackException, InvalidTransactionException, IllegalStateException, XAException, SecurityException, HeuristicMixedException,
+			HeuristicRollbackException {
+
+		// Start out at the first server
+		CompletionCounter counter = new CompletionCounter() {
+			private int commitCount = 0;
+			private int rollbackCount = 0;
+
+			@Override
+			public void incrementCommit() {
+				commitCount++;
+
+			}
+
+			@Override
+			public void incrementRollback() {
+				rollbackCount++;
+			}
+
+			@Override
+			public int getCommitCount() {
+				return commitCount;
+			}
+
+			@Override
+			public int getRollbackCount() {
+				return rollbackCount;
+			}
+
+			@Override
+			public void resetCounters() {
+				commitCount = 0;
+				rollbackCount = 0;
+			}
+		};
+		int totalNodeCount = nodesToFlowTo.size();
+		int startingServer = nodesToFlowTo.get(0);
+		LocalServer originalServer = getLocalServer(startingServer);
+		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();
+		transactionManager.suspend();
+		performTransactionalWork(counter, nodesToFlowTo, remainingTimeout, currentXid);
+		transactionManager.resume(originalTransaction);
+		originalServer.removeRootTransaction(currentXid);
+		if (commit) {
+			transactionManager.commit();
+			assertTrue(counter.getCommitCount() == totalNodeCount);
+		} else {
+			transactionManager.rollback();
+			assertTrue(counter.getRollbackCount() == totalNodeCount);
+		}
+		Thread.currentThread().setContextClassLoader(classLoader);
+	}
+
+	private boolean performTransactionalWork(CompletionCounter counter, List<Integer> nodesToFlowTo, int remainingTimeout, Xid toMigrate)
+			throws RollbackException, InvalidTransactionException, IllegalStateException, XAException, SystemException, NotSupportedException {
+		Integer 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);
+		// Perform work on the migrated transaction
+		TransactionManager transactionManager = currentServer.getTransactionManager();
+		Transaction transaction = transactionManager.getTransaction();
+		transaction.registerSynchronization(new TestSynchronization(currentServer.getNodeName()));
+		transaction.enlistResource(new TestResource(counter, currentServer.getNodeName(), false));
+
+		if (!nodesToFlowTo.isEmpty()) {
+			Integer nextServerNodeName = nodesToFlowTo.get(0);
+
+			// FLOW THE TRANSACTION
+			remainingTimeout = (int) (currentServer.getTimeLeftBeforeTransactionTimeout() / 1000);
+
+			// SUSPEND THE TRANSACTION
+			Xid currentXid = currentServer.getCurrentXid();
+			transactionManager.suspend();
+			boolean proxyRequired = performTransactionalWork(counter, nodesToFlowTo, remainingTimeout, currentXid);
+			transactionManager.resume(transaction);
+
+			// Create a proxy for the new server if necessary, this can orphan
+			// the remote server but XA recovery will handle that on the remote
+			// server
+			// The alternative is to always create a proxy but this is a
+			// performance drain and will result in multiple subordinate
+			// transactions and performance issues
+			if (proxyRequired) {
+				XAResource proxyXAResource = currentServer.generateProxyXAResource(lookupProvider, currentServer.getNodeName(), nextServerNodeName);
+				transaction.enlistResource(proxyXAResource);
+				transaction.registerSynchronization(currentServer.generateProxySynchronization(lookupProvider, currentServer.getNodeName(), nextServerNodeName,
+						toMigrate));
+			}
+		}
+
+		// SUSPEND THE TRANSACTION WHEN YOU ARE READY TO RETURN TO YOUR CALLER
+		transactionManager.suspend();
+
+		Thread.currentThread().setContextClassLoader(classLoader);
+		return requiresProxyAtPreviousServer;
+	}
+
+	private static LocalServer getLocalServer(Integer jndiName) {
+		int index = (jndiName / 1000) - 1;
+		return localServers[index];
+	}
+
+	private static class MyLookupProvider implements LookupProvider {
+
+		@Override
+		public RemoteServer lookup(Integer jndiName) {
+			int index = (jndiName / 1000) - 1;
+			return remoteServers[index];
+		}
+
+	}
+}

Copied: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java (from rev 37596, labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResource.java)
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java	                        (rev 0)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java	2011-10-19 08:37:36 UTC (rev 37599)
@@ -0,0 +1,202 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors 
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+
+package com.arjuna.jta.distributed.example;
+
+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.util.Arrays;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.jta.distributed.server.CompletionCounter;
+
+public class TestResource implements XAResource {
+	private Xid xid;
+
+	protected int timeout = 0;
+
+	private boolean readonly = false;
+
+	private File file;
+
+	private int serverId;
+
+	private CompletionCounter completionCounter;
+
+	public TestResource(CompletionCounter completionCounter, int serverId, boolean readonly) {
+		this.completionCounter = completionCounter;
+		this.serverId = serverId;
+		this.readonly = readonly;
+	}
+
+	public TestResource(CompletionCounter completionCounter, int serverId, File file) throws IOException {
+		this.completionCounter = completionCounter;
+		this.serverId = serverId;
+		this.file = file;
+		DataInputStream fis = new DataInputStream(new FileInputStream(file));
+		final int formatId = fis.readInt();
+		final int gtrid_length = fis.readInt();
+		final byte[] gtrid = new byte[gtrid_length];
+		fis.read(gtrid, 0, gtrid_length);
+		final int bqual_length = fis.readInt();
+		final byte[] bqual = new byte[bqual_length];
+		fis.read(bqual, 0, bqual_length);
+		this.xid = new Xid() {
+
+			@Override
+			public byte[] getGlobalTransactionId() {
+				return gtrid;
+			}
+
+			@Override
+			public int getFormatId() {
+				return formatId;
+			}
+
+			@Override
+			public byte[] getBranchQualifier() {
+				return bqual;
+			}
+		};
+	}
+
+	public synchronized int prepare(Xid xid) throws XAException {
+		System.out.println("        TestResource (" + serverId + ")      XA_PREPARE [" + xid + "]");
+
+		if (readonly)
+			return XA_RDONLY;
+		else {
+			File dir = new File(System.getProperty("user.dir") + "/tmp/TestResource/" + serverId + "/");
+			dir.mkdirs();
+			file = new File(dir, new Uid().fileStringForm() + "_");
+			try {
+				file.createNewFile();
+				final int formatId = xid.getFormatId();
+				final byte[] gtrid = xid.getGlobalTransactionId();
+				final int gtrid_length = gtrid.length;
+				final byte[] bqual = xid.getBranchQualifier();
+				final int bqual_length = bqual.length;
+
+				DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
+				fos.writeInt(formatId);
+				fos.writeInt(gtrid_length);
+				fos.write(gtrid, 0, gtrid_length);
+				fos.writeInt(bqual_length);
+				fos.write(bqual, 0, bqual_length);
+			} catch (IOException e) {
+				e.printStackTrace();
+				throw new XAException(XAException.XAER_RMERR);
+			}
+			return XA_OK;
+		}
+
+		// throw new XAException();
+	}
+
+	public synchronized void commit(Xid id, boolean onePhase) throws XAException {
+		System.out.println("        TestResource (" + serverId + ")      XA_COMMIT  [" + id + "]");
+		if (completionCounter != null) {
+			completionCounter.incrementCommit();
+		}
+		// String absoluteFile = file.getAbsolutePath();
+		// String newName = absoluteFile.substring(0, absoluteFile.length() -
+		// 1);
+		// File file2 = new File(newName);
+		// file.renameTo(file2);
+		if (file != null) {
+			file.delete();
+		}
+		this.xid = null;
+	}
+
+	public synchronized void rollback(Xid xid) throws XAException {
+		System.out.println("        TestResource (" + serverId + ")      XA_ROLLBACK[" + xid + "]");
+		if (completionCounter != null) {
+			completionCounter.incrementRollback();
+		}
+		if (file != null) {
+			file.delete();
+		}
+		this.xid = null;
+	}
+
+	public void end(Xid xid, int flags) throws XAException {
+		System.out.println("        TestResource (" + serverId + ")      XA_END     [" + xid + "] Flags=" + flags);
+	}
+
+	public void forget(Xid xid) throws XAException {
+		System.out.println("        TestResource (" + serverId + ")      XA_FORGET[" + xid + "]");
+	}
+
+	public int getTransactionTimeout() throws XAException {
+		return (timeout);
+	}
+
+	public boolean isSameRM(XAResource xares) throws XAException {
+		if (xares instanceof TestResource) {
+			TestResource other = (TestResource) xares;
+			if ((this.xid != null && other.xid != null)) {
+				if (this.xid.getFormatId() == other.xid.getFormatId()) {
+					if (Arrays.equals(this.xid.getGlobalTransactionId(), other.xid.getGlobalTransactionId())) {
+						if (Arrays.equals(this.xid.getBranchQualifier(), other.xid.getBranchQualifier())) {
+							return true;
+						}
+					}
+				}
+			}
+		}
+		return false;
+	}
+
+	public Xid[] recover(int flag) throws XAException {
+		Xid[] toReturn = null;
+		if ((flag & XAResource.TMSTARTRSCAN) == XAResource.TMSTARTRSCAN) {
+			System.out.println("        TestResource (" + serverId + ")      RECOVER[XAResource.TMSTARTRSCAN]: " + serverId);
+			if (xid != null) {
+				toReturn = new Xid[] { xid };
+			}
+		}
+		if ((flag & XAResource.TMENDRSCAN) == XAResource.TMENDRSCAN) {
+			System.out.println("        TestResource (" + serverId + ")      RECOVER[XAResource.TMENDRSCAN]: " + serverId);
+		}
+		if (flag == XAResource.TMNOFLAGS) {
+			System.out.println("        TestResource (" + serverId + ")      RECOVER[XAResource.TMENDRSCAN]: " + serverId);
+		}
+		return toReturn;
+	}
+
+	public boolean setTransactionTimeout(int seconds) throws XAException {
+		timeout = seconds;
+		return (true);
+	}
+
+	public void start(Xid xid, int flags) throws XAException {
+		System.out.println("        TestResource (" + serverId + ")      XA_START   [" + xid + "] Flags=" + flags);
+	}
+}

Copied: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResourceRecovery.java (from rev 37596, labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java)
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResourceRecovery.java	                        (rev 0)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResourceRecovery.java	2011-10-19 08:37:36 UTC (rev 37599)
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.transaction.xa.XAResource;
+
+import org.jboss.tm.XAResourceRecovery;
+
+import com.arjuna.ats.jta.distributed.server.CompletionCounter;
+
+public class TestResourceRecovery implements XAResourceRecovery {
+
+	private List<TestResource> resources = new ArrayList<TestResource>();
+
+	public TestResourceRecovery(CompletionCounter counter, Integer nodeName) throws IOException {
+		File file = new File(System.getProperty("user.dir") + "/tmp/TestResource/" + nodeName + "/");
+		if (file.exists() && file.isDirectory()) {
+			File[] listFiles = file.listFiles();
+			for (int i = 0; i < listFiles.length; i++) {
+				File currentFile = listFiles[i];
+				if (currentFile.getAbsolutePath().endsWith("_")) {
+					resources.add(new TestResource(counter, nodeName, currentFile));
+				}
+			}
+		}
+	}
+
+	@Override
+	public XAResource[] getXAResources() {
+		return resources.toArray(new XAResource[] {});
+	}
+
+}

Copied: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestSynchronization.java (from rev 37596, labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/ats/jta/distributed/TestSynchronization.java)
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestSynchronization.java	                        (rev 0)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestSynchronization.java	2011-10-19 08:37:36 UTC (rev 37599)
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import javax.transaction.Synchronization;
+
+public class TestSynchronization implements Synchronization {
+	private int serverId;
+
+	public TestSynchronization(int serverId) {
+		this.serverId = serverId;
+	}
+
+	@Override
+	public void beforeCompletion() {
+		System.out.println(" TestSynchronization (" + serverId + ")      beforeCompletion");
+	}
+
+	@Override
+	public void afterCompletion(int status) {
+		System.out.println(" TestSynchronization (" + serverId + ")      afterCompletion");
+	}
+}



More information about the jboss-svn-commits mailing list