[jboss-svn-commits] JBL Code SVN: r37750 - 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
Wed Nov 30 16:17:02 EST 2011


Author: tomjenkinson
Date: 2011-11-30 16:17:01 -0500 (Wed, 30 Nov 2011)
New Revision: 37750

Removed:
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounterImpl.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProviderImpl.java
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/TestResource.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/IsolatableServersClassLoader.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/ServerImpl.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResource.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounter.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/IsolatableServersClassLoader.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProvider.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java
Log:
JBTM-895 updated the example to reflect the fact that we do not want to require the transport to persist additional data

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/ExampleDistributedJTATestCase.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -35,7 +35,6 @@
 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.jboss.tm.TransactionTimeoutConfiguration;
@@ -46,7 +45,6 @@
 import com.arjuna.jta.distributed.example.server.IsolatableServersClassLoader;
 import com.arjuna.jta.distributed.example.server.LocalServer;
 import com.arjuna.jta.distributed.example.server.LookupProvider;
-import com.arjuna.jta.distributed.example.server.RemoteServer;
 
 /**
  * This example shows how to use the JTA in a distributed manner.
@@ -78,19 +76,30 @@
 	/**
 	 * This is to simulate JNDI.
 	 */
-	private static LookupProvider lookupProvider = new MyLookupProvider();
+	private static LookupProvider lookupProvider = LookupProvider.getInstance();
 
 	/**
-	 * The example stores a reference to all local servers as a convenience
+	 * The list of server node names
 	 */
-	private static LocalServer[] localServers = new LocalServer[3];
+	private static String[] serverNodeNames = new String[] { "1000", "2000", "3000" };
 
 	/**
-	 * The example stores a reference to all remote servers as a convenience
+	 * A list of port offsets to use for the servers
 	 */
-	private static RemoteServer[] remoteServers = new RemoteServer[3];
+	private static int[] serverPortOffsets = new int[] { 1000, 2000, 3000 };
 
 	/**
+	 * For each of the server nodes, a list of the other servers in the cluster
+	 */
+	private static String[][] clusterBuddies = new String[][] { new String[] { "2000", "3000" }, new String[] { "1000", "3000" },
+			new String[] { "1000", "2000" } };
+
+	/**
+	 * The example stores a reference to all local servers as a convenience
+	 */
+	private static LocalServer[] localServers = new LocalServer[serverNodeNames.length];
+
+	/**
 	 * Initialise references to the local and remote servers.
 	 * 
 	 * @throws SecurityException
@@ -115,11 +124,11 @@
 			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, String.valueOf((i + 1) * 1000), (i + 1) * 1000);
+			localServers[i].initialise(lookupProvider, serverNodeNames[i], serverPortOffsets[i], clusterBuddies[i]);
 			// This is a short cut, normally remote servers would not be the
 			// same as the local servers and would be a tranport layer
 			// abstraction
-			remoteServers[i] = localServers[i].connectTo();
+			lookupProvider.bind(i, localServers[i].connectTo());
 			Thread.currentThread().setContextClassLoader(contextClassLoader);
 		}
 	}
@@ -195,7 +204,7 @@
 				// subordinate naughtily comes back to this server part way
 				// through
 				// so we can return the original transaction to them
-				originalServer.storeRootTransaction(transaction);
+				originalServer.storeRootTransaction();
 
 				// Peek at the next node - this is just a test abstraction to
 				// simulate where business logic might decide to access an EJB
@@ -208,12 +217,6 @@
 				int remainingTimeout = (int) (((TransactionTimeoutConfiguration) transactionManager).getTimeLeftBeforeTransactionTimeout(false) / 1000);
 				// Get the Xid to propagate
 				Xid currentXid = originalServer.getCurrentXid();
-				// Generate a ProxyXAresource, this is transport specific but it
-				// should at least have stored the currentXid in a temporary
-				// location or the name of the remote server so that we can
-				// recover
-				// orphan subordinate transactions
-				XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, nextServerNodeName);
 				// Suspend the transaction locally
 				transactionManager.suspend();
 
@@ -226,7 +229,8 @@
 				// that
 				// it can propagate the transaction completion events to the
 				// subordinate
-				transaction.enlistResource(proxyXAResource);
+				transaction.enlistResource(originalServer.generateProxyXAResource(lookupProvider, nextServerNodeName,
+						dataReturnedFromRemoteServer.getRemoteXidCreated()));
 				// Register a synchronization that can proxy the
 				// beforeCompletion
 				// event to the remote side, after completion events are the
@@ -282,8 +286,8 @@
 	 * @throws NotSupportedException
 	 * @throws IOException
 	 */
-	private DataReturnedFromRemoteServer propagateTransaction(List<String> nodesToFlowTo, int remainingTimeout, Xid toMigrate) throws RollbackException, IllegalStateException, XAException, SystemException, NotSupportedException,
-			IOException {
+	private DataReturnedFromRemoteServer propagateTransaction(List<String> nodesToFlowTo, int remainingTimeout, Xid toMigrate) throws RollbackException,
+			IllegalStateException, XAException, SystemException, NotSupportedException, IOException {
 		// Do some test setup to initialize this method as it if was being
 		// invoked in a remote server
 		String currentServerName = nodesToFlowTo.remove(0);
@@ -298,7 +302,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.
-		boolean requiresProxyAtPreviousServer = !currentServer.getAndResumeTransaction(remainingTimeout, toMigrate);
+		Xid requiresProxyAtPreviousServer = currentServer.getAndResumeTransaction(remainingTimeout, toMigrate);
 
 		{
 			// Perform work on the migrated transaction
@@ -329,14 +333,6 @@
 				remainingTimeout = (int) (((TransactionTimeoutConfiguration) transactionManager).getTimeLeftBeforeTransactionTimeout(false) / 1000);
 				// Get the XID to propagate
 				Xid currentXid = currentServer.getCurrentXid();
-				// Generate the proxy (which saves a temporary copy of the XID
-				// in
-				// case the remote server was to be orphaned, this could just
-				// save a
-				// proxy that knows to contact the remote server but then it
-				// will
-				// force rollbacks on recovery - not ideal)
-				XAResource proxyXAResource = currentServer.generateProxyXAResource(lookupProvider, nextServerNodeName);
 				// Suspend the transaction ready for propagation
 				transactionManager.suspend();
 				// Propagate the transaction - in the example I return a boolean
@@ -352,16 +348,12 @@
 				// If this caller was the first entity to propagate the
 				// transaction
 				// to the remote server
-				if (dataReturnedFromRemoteServer.isProxyRequired()) {
+				if (dataReturnedFromRemoteServer.getRemoteXidCreated() != null) {
 					// Formally enlist the resource
-					transaction.enlistResource(proxyXAResource);
+					transaction.enlistResource(currentServer.generateProxyXAResource(lookupProvider, nextServerNodeName,
+							dataReturnedFromRemoteServer.getRemoteXidCreated()));
 					// Register a sync
 					transaction.registerSynchronization(currentServer.generateProxySynchronization(lookupProvider, nextServerNodeName, toMigrate));
-				} else {
-					// This will discard the state of this resource, i.e. the
-					// file
-					// containing the temporary unprepared XID
-					currentServer.cleanupProxyXAResource(proxyXAResource);
 				}
 
 				// Align the local state with the returning state of the
@@ -395,34 +387,20 @@
 	}
 
 	/**
-	 * A simple class that simulates JNDI to lookup references to remote servers
-	 * for this in memory transport.
-	 */
-	private static class MyLookupProvider implements LookupProvider {
-
-		@Override
-		public RemoteServer lookup(String jndiName) {
-			int index = (new Integer(jndiName) / 1000) - 1;
-			return remoteServers[index];
-		}
-
-	}
-
-	/**
 	 * This is the transactional data the transport needs to return from remote
 	 * instances.
 	 */
 	private class DataReturnedFromRemoteServer {
-		private boolean proxyRequired;
+		private Xid proxyRequired;
 
 		private int transactionState;
 
-		public DataReturnedFromRemoteServer(boolean proxyRequired, int transactionState) {
+		public DataReturnedFromRemoteServer(Xid proxyRequired, int transactionState) {
 			this.proxyRequired = proxyRequired;
 			this.transactionState = transactionState;
 		}
 
-		public boolean isProxyRequired() {
+		public Xid getRemoteXidCreated() {
 			return proxyRequired;
 		}
 

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java	2011-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/TestResource.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -102,24 +102,17 @@
 			fos.write(gtrid, 0, gtrid_length);
 			fos.writeInt(bqual_length);
 			fos.write(bqual, 0, bqual_length);
+			fos.flush();
+			fos.close();
 		} 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 (" + localServerName + ")      XA_COMMIT  [" + id + "]");
 		if (file != null) {
-			// String absoluteFile = file.getAbsolutePath();
-			// String newName = absoluteFile.substring(0, absoluteFile.length()
-			// -
-			// 1);
-			// File file2 = new File(newName);
-			// file.renameTo(file2);
 			file.delete();
 		}
 		this.xid = null;

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/IsolatableServersClassLoader.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/IsolatableServersClassLoader.java	2011-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/IsolatableServersClassLoader.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -56,7 +56,6 @@
 	public IsolatableServersClassLoader(String ignoredPackage, ClassLoader parent) throws SecurityException, NoSuchMethodException, MalformedURLException {
 		super(parent);
 		this.ignoredPackage = ignoredPackage;
-
 		String property = System.getProperty("java.class.path");
 		String[] split = property.split(System.getProperty("path.separator"));
 		URL[] urls = new URL[split.length];
@@ -84,24 +83,29 @@
 		if (clazzMap.containsKey(name)) {
 			clazz = clazzMap.get(name);
 		}
-		if (!name.startsWith("com.arjuna") || (ignoredPackage != null && name.matches(ignoredPackage + ".[A-Za-z0-9]*"))) {
-			clazz = super.loadClass(name);
+
+		if (clazz != null) {
+			System.err.println("Already loaded: " + name);
 		} else {
+			if (!name.startsWith("com.arjuna") || (ignoredPackage != null && name.matches(ignoredPackage + ".[A-Za-z0-9]*"))) {
+				clazz = super.loadClass(name);
+			} else {
 
-			String path = name.replace('.', '/').concat(".class");
-			Resource res = ucp.getResource(path, false);
-			if (res == null) {
-				throw new ClassNotFoundException(name);
+				String path = name.replace('.', '/').concat(".class");
+				Resource res = ucp.getResource(path, false);
+				if (res == null) {
+					throw new ClassNotFoundException(name);
+				}
+				try {
+					byte[] classData = res.getBytes();
+					clazz = defineClass(name, classData, 0, classData.length);
+					clazzMap.put(name, clazz);
+				} catch (IOException e) {
+					throw new ClassNotFoundException(name, e);
+				}
 			}
-			try {
-				byte[] classData = res.getBytes();
-				clazz = defineClass(name, classData, 0, classData.length);
-				clazzMap.put(name, clazz);
-			} catch (IOException e) {
-				throw new ClassNotFoundException(name, e);
-			}
+
 		}
-
 		return clazz;
 	}
 }
\ No newline at end of file

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LocalServer.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -27,7 +27,6 @@
 import javax.transaction.NotSupportedException;
 import javax.transaction.Synchronization;
 import javax.transaction.SystemException;
-import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
@@ -56,8 +55,8 @@
 	 * @throws IllegalArgumentException
 	 * @throws IllegalAccessException
 	 */
-	public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset) throws CoreEnvironmentBeanException, IOException, SecurityException,
-			NoSuchFieldException, IllegalArgumentException, IllegalAccessException;
+	public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset, String[] clusterCompatriots) throws CoreEnvironmentBeanException,
+			IOException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException;
 
 	/**
 	 * Get the local transaction managers node name.
@@ -84,7 +83,7 @@
 	 * 
 	 * @throws SystemException
 	 */
-	public void storeRootTransaction(Transaction transaction) throws SystemException;
+	public void storeRootTransaction() throws SystemException;
 
 	/**
 	 * Remove the parent transaction from the local cache. It is indexed on XID.
@@ -112,8 +111,8 @@
 	 * and a potential method of persisting this data). This is important when a
 	 * proxy xa resource is involved in recovery and invokes commit or rollback
 	 * as the transaction must be reloaded by the remote server before the
-	 * commit/rollback – if it was prepared - before we attempt to complete the
-	 * transaction.
+	 * commit/rollback – if it was prepared - before we attempt to complete
+	 * the transaction.
 	 * 
 	 * @param remainingTimeout
 	 * @param toImport
@@ -124,8 +123,8 @@
 	 * @throws SystemException
 	 * @throws IOException
 	 */
-	public boolean getAndResumeTransaction(int remainingTimeout, Xid toImport) throws XAException,
-			InvalidTransactionException, IllegalStateException, SystemException, IOException;
+	public Xid getAndResumeTransaction(int remainingTimeout, Xid toImport) throws XAException, InvalidTransactionException, IllegalStateException,
+			SystemException, IOException;
 
 	/**
 	 * Transport specific function to generate a proxy for a remote server.
@@ -136,17 +135,10 @@
 	 * @throws IOException
 	 * @throws SystemException
 	 */
-	public XAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName) throws IOException, SystemException;
+	public XAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName, Xid migratedTransaction) throws IOException,
+			SystemException;
 
 	/**
-	 * Discard the proxy if it turns out the remote server was already part of
-	 * the transaction
-	 * 
-	 * @param proxyXAResource
-	 */
-	public void cleanupProxyXAResource(XAResource proxyXAResource);
-
-	/**
 	 * Generate a proxy synchronization
 	 * 
 	 * @param lookupProvider

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/LookupProvider.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -1,29 +1,54 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package com.arjuna.jta.distributed.example.server;
-
-/**
- * Simulates a simple JNDI inorder to resolve remote servers.
- */
-public interface LookupProvider {
-	public RemoteServer lookup(String remotingNodeName);
-}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package com.arjuna.jta.distributed.example.server;
+
+public class LookupProvider {
+	private static LookupProvider instance;
+
+	private RemoteServer[] remoteServers = new RemoteServer[3];
+
+	public static LookupProvider getInstance() {
+		if (instance == null) {
+			instance = new LookupProvider();
+		}
+		return instance;
+	}
+
+	protected LookupProvider() {
+	}
+
+	public RemoteServer lookup(String jndiName) {
+		int index = (Integer.valueOf(jndiName) / 1000) - 1;
+		return remoteServers[index];
+	}
+
+	public void clear() {
+		for (int i = 0; i < remoteServers.length; i++) {
+			// Disconnect
+			remoteServers[i] = null;
+		}
+	}
+
+	public void bind(int index, RemoteServer connectTo) {
+		remoteServers[index] = connectTo;
+	}
+}

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/RemoteServer.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -27,74 +27,18 @@
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.Xid;
 
-/**
- * This interface is to simulate most remote calls to a server (except where
- * classloader separation is used in
- * <class>ExampelDistributedJTATestCase</class>
- * 
- * Most of the calls are fairly innocuous, however one needs special explanation.
- * 
- * Firstly the before completion takes an XID, check out
- * <class>ProxySynchronization</class> for more details on that.
- */
 public interface RemoteServer {
 
-	/**
-	 * Relay the propagate completion.
-	 * 
-	 * @param xid
-	 * @throws XAException
-	 * @throws SystemException
-	 * @throws DummyRemoteException
-	 */
-	public void beforeCompletion(Xid xid) throws XAException, SystemException;
+	public int prepare(Xid xid, boolean recover) throws XAException, IOException;
 
-	/**
-	 * Relay a prepare to the remote side for a specific Xid.
-	 * 
-	 * @param xid
-	 * @return
-	 * @throws XAException
-	 * @throws DummyRemoteException
-	 */
-	public int prepare(Xid xid) throws XAException;
-
-	/**
-	 * Relay the commit.
-	 * 
-	 * If this call is coming from a recover scan on a ProxyXAResource, then
-	 * pass the recover flag in so the remote server knows it needs to recover
-	 * the transaction.
-	 * 
-	 * @param xid
-	 * @param onePhase
-	 * @throws XAException
-	 * @throws IOException 
-	 * @throws DummyRemoteException
-	 */
 	public void commit(Xid xid, boolean onePhase, boolean recover) throws XAException, IOException;
 
-	/**
-	 * Relay the rollback.
-	 * 
-	 * If this call is coming from a recover scan on a ProxyXAResource, then
-	 * pass the recover flag in so the remote server knows it needs to recover
-	 * the transaction.
-	 * 
-	 * @param xid
-	 * @throws XAException
-	 * @throws IOException 
-	 * @throws DummyRemoteException
-	 */
 	public void rollback(Xid xid, boolean recover) throws XAException, IOException;
 
-	/**
-	 * Relay the forget.
-	 * 
-	 * @param xid
-	 * @throws XAException
-	 * @throws DummyRemoteException
-	 */
-	public void forget(Xid xid) throws XAException;
+	public void forget(Xid xid, boolean recover) throws XAException, IOException;
 
+	public void beforeCompletion(Xid xid) throws XAException, SystemException;
+
+	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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxySynchronization.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -28,11 +28,6 @@
 
 import com.arjuna.jta.distributed.example.server.LookupProvider;
 
-/**
- * Proxy the before completion call to the remote servers. Unusual for a
- * synchronization it must be created with a reference to an Xid in order to be
- * able to propate this information to a remote server.
- */
 public class ProxySynchronization implements Synchronization {
 
 	private String localServerName;

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResource.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -21,113 +21,61 @@
  */
 package com.arjuna.jta.distributed.example.server.impl;
 
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import java.io.Serializable;
 
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-import com.arjuna.ats.arjuna.common.Uid;
+import org.jboss.tm.XAResourceWrapper;
+
 import com.arjuna.jta.distributed.example.server.LookupProvider;
 
 /**
- * The XA resource that the transport must provide inorder to proxy directives
- * from the root transaction coordinator.
- * 
- * One of the key features of the pattern is the Proxy. It will adapt the XID of
- * the subordinate (which the local transaction manager does not know about) to
- * an XID that is allocated by the local transaction manager for this spoof XA
- * resource.
- * 
- * Persistence points required by the transport: ProxyXAResource: 1. Before a
- * transaction is propagated the Xid must be recorded 2. When a transaction is
- * successfully prepared the previously recorded Xid must be deleted and the
- * real Xid recorded – otherwise the transaction could only be aborted with a
- * heuristic The transport must register a *single* proxy XA resource per
- * subordinate transaction – thereby eliminating diamonds in the users
- * transaction flow. In my example I do this by registering the proxy xa
- * resource after I have spoken to the remote server thereby allowing me to use
- * knowledge from the remote server to determine whether or not a proxy is
- * required. Do notice how the proxy xa resource is created before the
- * transaction is flowed though, and the XID of the transaction is persisted to
- * assist with recovery. Once the proxy xa resource is prepared, the file is
- * then replaced and persisted again with the XID of the actual proxy xa
- * resource. The first persist was just so that when recovering this proxy xa
- * resource can be recovered so that we know we talked to a remote server for
- * this transaction (and the remote server may have prepared the transaction,
- * even if the parent failed before it was able to).
- * 
- * Recovery The proxy xa resource is responsible for recording which
- * transactions are known of at the remote server and can therefore be recovered
- * by it without requiring the proxy invoke the remote server to ascertain this
- * list. When a transaction is propagated to a server the transport is
- * responsible for detecting that the server has not participated in the
- * transaction yet and if so it must assign it the next available subordinate
- * name and persist this information to help with recovery (see ServerImpl.java
- * and the test itself for how to determine the next available subordinate name
- * and a potential method of persisting this data). This is important when a
- * proxy xa resource is involved in recovery and invokes commit or rollback as
- * the transaction must be reloaded by the remote server before the
- * commit/rollback – if it was prepared - before we attempt to complete the
- * transaction.
- * 
- * IMPORTANT: Although this example shows points at which the transport is
- * expected to persist data, it does not define concretely the mechanisms to do
- * so, nor should it be considered sufficient for reliably persisting this data.
- * For instance, we do not flush to disk.
+ * 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.
  */
-public class ProxyXAResource implements XAResource {
+public class ProxyXAResource implements XAResource, XAResourceWrapper, Serializable {
 
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
 	private int transactionTimeout;
-	private String remoteServerName = null;
-	private Map<Xid, File> map;
+	private String remoteServerName;
 	private String localServerName;
-	private LookupProvider lookupProvider;
-	private File file;
-	private boolean recover;
+	private transient boolean nonerecovered;
 
+	private Xid migratedXid;
+
 	/**
 	 * Create a new proxy to the remote server.
 	 * 
-	 * @param lookupProvider
+	 * @param LookupProvider
+	 *            .getLookupProvider()
 	 * @param localServerName
 	 * @param remoteServerName
 	 */
-	public ProxyXAResource(LookupProvider lookupProvider, String localServerName, String remoteServerName, File file) {
-		this.lookupProvider = lookupProvider;
+	public ProxyXAResource(String localServerName, String remoteServerName, Xid migratedXid) {
 		this.localServerName = localServerName;
 		this.remoteServerName = remoteServerName;
-		this.file = file;
-		map = new HashMap<Xid, File>();
+		this.migratedXid = migratedXid;
+		this.nonerecovered = true;
 	}
 
 	/**
-	 * Used by recovery
+	 * Constructor for fallback bottom up recovery.
 	 * 
-	 * @param lookupProvider
 	 * @param localServerName
-	 * @param map
 	 * @param remoteServerName
-	 * @param file
-	 * @throws IOException
 	 */
-	public ProxyXAResource(LookupProvider lookupProvider, String localServerName, String remoteServerName, Map<Xid, File> map) throws IOException {
-		this.lookupProvider = lookupProvider;
+	public ProxyXAResource(String localServerName, String remoteServerName) {
 		this.localServerName = localServerName;
 		this.remoteServerName = remoteServerName;
-		this.map = map;
-		this.recover = true;
 	}
 
-	public void deleteTemporaryFile() {
-		this.file.delete();
-	}
-
 	/**
 	 * Store the XID.
 	 */
@@ -153,74 +101,37 @@
 	public synchronized int prepare(Xid xid) throws XAException {
 		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_PREPARE [" + xid + "]");
 
-		// Persist a proxy for the remote server this can mean we try to recover
-		// a transaction at a remote server that did not get chance to
-		// prepare but the alternative is to orphan a prepared server
-
+		Xid toPropagate = migratedXid != null ? migratedXid : xid;
 		try {
-			File dir = new File(System.getProperty("user.dir") + "/distributedjta-examples/ProxyXAResource/" + localServerName + "/");
-			dir.mkdirs();
-			File file = new File(dir, new Uid().fileStringForm());
-			file.createNewFile();
-			DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
-
-			fos.writeInt(remoteServerName.length());
-			fos.writeBytes(remoteServerName);
-			fos.writeInt(xid.getFormatId());
-			fos.writeInt(xid.getGlobalTransactionId().length);
-			fos.write(xid.getGlobalTransactionId());
-			fos.writeInt(xid.getBranchQualifier().length);
-			fos.write(xid.getBranchQualifier());
-
-			if (map.containsKey(xid)) {
-				System.out.println(map.get(xid));
-				map.remove(xid).delete();
-			}
-			if (this.file != null) {
-				this.file.delete();
-			}
-
-			map.put(xid, file);
+			int propagatePrepare = LookupProvider.getInstance().lookup(remoteServerName).prepare(toPropagate, !nonerecovered);
+			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_PREPARED");
+			return propagatePrepare;
 		} catch (IOException e) {
-			e.printStackTrace();
-			throw new XAException(XAException.XAER_RMERR);
+			throw new XAException(XAException.XA_RETRY);
 		}
-
-		int propagatePrepare = lookupProvider.lookup(remoteServerName).prepare(xid);
-		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_PREPARED");
-		return propagatePrepare;
 	}
 
 	@Override
 	public synchronized void commit(Xid xid, boolean onePhase) throws XAException {
 		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMIT  [" + xid + "]");
 
+		Xid toPropagate = migratedXid != null ? migratedXid : xid;
 		try {
-			lookupProvider.lookup(remoteServerName).commit(xid, onePhase, recover);
+			LookupProvider.getInstance().lookup(remoteServerName).commit(toPropagate, onePhase, !nonerecovered);
 		} catch (IOException e) {
 			e.printStackTrace();
 			throw new XAException(XAException.XA_RETRY);
 		}
-
 		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMITED");
-
-		if (map.get(xid) != null) {
-			map.get(xid).delete();
-			map.remove(xid);
-		}
-
-		// THIS CAN ONLY HAPPEN IN 1PC OR ROLLBACK
-		if (file != null) {
-			file.delete();
-		}
 	}
 
 	@Override
 	public synchronized void rollback(Xid xid) throws XAException {
 		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACK[" + xid + "]");
 
+		Xid toPropagate = migratedXid != null ? migratedXid : xid;
 		try {
-			lookupProvider.lookup(remoteServerName).rollback(xid, recover);
+			LookupProvider.getInstance().lookup(remoteServerName).rollback(toPropagate, !nonerecovered);
 			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACKED");
 		} catch (XAException e) {
 			// We know the remote side must have done a JBTM-917
@@ -232,16 +143,6 @@
 			e.printStackTrace();
 			throw new XAException(XAException.XA_RETRY);
 		}
-
-		if (map.get(xid) != null) {
-			map.get(xid).delete();
-			map.remove(xid);
-		}
-
-		// THIS CAN ONLY HAPPEN IN 1PC OR ROLLBACK
-		if (file != null) {
-			file.delete();
-		}
 	}
 
 	/**
@@ -257,29 +158,39 @@
 	@Override
 	public Xid[] recover(int flag) throws XAException {
 		if ((flag & XAResource.TMSTARTRSCAN) == XAResource.TMSTARTRSCAN) {
-			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVER [XAResource.TMSTARTRSCAN]: "
-					+ remoteServerName);
+			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVER [XAResource.TMSTARTRSCAN]");
 		}
 		if ((flag & XAResource.TMENDRSCAN) == XAResource.TMENDRSCAN) {
-			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVER [XAResource.TMENDRSCAN]: "
-					+ remoteServerName);
+			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVER [XAResource.TMENDRSCAN]");
 		}
 
+		Xid[] toReturn = LookupProvider.getInstance().lookup(remoteServerName).recoverFor(localServerName);
+
+		if (toReturn != null) {
+			for (int i = 0; i < toReturn.length; i++) {
+				System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVERD: " + toReturn[i]);
+			}
+		}
+
 		if ((flag & XAResource.TMSTARTRSCAN) == XAResource.TMSTARTRSCAN) {
-			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVERD[XAResource.TMSTARTRSCAN]: "
-					+ remoteServerName);
+			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVERD[XAResource.TMSTARTRSCAN]");
 		}
 		if ((flag & XAResource.TMENDRSCAN) == XAResource.TMENDRSCAN) {
-			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVERD[XAResource.TMENDRSCAN]: "
-					+ remoteServerName);
+			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVERD[XAResource.TMENDRSCAN]");
 		}
-		return map.keySet().toArray(new Xid[0]);
+		return toReturn;
 	}
 
 	@Override
 	public void forget(Xid xid) throws XAException {
 		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_FORGET  [" + xid + "]");
-		lookupProvider.lookup(remoteServerName).forget(xid);
+
+		Xid toPropagate = migratedXid != null ? migratedXid : xid;
+		try {
+			LookupProvider.getInstance().lookup(remoteServerName).forget(toPropagate, !nonerecovered);
+		} catch (IOException e) {
+			throw new XAException(XAException.XA_RETRY);
+		}
 		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_FORGETED[" + xid + "]");
 	}
 
@@ -304,4 +215,37 @@
 		}
 		return toReturn;
 	}
-}
\ No newline at end of file
+
+	/**
+	 * Not used by the TM.
+	 */
+	@Override
+	public XAResource getResource() {
+		return null;
+	}
+
+	/**
+	 * Not used by the TM.
+	 */
+	@Override
+	public String getProductName() {
+		return null;
+	}
+
+	/**
+	 * Not used by the TM.
+	 */
+	@Override
+	public String getProductVersion() {
+		return null;
+	}
+
+	/**
+	 * This allows the proxy to contain meaningful information in the XID in
+	 * case of failure to recover.
+	 */
+	@Override
+	public String getJndiName() {
+		return "ProxyXAResource: " + localServerName + " " + remoteServerName;
+	}
+}

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ProxyXAResourceRecovery.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -21,79 +21,22 @@
  */
 package com.arjuna.jta.distributed.example.server.impl;
 
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import javax.transaction.xa.XAResource;
-import javax.transaction.xa.Xid;
 
 import org.jboss.tm.XAResourceRecovery;
 
-import com.arjuna.ats.jta.xa.XidImple;
-import com.arjuna.jta.distributed.example.server.LookupProvider;
-
 public class ProxyXAResourceRecovery implements XAResourceRecovery {
 
 	private List<ProxyXAResource> resources = new ArrayList<ProxyXAResource>();
 
-	public ProxyXAResourceRecovery(LookupProvider lookupProvider, String nodeName) throws IOException {
-		File directory = new File(System.getProperty("user.dir") + "/distributedjta-examples/ProxyXAResource/" + nodeName + "/");
-		Map<String, Map<Xid, File>> savedData = new HashMap<String, Map<Xid, File>>();
-		if (directory.exists() && directory.isDirectory()) {
-			File[] listFiles = directory.listFiles();
-			for (int i = 0; i < listFiles.length; i++) {
-				File file = listFiles[i];
-				DataInputStream fis = new DataInputStream(new FileInputStream(file));
-				int read = fis.readInt();
-				byte[] nameB = new byte[read];
-				fis.read(nameB, 0, read);
-				String remoteServerName = new String(nameB);
-
-				Map<Xid, File> map = savedData.get(remoteServerName);
-				if (map == null) {
-					map = new HashMap<Xid, File>();
-					savedData.put(remoteServerName, map);
-				}
-				final int formatId = fis.readInt();
-				int gtrid_length = fis.readInt();
-				final byte[] gtrid = new byte[gtrid_length];
-				fis.read(gtrid, 0, gtrid_length);
-
-				int bqual_length = fis.readInt();
-				final byte[] bqual = new byte[bqual_length];
-				fis.read(bqual, 0, bqual_length);
-				Xid xid = new XidImple(new Xid() {
-					@Override
-					public byte[] getBranchQualifier() {
-						return bqual;
-					}
-
-					@Override
-					public int getFormatId() {
-						return formatId;
-					}
-
-					@Override
-					public byte[] getGlobalTransactionId() {
-						return gtrid;
-					}
-				});
-				map.put(xid, file);
-			}
+	public ProxyXAResourceRecovery(String nodeName, String[] toRecoverFor) throws IOException {
+		for (int i = 0; i < toRecoverFor.length; i++) {
+			resources.add(new ProxyXAResource(nodeName, toRecoverFor[i]));
 		}
-		Iterator<String> iterator = savedData.keySet().iterator();
-		while (iterator.hasNext()) {
-			String remoteServerName = iterator.next();
-			Map<Xid, File> map = savedData.get(remoteServerName);
-			resources.add(new ProxyXAResource(lookupProvider, nodeName, remoteServerName, map));
-		}
 	}
 
 	@Override

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/examples/classes/com/arjuna/jta/distributed/example/server/impl/ServerImpl.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -21,11 +21,6 @@
  */
 package com.arjuna.jta.distributed.example.server.impl;
 
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.util.ArrayList;
@@ -33,13 +28,13 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.transaction.Synchronization;
 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 com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean;
@@ -47,40 +42,37 @@
 import com.arjuna.ats.arjuna.common.CoreEnvironmentBeanException;
 import com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean;
 import com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean;
-import com.arjuna.ats.arjuna.common.Uid;
 import com.arjuna.ats.arjuna.coordinator.TxControl;
+import com.arjuna.ats.arjuna.recovery.RecoveryManager;
 import com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser;
+import com.arjuna.ats.internal.arjuna.utils.ManualProcessId;
 import com.arjuna.ats.internal.jbossatx.jta.XAResourceRecordWrappingPluginImpl;
 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;
-import com.arjuna.ats.jta.xa.XATxConverter;
 import com.arjuna.ats.jta.xa.XidImple;
 import com.arjuna.jta.distributed.example.TestResourceRecovery;
 import com.arjuna.jta.distributed.example.server.LocalServer;
 import com.arjuna.jta.distributed.example.server.LookupProvider;
 import com.arjuna.jta.distributed.example.server.RemoteServer;
 
-/**
- * IMPORTANT: Although this example shows points at which the transport is
- * expected to persist data, it does not define concretely the mechanisms to do
- * so, nor should it be considered sufficient for reliably persisting this data.
- * For instance, we do not flush to disk.
- */
 public class ServerImpl implements LocalServer, RemoteServer {
 
+	private String nodeName;
 	private RecoveryManagerService recoveryManagerService;
 	private TransactionManagerService transactionManagerService;
-	private Map<SubordinateXidImple, TransactionImple> transactions = new HashMap<SubordinateXidImple, TransactionImple>();
-	private String nodeName;
+	private Map<SubordinateXidImple, TransactionImple> rootTransactionsAsSubordinate = new HashMap<SubordinateXidImple, TransactionImple>();
+	private RecoveryManager _recoveryManager;
 
-	public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset) throws CoreEnvironmentBeanException, IOException, SecurityException,
-			NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
+	public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset, String[] clusterBuddies) throws CoreEnvironmentBeanException,
+			IOException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
 		this.nodeName = nodeName;
+
 		RecoveryEnvironmentBean recoveryEnvironmentBean = com.arjuna.ats.arjuna.common.recoveryPropertyManager.getRecoveryEnvironmentBean();
 		recoveryEnvironmentBean.setRecoveryBackoffPeriod(1);
 
@@ -91,7 +83,7 @@
 		List<String> recoveryModuleClassNames = new ArrayList<String>();
 
 		recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
-		recoveryModuleClassNames.add("com.arjuna.ats.internal.txoj.recovery.TORecoveryModule");
+		// recoveryModuleClassNames.add("com.arjuna.ats.internal.txoj.recovery.TORecoveryModule");
 		recoveryModuleClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
 		recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryModuleClassNames);
 		List<String> expiryScannerClassNames = new ArrayList<String>();
@@ -100,9 +92,11 @@
 		recoveryEnvironmentBean.setRecoveryActivators(null);
 
 		CoreEnvironmentBean coreEnvironmentBean = com.arjuna.ats.arjuna.common.arjPropertyManager.getCoreEnvironmentBean();
-		coreEnvironmentBean.setSocketProcessIdPort(4714 + portOffset);
+		// coreEnvironmentBean.setSocketProcessIdPort(4714 + nodeName);
 		coreEnvironmentBean.setNodeIdentifier(nodeName);
-		coreEnvironmentBean.setSocketProcessIdMaxPorts(1);
+		// coreEnvironmentBean.setSocketProcessIdMaxPorts(1);
+		coreEnvironmentBean.setProcessImplementationClassName(ManualProcessId.class.getName());
+		coreEnvironmentBean.setPid(portOffset);
 
 		CoordinatorEnvironmentBean coordinatorEnvironmentBean = com.arjuna.ats.arjuna.common.arjPropertyManager.getCoordinatorEnvironmentBean();
 		coordinatorEnvironmentBean.setEnableStatistics(false);
@@ -147,10 +141,12 @@
 
 		recoveryManagerService = new RecoveryManagerService();
 		recoveryManagerService.create();
-		recoveryManagerService.addXAResourceRecovery(new ProxyXAResourceRecovery(lookupProvider, nodeName));
+		recoveryManagerService.addXAResourceRecovery(new ProxyXAResourceRecovery(nodeName, clusterBuddies));
 		recoveryManagerService.addXAResourceRecovery(new TestResourceRecovery(nodeName));
 
-		recoveryManagerService.start();
+		// recoveryManagerService.start();
+		_recoveryManager = RecoveryManager.manager();
+		RecoveryManager.manager().initialize();
 
 		transactionManagerService = new TransactionManagerService();
 		TxControl txControl = new com.arjuna.ats.arjuna.coordinator.TxControl();
@@ -165,53 +161,31 @@
 		return transactionManagerService.getTransactionManager();
 	}
 
-	/**
-	 * If this returns the root transaction, it must not be committed!
-	 * 
-	 * e.g. A transaction flowed 1,2,1 **must not** be committed at the third
-	 * stage of the flow!!!
-	 * 
-	 * NOTE: CMT would not allow you do this anyway
-	 * 
-	 * @throws IOException
-	 */
 	@Override
-	public boolean getAndResumeTransaction(int remainingTimeout, Xid toResume) throws XAException, IllegalStateException,
-			SystemException, IOException {
-		boolean existed = true;
-		Transaction transaction = transactions.get(new SubordinateXidImple(toResume));
+	public Xid getAndResumeTransaction(int remainingTimeout, Xid toResume) throws XAException, IllegalStateException, SystemException, IOException {
+		Xid toReturn = null;
+		Transaction transaction = rootTransactionsAsSubordinate.get(new SubordinateXidImple(toResume));
 		if (transaction == null) {
 			transaction = SubordinationManager.getTransactionImporter().getImportedTransaction(toResume);
 			if (transaction == null) {
-
-				XidImple toImport = new XidImple(toResume);
-				XATxConverter.setSubordinateNodeName(toImport.getXID(), TxControl.getXANodeName());
-
-				transaction = SubordinationManager.getTransactionImporter().importTransaction(toImport, remainingTimeout);
-				existed = false;
+				transaction = SubordinationManager.getTransactionImporter().importTransaction(toResume, remainingTimeout);
+				toReturn = ((TransactionImple) transaction).getTxId();
 			}
 		}
 		transactionManagerService.getTransactionManager().resume(transaction);
-		return existed;
+		return toReturn;
 	}
 
 	@Override
 	public String getNodeName() {
-		return TxControl.getXANodeName();
+		return nodeName;
 	}
 
-	/**
-	 * If a subordinate returns the root transaction in a call to
-	 * getAndResumeTransaction, it must not be committed
-	 * 
-	 * e.g. A transaction flowed 1,2,1 **must not** be committed at the third
-	 * stage of the flow!!!
-	 */
 	@Override
-	public void storeRootTransaction(Transaction transaction) throws SystemException {
-		TransactionImple transactionI = ((TransactionImple) transaction);
-		Xid txId = transactionI.getTxId();
-		transactions.put(new SubordinateXidImple(txId), transactionI);
+	public void storeRootTransaction() throws SystemException {
+		TransactionImple transaction = ((TransactionImple) transactionManagerService.getTransactionManager().getTransaction());
+		Xid txId = transaction.getTxId();
+		rootTransactionsAsSubordinate.put(new SubordinateXidImple(txId), transaction);
 	}
 
 	@Override
@@ -222,38 +196,15 @@
 
 	@Override
 	public void removeRootTransaction(Xid toMigrate) {
-		transactions.remove(new SubordinateXidImple(toMigrate));
+		rootTransactionsAsSubordinate.remove(new SubordinateXidImple(toMigrate));
 	}
 
 	@Override
-	public ProxyXAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName) throws IOException, SystemException {
-		// Persist a proxy for the remote server this can mean we try to recover
-		// transactions at a remote server that did not get chance to
-		// prepare but the alternative is to orphan a prepared server
-
-		Xid currentXid = getCurrentXid();
-		File dir = new File(System.getProperty("user.dir") + "/distributedjta-examples/ProxyXAResource/" + TxControl.getXANodeName());
-		dir.mkdirs();
-		File file = new File(dir, new Uid().fileStringForm());
-		file.createNewFile();
-		DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
-		fos.writeInt(remoteServerName.length());
-		fos.writeBytes(remoteServerName);
-		fos.writeInt(currentXid.getFormatId());
-		fos.writeInt(currentXid.getGlobalTransactionId().length);
-		fos.write(currentXid.getGlobalTransactionId());
-		fos.writeInt(currentXid.getBranchQualifier().length);
-		fos.write(currentXid.getBranchQualifier());
-
-		return new ProxyXAResource(lookupProvider, nodeName, remoteServerName, file);
+	public ProxyXAResource generateProxyXAResource(LookupProvider lookupProvider, String remoteServerName, Xid migratedXid) throws SystemException, IOException {
+		return new ProxyXAResource(getNodeName(), remoteServerName, migratedXid);
 	}
 
 	@Override
-	public void cleanupProxyXAResource(XAResource proxyXAResource) {
-		((ProxyXAResource) proxyXAResource).deleteTemporaryFile();
-	}
-
-	@Override
 	public Synchronization generateProxySynchronization(LookupProvider lookupProvider, String remoteServerName, Xid toRegisterAgainst) {
 		return new ProxySynchronization(lookupProvider, nodeName, remoteServerName, toRegisterAgainst);
 	}
@@ -264,10 +215,13 @@
 	}
 
 	@Override
-	public int prepare(Xid xid) throws XAException {
+	public int prepare(Xid xid, boolean recover) throws XAException, IOException {
 		ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
 		try {
 			Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+			if (recover) {
+				recover(xid);
+			}
 			return SubordinationManager.getXATerminator().prepare(xid);
 		} finally {
 			Thread.currentThread().setContextClassLoader(contextClassLoader);
@@ -277,11 +231,11 @@
 	@Override
 	public void commit(Xid xid, boolean onePhase, boolean recover) throws XAException, IOException {
 		ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-		if (recover) {
-			recover(xid);
-		}
 		try {
 			Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+			if (recover) {
+				recover(xid);
+			}
 			SubordinationManager.getXATerminator().commit(xid, onePhase);
 		} finally {
 			Thread.currentThread().setContextClassLoader(contextClassLoader);
@@ -291,26 +245,29 @@
 	@Override
 	public void rollback(Xid xid, boolean recover) throws XAException, IOException {
 		ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-		if (recover) {
-			recover(xid);
-		}
 		try {
 			Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+			if (recover) {
+				recover(xid);
+			}
 			SubordinationManager.getXATerminator().rollback(xid);
 		} finally {
 			Thread.currentThread().setContextClassLoader(contextClassLoader);
 		}
 	}
 
-	public void recover(Xid toRecover) throws XAException, IOException {
+	protected void recover(Xid toRecover) throws XAException, IOException {
 		((XATerminatorImple) SubordinationManager.getXATerminator()).doRecover(new XidImple(toRecover), null);
 	}
 
 	@Override
-	public void forget(Xid xid) throws XAException {
+	public void forget(Xid xid, boolean recover) throws XAException, IOException {
 		ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
 		try {
 			Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+			if (recover) {
+				recover(xid);
+			}
 			SubordinationManager.getXATerminator().forget(xid);
 		} finally {
 			Thread.currentThread().setContextClassLoader(contextClassLoader);
@@ -328,4 +285,14 @@
 			Thread.currentThread().setContextClassLoader(contextClassLoader);
 		}
 	}
+
+	@Override
+	public Xid[] recoverFor(String localServerName) throws XAException {
+		Set<Xid> toReturn = ((TransactionImporterImple) SubordinationManager.getTransactionImporter()).getInflightXids(localServerName);
+		Xid[] doRecover = ((XATerminatorImple) SubordinationManager.getXATerminator()).doRecover(null, localServerName);
+		if (doRecover != null) {
+			toReturn.addAll(Arrays.asList(doRecover));
+		}
+		return toReturn.toArray(new Xid[0]);
+	}
 }

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -51,11 +51,9 @@
 
 import com.arjuna.ats.arjuna.common.CoreEnvironmentBeanException;
 import com.arjuna.ats.jta.distributed.server.CompletionCounter;
-import com.arjuna.ats.jta.distributed.server.CompletionCounterImpl;
 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.LookupProviderImpl;
 
 @RunWith(BMUnitRunner.class)
 public class SimpleIsolatedServers {
@@ -63,9 +61,9 @@
 	private static int[] serverPortOffsets = new int[] { 1000, 2000, 3000 };
 	private static String[][] clusterBuddies = new String[][] { new String[] { "2000", "3000" }, new String[] { "1000", "3000" },
 			new String[] { "1000", "2000" } };
-	private static LookupProvider lookupProvider = LookupProviderImpl.getLookupProvider();
+	private static LookupProvider lookupProvider = LookupProvider.getInstance();
 	private static LocalServer[] localServers = new LocalServer[serverNodeNames.length];
-	private static CompletionCounter completionCounter = CompletionCounterImpl.getCompletionCounter();
+	private static CompletionCounter completionCounter = CompletionCounter.getInstance();
 
 	@BeforeClass
 	public static void setup() throws SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, ClassNotFoundException,

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResource.java	2011-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResource.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -33,11 +33,8 @@
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-import org.jboss.tm.XAResourceWrapper;
-
 import com.arjuna.ats.arjuna.common.Uid;
 import com.arjuna.ats.jta.distributed.server.CompletionCounter;
-import com.arjuna.ats.jta.distributed.server.CompletionCounterImpl;
 
 public class TestResource implements XAResource {
 	private Xid xid;
@@ -53,13 +50,13 @@
 	private CompletionCounter completionCounter;
 
 	public TestResource(String serverId, boolean readonly) {
-		this.completionCounter = CompletionCounterImpl.getCompletionCounter();
+		this.completionCounter = CompletionCounter.getInstance();
 		this.serverId = serverId;
 		this.readonly = readonly;
 	}
 
 	public TestResource(String serverId, File file) throws IOException {
-		this.completionCounter = CompletionCounterImpl.getCompletionCounter();
+		this.completionCounter = CompletionCounter.getInstance();
 		this.serverId = serverId;
 		this.file = file;
 		DataInputStream fis = new DataInputStream(new FileInputStream(file));
@@ -122,23 +119,15 @@
 				fos.flush();
 				fos.close();
 			} 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 + "]");
 		completionCounter.incrementCommit(serverId);
-		// String absoluteFile = file.getAbsolutePath();
-		// String newName = absoluteFile.substring(0, absoluteFile.length() -
-		// 1);
-		// File file2 = new File(newName);
-		// file.renameTo(file2);
 		if (file != null) {
 			if (!file.delete()) {
 				throw new XAException(XAException.XA_RETRY);

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java	2011-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/TestResourceRecovery.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -30,8 +30,6 @@
 
 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>();

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounter.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounter.java	2011-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounter.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -1,38 +1,105 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package com.arjuna.ats.jta.distributed.server;
-
-public interface CompletionCounter {
-	public void incrementCommit(String nodeName);
-
-	public void incrementRollback(String nodeName);
-
-	int getCommitCount(String nodeName);
-
-	int getRollbackCount(String nodeName);
-
-	public int getTotalCommitCount();
-
-	public int getTotalRollbackCount();
-	
-	public void reset();
-}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package com.arjuna.ats.jta.distributed.server;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class CompletionCounter {
+
+	private static CompletionCounter instance;
+
+	private Map<String, Integer> commitCounter = new HashMap<String, Integer>();
+	private Map<String, Integer> rollbackCounter = new HashMap<String, Integer>();
+
+	public static CompletionCounter getInstance() {
+		if (instance == null) {
+			instance = new CompletionCounter();
+		}
+		return instance;
+	}
+
+	protected CompletionCounter() {
+
+	}
+
+	public void incrementCommit(String nodeName) {
+		Integer integer = commitCounter.get(nodeName);
+		if (integer == null) {
+			integer = new Integer(1);
+		} else {
+			integer = new Integer(integer.intValue() + 1);
+		}
+		commitCounter.put(nodeName, integer);
+
+	}
+
+	public void incrementRollback(String nodeName) {
+		Integer integer = rollbackCounter.get(nodeName);
+		if (integer == null) {
+			integer = new Integer(1);
+		} else {
+			integer = new Integer(integer.intValue() + 1);
+		}
+		rollbackCounter.put(nodeName, integer);
+	}
+
+	public int getCommitCount(String nodeName) {
+		Integer integer = commitCounter.get(nodeName);
+		if (integer == null) {
+			integer = new Integer(0);
+		}
+		return integer;
+	}
+
+	public int getRollbackCount(String nodeName) {
+		Integer integer = rollbackCounter.get(nodeName);
+		if (integer == null) {
+			integer = new Integer(0);
+		}
+		return integer;
+	}
+
+	public int getTotalCommitCount() {
+		Integer toReturn = 0;
+		Iterator<Integer> iterator = commitCounter.values().iterator();
+		while (iterator.hasNext()) {
+			toReturn += iterator.next();
+		}
+		return toReturn;
+	}
+
+	public int getTotalRollbackCount() {
+		Integer toReturn = 0;
+		Iterator<Integer> iterator = rollbackCounter.values().iterator();
+		while (iterator.hasNext()) {
+			toReturn += iterator.next();
+		}
+		return toReturn;
+	}
+
+	public void reset() {
+		commitCounter.clear();
+		rollbackCounter.clear();
+	}
+}

Deleted: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounterImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounterImpl.java	2011-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounterImpl.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -1,88 +0,0 @@
-package com.arjuna.ats.jta.distributed.server;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-
-public class CompletionCounterImpl implements CompletionCounter {
-
-	private static CompletionCounter instance;
-
-	private Map<String, Integer> commitCounter = new HashMap<String, Integer>();
-	private Map<String, Integer> rollbackCounter = new HashMap<String, Integer>();
-
-	public static CompletionCounter getCompletionCounter() {
-		if (instance == null) {
-			instance = new CompletionCounterImpl();
-		}
-		return instance;
-	}
-
-	@Override
-	public void incrementCommit(String nodeName) {
-		Integer integer = commitCounter.get(nodeName);
-		if (integer == null) {
-			integer = new Integer(1);
-		} else {
-			integer = new Integer(integer.intValue() + 1);
-		}
-		commitCounter.put(nodeName, integer);
-
-	}
-
-	@Override
-	public void incrementRollback(String nodeName) {
-		Integer integer = rollbackCounter.get(nodeName);
-		if (integer == null) {
-			integer = new Integer(1);
-		} else {
-			integer = new Integer(integer.intValue() + 1);
-		}
-		rollbackCounter.put(nodeName, integer);
-	}
-
-	@Override
-	public int getCommitCount(String nodeName) {
-		Integer integer = commitCounter.get(nodeName);
-		if (integer == null) {
-			integer = new Integer(0);
-		}
-		return integer;
-	}
-
-	@Override
-	public int getRollbackCount(String nodeName) {
-		Integer integer = rollbackCounter.get(nodeName);
-		if (integer == null) {
-			integer = new Integer(0);
-		}
-		return integer;
-	}
-
-	@Override
-	public int getTotalCommitCount() {
-		Integer toReturn = 0;
-		Iterator<Integer> iterator = commitCounter.values().iterator();
-		while (iterator.hasNext()) {
-			toReturn += iterator.next();
-		}
-		return toReturn;
-	}
-
-	@Override
-	public int getTotalRollbackCount() {
-		Integer toReturn = 0;
-		Iterator<Integer> iterator = rollbackCounter.values().iterator();
-		while (iterator.hasNext()) {
-			toReturn += iterator.next();
-		}
-		return toReturn;
-	}
-
-	@Override
-	public void reset() {
-		commitCounter.clear();
-		rollbackCounter.clear();
-	}
-}

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/IsolatableServersClassLoader.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/IsolatableServersClassLoader.java	2011-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/IsolatableServersClassLoader.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -70,10 +70,6 @@
 		if (clazz != null) {
 			System.err.println("Already loaded: " + name);
 		} else {
-//			if (name.contains("BasicAction")) {
-//				System.err.println(name);
-//			}
-
 			if (!name.startsWith("com.arjuna") || (ignoredPackage != null && name.matches(ignoredPackage + ".[A-Za-z0-9]*"))) {
 				clazz = super.loadClass(name);
 			} else {

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -37,8 +37,8 @@
 
 public interface LocalServer {
 
-	public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset, String[] clusterBuddies) throws CoreEnvironmentBeanException, IOException, SecurityException,
-			NoSuchFieldException, IllegalArgumentException, IllegalAccessException;
+	public void initialise(LookupProvider lookupProvider, String nodeName, int portOffset, String[] clusterBuddies) throws CoreEnvironmentBeanException,
+			IOException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException;
 
 	public String getNodeName();
 

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProvider.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProvider.java	2011-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProvider.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -1,30 +1,54 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package com.arjuna.ats.jta.distributed.server;
-
-public interface LookupProvider {
-	public RemoteServer lookup(String jndiName);
-
-	public void clear();
-
-	public void bind(int index, RemoteServer connectTo);
-}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package com.arjuna.ats.jta.distributed.server;
+
+public class LookupProvider {
+	private static LookupProvider instance;
+
+	private RemoteServer[] remoteServers = new RemoteServer[3];
+
+	public static LookupProvider getInstance() {
+		if (instance == null) {
+			instance = new LookupProvider();
+		}
+		return instance;
+	}
+
+	protected LookupProvider() {
+	}
+
+	public RemoteServer lookup(String jndiName) {
+		int index = (Integer.valueOf(jndiName) / 1000) - 1;
+		return remoteServers[index];
+	}
+
+	public void clear() {
+		for (int i = 0; i < remoteServers.length; i++) {
+			// Disconnect
+			remoteServers[i] = null;
+		}
+	}
+
+	public void bind(int index, RemoteServer connectTo) {
+		remoteServers[index] = connectTo;
+	}
+}

Deleted: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProviderImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProviderImpl.java	2011-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LookupProviderImpl.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -1,42 +0,0 @@
-package com.arjuna.ats.jta.distributed.server;
-
-
-public class LookupProviderImpl implements LookupProvider {
-	static {
-		System.out.println("Loaded the provider");
-	}
-
-	private static LookupProviderImpl instance;
-
-	private RemoteServer[] remoteServers = new RemoteServer[3];
-
-	public static LookupProvider getLookupProvider() {
-		if (instance == null) {
-			instance = new LookupProviderImpl();
-		}
-		return instance;
-	}
-
-	public LookupProviderImpl() {
-		System.out.println("Created the provider");
-	}
-
-	@Override
-	public RemoteServer lookup(String jndiName) {
-		int index = (Integer.valueOf(jndiName) / 1000) - 1;
-		return remoteServers[index];
-	}
-
-	@Override
-	public void clear() {
-		for (int i = 0; i < remoteServers.length; i++) {
-			// Disconnect
-			remoteServers[i] = null;
-		}
-	}
-
-	@Override
-	public void bind(int index, RemoteServer connectTo) {
-		remoteServers[index] = connectTo;
-	}
-}

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-11-30 19:40:39 UTC (rev 37749)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java	2011-11-30 21:17:01 UTC (rev 37750)
@@ -30,8 +30,8 @@
 
 import org.jboss.tm.XAResourceWrapper;
 
-import com.arjuna.ats.jta.distributed.server.CompletionCounterImpl;
-import com.arjuna.ats.jta.distributed.server.LookupProviderImpl;
+import com.arjuna.ats.jta.distributed.server.CompletionCounter;
+import com.arjuna.ats.jta.distributed.server.LookupProvider;
 
 /**
  * I chose for this class to implement XAResourceWrapper so that I can provide a
@@ -54,7 +54,7 @@
 	/**
 	 * Create a new proxy to the remote server.
 	 * 
-	 * @param LookupProviderImpl
+	 * @param LookupProvider
 	 *            .getLookupProvider()
 	 * @param localServerName
 	 * @param remoteServerName
@@ -104,11 +104,10 @@
 
 		Xid toPropagate = migratedXid != null ? migratedXid : xid;
 		try {
-			int propagatePrepare = LookupProviderImpl.getLookupProvider().lookup(remoteServerName).prepare(toPropagate, !nonerecovered);
+			int propagatePrepare = LookupProvider.getInstance().lookup(remoteServerName).prepare(toPropagate, !nonerecovered);
 			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_PREPARED");
 			return propagatePrepare;
 		} catch (IOException e) {
-			e.printStackTrace();
 			throw new XAException(XAException.XA_RETRY);
 		}
 	}
@@ -119,7 +118,7 @@
 
 		Xid toPropagate = migratedXid != null ? migratedXid : xid;
 		try {
-			LookupProviderImpl.getLookupProvider().lookup(remoteServerName).commit(toPropagate, onePhase, !nonerecovered);
+			LookupProvider.getInstance().lookup(remoteServerName).commit(toPropagate, onePhase, !nonerecovered);
 		} catch (IOException e) {
 			e.printStackTrace();
 			throw new XAException(XAException.XA_RETRY);
@@ -127,7 +126,7 @@
 		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_COMMITED");
 
 		// THIS CAN ONLY HAPPEN IN 1PC OR ROLLBACK
-		CompletionCounterImpl.getCompletionCounter().incrementCommit(localServerName);
+		CompletionCounter.getInstance().incrementCommit(localServerName);
 
 	}
 
@@ -137,7 +136,7 @@
 
 		Xid toPropagate = migratedXid != null ? migratedXid : xid;
 		try {
-			LookupProviderImpl.getLookupProvider().lookup(remoteServerName).rollback(toPropagate, !nonerecovered);
+			LookupProvider.getInstance().lookup(remoteServerName).rollback(toPropagate, !nonerecovered);
 			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACKED");
 		} catch (XAException e) {
 			// We know the remote side must have done a JBTM-917
@@ -150,7 +149,7 @@
 			throw new XAException(XAException.XA_RETRY);
 		}
 
-		CompletionCounterImpl.getCompletionCounter().incrementRollback(localServerName);
+		CompletionCounter.getInstance().incrementRollback(localServerName);
 	}
 
 	/**
@@ -172,7 +171,7 @@
 			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_RECOVER [XAResource.TMENDRSCAN]");
 		}
 
-		Xid[] toReturn = LookupProviderImpl.getLookupProvider().lookup(remoteServerName).recoverFor(localServerName);
+		Xid[] toReturn = LookupProvider.getInstance().lookup(remoteServerName).recoverFor(localServerName);
 
 		if (toReturn != null) {
 			for (int i = 0; i < toReturn.length; i++) {
@@ -195,9 +194,8 @@
 
 		Xid toPropagate = migratedXid != null ? migratedXid : xid;
 		try {
-			LookupProviderImpl.getLookupProvider().lookup(remoteServerName).forget(toPropagate, !nonerecovered);
+			LookupProvider.getInstance().lookup(remoteServerName).forget(toPropagate, !nonerecovered);
 		} catch (IOException e) {
-			e.printStackTrace();
 			throw new XAException(XAException.XA_RETRY);
 		}
 		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_FORGETED[" + xid + "]");



More information about the jboss-svn-commits mailing list