[jboss-cvs] JBoss Messaging SVN: r3655 - in trunk: src/main/org/jboss/jms/client/api and 17 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 31 15:26:33 EST 2008


Author: timfox
Date: 2008-01-31 15:26:32 -0500 (Thu, 31 Jan 2008)
New Revision: 3655

Added:
   trunk/src/main/org/jboss/messaging/core/ResourceManager.java
   trunk/src/main/org/jboss/messaging/core/impl/ResourceManagerImpl.java
   trunk/src/main/org/jboss/messaging/core/impl/XidImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXACommitMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAEndMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAForgetMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAGetInDoubtXidsResponseCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAGetTimeoutResponseCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAJoinMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAPrepareMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAResponseCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAResumeMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXARollbackMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXASetTimeoutMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXASetTimeoutResponseCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAStartMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXACommitMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAEndMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAForgetMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetInDoubtXidsRequest.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetInDoubtXidsResponse.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetTimeoutMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetTimeoutResponse.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAJoinMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAPrepareMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAResponse.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAResumeMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXARollbackMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASetTimeoutMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASetTimeoutResponse.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAStartMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASuspendMessage.java
Removed:
   trunk/src/main/org/jboss/messaging/core/TransactionStore.java
   trunk/src/main/org/jboss/messaging/core/tx/
Modified:
   trunk/.classpath
   trunk/src/main/org/jboss/jms/client/api/ClientSession.java
   trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
   trunk/src/main/org/jboss/messaging/core/MessagingServer.java
   trunk/src/main/org/jboss/messaging/core/Transaction.java
   trunk/src/main/org/jboss/messaging/core/impl/BindingImpl.java
   trunk/src/main/org/jboss/messaging/core/impl/ConditionImpl.java
   trunk/src/main/org/jboss/messaging/core/impl/DestinationImpl.java
   trunk/src/main/org/jboss/messaging/core/impl/QueueImpl.java
   trunk/src/main/org/jboss/messaging/core/impl/TransactionImpl.java
   trunk/src/main/org/jboss/messaging/core/impl/filter/FilterImpl.java
   trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/AbstractPacketCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/PacketType.java
   trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/BDBSpeedTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java
   trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java
   trunk/tests/src/org/jboss/messaging/core/tx/test/unit/MessagingXidTest.java
   trunk/tests/src/org/jboss/messaging/test/unit/UnitTestCase.java
   trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/XATest.java
   trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCReceiver.java
   trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCSender.java
Log:
XA support


Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/.classpath	2008-01-31 20:26:32 UTC (rev 3655)
@@ -17,7 +17,6 @@
 	<classpathentry kind="src" path="docs/examples/topic/src"/>
 	<classpathentry excluding="**/.svn/**/*" kind="src" path="src/main"/>
 	<classpathentry excluding="**/.svn/**/*" kind="src" path="tests/src"/>
-	<classpathentry kind="src" path="tests/etc/ide"/>
 	<classpathentry excluding="ide/" kind="src" path="tests/etc"/>
 	<classpathentry kind="lib" path="thirdparty/oswego-concurrent/lib/concurrent.jar"/>
 	<classpathentry kind="lib" path="thirdparty/jgroups/lib/jgroups.jar"/>

Modified: trunk/src/main/org/jboss/jms/client/api/ClientSession.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientSession.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/jms/client/api/ClientSession.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -21,7 +21,7 @@
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
  */
-public interface ClientSession
+public interface ClientSession extends XAResource
 {
    ClientConnection getConnection();
 
@@ -71,4 +71,6 @@
    //TOD hide these  private api
    void delivered(long deliveryID, boolean expired);
    
+   void flushAcks() throws JMSException;
+   
 }

Modified: trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -23,13 +23,16 @@
 
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import javax.jms.IllegalStateException;
 import javax.jms.JMSException;
 import javax.jms.TransactionInProgressException;
+import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
 
 import org.jboss.jms.client.SelectorTranslator;
 import org.jboss.jms.client.api.ClientBrowser;
@@ -44,6 +47,7 @@
 import org.jboss.messaging.core.Destination;
 import org.jboss.messaging.core.Message;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
+import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
 import org.jboss.messaging.core.remoting.wireformat.AddTemporaryDestinationMessage;
 import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
 import org.jboss.messaging.core.remoting.wireformat.ClosingMessage;
@@ -59,6 +63,22 @@
 import org.jboss.messaging.core.remoting.wireformat.SessionCommitMessage;
 import org.jboss.messaging.core.remoting.wireformat.SessionRollbackMessage;
 import org.jboss.messaging.core.remoting.wireformat.SessionSendMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXACommitMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAEndMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAForgetMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsRequest;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAJoinMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAPrepareMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResumeMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXARollbackMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAStartMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASuspendMessage;
 import org.jboss.messaging.core.remoting.wireformat.UnsubscribeMessage;
 import org.jboss.messaging.util.ClearableQueuedExecutor;
 import org.jboss.messaging.util.Logger;
@@ -91,8 +111,6 @@
 
    private int lazyAckBatchSize;
    
-   private XAResource xaResource;
-           
    private volatile boolean closed;
       
    private boolean acked = true;
@@ -120,6 +138,8 @@
    
    private Map<String, ClientConsumer> consumers = new HashMap<String, ClientConsumer>();
    
+   //For testing only
+   private boolean setForceNotSameRM;
       
    // Constructors ---------------------------------------------------------------------------------
    
@@ -136,7 +156,7 @@
  
       executor = new ClearableQueuedExecutor(new LinkedQueue());
       
-      this.lazyAckBatchSize = lazyAckBatchSize;   
+      this.lazyAckBatchSize = lazyAckBatchSize;         
    }
    
    // ClientSession implementation ----------------------------------------------------
@@ -392,7 +412,7 @@
 
    public XAResource getXAResource()
    {
-      return xaResource;
+      return this;
    }
 
    public void send(Message m) throws JMSException
@@ -445,9 +465,259 @@
    {
       return closed;
    }
+   
+   public void flushAcks() throws JMSException
+   {
+      this.acknowledgeInternal(false);
+   }
+   
+   // XAResource implementation --------------------------------------------------------------------
+   
+   public void commit(Xid xid, boolean onePhase) throws XAException
+   {
+      try
+      { 
+         SessionXACommitMessage packet = new SessionXACommitMessage(xid, onePhase);
+                  
+         SessionXAResponse response = (SessionXAResponse)remotingConnection.send(id, packet);
+         
+         if (response.isError())
+         {
+            throw new XAException(response.getResponseCode());
+         }
+      }
+      catch (JMSException e)
+      {
+         log.error("Caught jmsexecptione ", e);
+         //This should never occur
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
 
+   public void end(Xid xid, int flags) throws XAException
+   {
+      try
+      {
+         AbstractPacket packet;
+         
+         if (flags == XAResource.TMSUSPEND)
+         {
+            packet = new SessionXASuspendMessage();                  
+         }
+         else if (flags == XAResource.TMSUCCESS)
+         {
+            packet = new SessionXAEndMessage(xid, false);
+         }
+         else if (flags == XAResource.TMFAIL)
+         {
+            packet = new SessionXAEndMessage(xid, true);
+         }
+         else
+         {
+            throw new XAException(XAException.XAER_INVAL);
+         }
+               
+         //Need to flush any acks to server first
+         acknowledgeInternal(false);
+         
+         SessionXAResponse response = (SessionXAResponse)remotingConnection.send(id, packet);
+         
+         if (response.isError())
+         {
+            throw new XAException(response.getResponseCode());
+         }
+      }
+      catch (JMSException e)
+      {
+         log.error("Caught jmsexecptione ", e);
+         //This should never occur
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
+
+   public void forget(Xid xid) throws XAException
+   {
+      try
+      {                              
+         SessionXAResponse response = (SessionXAResponse)remotingConnection.send(id, new SessionXAForgetMessage(xid));
+         
+         if (response.isError())
+         {
+            throw new XAException(response.getResponseCode());
+         }
+      }
+      catch (JMSException e)
+      {
+         //This should never occur
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
+
+   public int getTransactionTimeout() throws XAException
+   {
+      try
+      {                              
+         SessionXAGetTimeoutResponse response =
+            (SessionXAGetTimeoutResponse)remotingConnection.send(id, new SessionXAGetTimeoutMessage());
+         
+         return response.getTimeoutSeconds();
+      }
+      catch (JMSException e)
+      {
+         //This should never occur
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
+
+   public boolean isSameRM(XAResource xares) throws XAException
+   {
+      if (!(xares instanceof ClientSessionImpl))
+      {
+         return false;
+      }
+      
+      if (forceNotSameRM)
+      {
+         return false;
+      }
+      
+      ClientSessionImpl other = (ClientSessionImpl)xares;
+      
+      return this.connection.getServerID() == other.getConnection().getServerID();
+   }
+
+   public int prepare(Xid xid) throws XAException
+   {
+      try
+      {
+         SessionXAPrepareMessage packet = new SessionXAPrepareMessage(xid);
+         
+         SessionXAResponse response = (SessionXAResponse)remotingConnection.send(id, packet);
+         
+         if (response.isError())
+         {
+            throw new XAException(response.getResponseCode());
+         }
+         else
+         {
+            return response.getResponseCode();
+         }
+      }
+      catch (JMSException e)
+      {
+         log.error("Caught jmsexecptione ", e);
+         //This should never occur
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
+
+   public Xid[] recover(int flag) throws XAException
+   {
+      try
+      {
+         SessionXAGetInDoubtXidsRequest packet = new SessionXAGetInDoubtXidsRequest();
+         
+         SessionXAGetInDoubtXidsResponse response = (SessionXAGetInDoubtXidsResponse)remotingConnection.send(id, packet);
+         
+         List<Xid> xids = response.getXids();
+         
+         Xid[] xidArray = xids.toArray(new Xid[xids.size()]);
+         
+         return xidArray;
+      }
+      catch (JMSException e)
+      {
+         //This should never occur
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
+
+   public void rollback(Xid xid) throws XAException
+   {
+      try
+      {
+
+         SessionXARollbackMessage packet = new SessionXARollbackMessage(xid);
+         
+         SessionXAResponse response = (SessionXAResponse)remotingConnection.send(id, packet);
+         
+         if (response.isError())
+         {
+            throw new XAException(response.getResponseCode());
+         }
+      }
+      catch (JMSException e)
+      {
+         log.error("Caught jmsexecptione ", e);
+         //This should never occur
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
+
+   public boolean setTransactionTimeout(int seconds) throws XAException
+   {
+      try
+      {                              
+         SessionXASetTimeoutResponse response =
+            (SessionXASetTimeoutResponse)remotingConnection.send(id, new SessionXASetTimeoutMessage(seconds));
+         
+         return response.isOK();
+      }
+      catch (JMSException e)
+      {
+         //This should never occur
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
+
+   public void start(Xid xid, int flags) throws XAException
+   {
+      try
+      {
+         AbstractPacket packet;
+         
+         if (flags == XAResource.TMJOIN)
+         {
+            packet = new SessionXAJoinMessage(xid);                  
+         }
+         else if (flags == XAResource.TMRESUME)
+         {
+            packet = new SessionXAResumeMessage(xid);
+         }
+         else if (flags == XAResource.TMNOFLAGS)
+         {
+            packet = new SessionXAStartMessage(xid);
+         }
+         else
+         {
+            throw new XAException(XAException.XAER_INVAL);
+         }
+                     
+         SessionXAResponse response = (SessionXAResponse)remotingConnection.send(id, packet);
+         
+         if (response.isError())
+         {
+            log.error("XA operation failed " + response.getMessage() +" code:" + response.getResponseCode());
+            throw new XAException(response.getResponseCode());
+         }
+      }
+      catch (JMSException e)
+      {
+         log.error("Caught jmsexecptione ", e);
+         //This should never occur
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
+
    // Public ---------------------------------------------------------------------------------------
   
+   private boolean forceNotSameRM;
+   
+   public void setForceNotSameRM(boolean force)
+   {
+      this.forceNotSameRM = force;
+   }
+   
    // Protected ------------------------------------------------------------------------------------
 
    // Package Private ------------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -56,6 +56,7 @@
 import org.jboss.messaging.core.MessagingServer;
 import org.jboss.messaging.core.PostOffice;
 import org.jboss.messaging.core.impl.ConditionImpl;
+import org.jboss.messaging.core.impl.XidImpl;
 import org.jboss.messaging.core.remoting.PacketHandler;
 import org.jboss.messaging.core.remoting.PacketSender;
 import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
@@ -67,7 +68,6 @@
 import org.jboss.messaging.core.remoting.wireformat.Packet;
 import org.jboss.messaging.core.remoting.wireformat.PacketType;
 import org.jboss.messaging.core.remoting.wireformat.SetClientIDMessage;
-import org.jboss.messaging.core.tx.MessagingXid;
 import org.jboss.messaging.util.ExceptionUtil;
 import org.jboss.messaging.util.Logger;
 import org.jboss.messaging.util.Util;
@@ -227,7 +227,8 @@
          
          //Note we only replicate transacted and client acknowledge sessions.
          ServerSessionEndpoint ep =
-            new ServerSessionEndpoint(sessionID, this, autoCommitSends, autoCommitAcks, xa, sender);
+            new ServerSessionEndpoint(sessionID, this, autoCommitSends, autoCommitAcks, xa, sender,
+                                      messagingServer.getResourceManager());            
 
          synchronized (sessions)
          {
@@ -409,13 +410,13 @@
     * This would be used by the transaction manager in recovery or by a tool to apply
     * heuristic decisions to commit or rollback particular transactions
     */
-   public MessagingXid[] getPreparedTransactions() throws JMSException
+   public XidImpl[] getPreparedTransactions() throws JMSException
    {
       try
       {
          List<Xid> xids = messagingServer.getPersistenceManager().getInDoubtXids();
 
-         return (MessagingXid[])xids.toArray(new MessagingXid[xids.size()]);
+         return (XidImpl[])xids.toArray(new XidImpl[xids.size()]);
       }
       catch (Throwable t)
       {

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -41,6 +41,9 @@
 import javax.jms.InvalidDestinationException;
 import javax.jms.InvalidSelectorException;
 import javax.jms.JMSException;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
 
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.destination.JBossQueue;
@@ -59,6 +62,7 @@
 import org.jboss.messaging.core.MessagingServer;
 import org.jboss.messaging.core.PostOffice;
 import org.jboss.messaging.core.Queue;
+import org.jboss.messaging.core.ResourceManager;
 import org.jboss.messaging.core.Transaction;
 import org.jboss.messaging.core.impl.ConditionImpl;
 import org.jboss.messaging.core.impl.DeliveryImpl;
@@ -82,6 +86,19 @@
 import org.jboss.messaging.core.remoting.wireformat.SessionAcknowledgeMessage;
 import org.jboss.messaging.core.remoting.wireformat.SessionCancelMessage;
 import org.jboss.messaging.core.remoting.wireformat.SessionSendMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXACommitMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAEndMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAForgetMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAJoinMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAPrepareMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResumeMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXARollbackMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAStartMessage;
 import org.jboss.messaging.core.remoting.wireformat.UnsubscribeMessage;
 import org.jboss.messaging.util.ExceptionUtil;
 import org.jboss.messaging.util.Logger;
@@ -161,12 +178,14 @@
    private boolean autoCommitSends;
    
    private boolean autoCommitAcks;
+   
+   private ResourceManager resourceManager;
 
    // Constructors ---------------------------------------------------------------------------------
 
    ServerSessionEndpoint(String sessionID, ServerConnectionEndpoint connectionEndpoint,
                          boolean autoCommitSends, boolean autoCommitAcks, boolean xa,
-                         PacketSender sender) throws Exception
+                         PacketSender sender, ResourceManager resourceManager) throws Exception
    {
       this.id = sessionID;
 
@@ -188,9 +207,11 @@
       
       this.xa = xa;
       
-      tx = new TransactionImpl();
-      
-      
+      if (!xa)
+      {
+         tx = new TransactionImpl();
+      }
+            
       this.sender = sender;
       
       //this.transactionalSends = transactionalSends;
@@ -198,6 +219,8 @@
       this.autoCommitSends = autoCommitSends;
       
       this.autoCommitAcks = autoCommitAcks;
+      
+      this.resourceManager = resourceManager;
    }
    
    
@@ -806,6 +829,13 @@
    {     
       try
       {                        
+         if (tx == null)
+         {
+            //Might be null if XA
+            
+            tx = new TransactionImpl();
+         }
+         
          //Synchronize to prevent any new deliveries arriving during this recovery
          synchronized (this)
          {                     
@@ -883,7 +913,7 @@
    {
       try
       {
-         tx.commit(sp.getPersistenceManager());      
+         tx.commit(true, sp.getPersistenceManager());      
       }
       catch (Throwable t)
       {
@@ -891,6 +921,332 @@
       }
    }
          
+   private SessionXAResponse XACommit(boolean onePhase, Xid xid)
+   {      
+      try
+      {
+         if (tx != null)
+         {
+            final String msg = "Cannot commit, session is currently doing work in a transaction " + tx.getXid();
+            
+            return new SessionXAResponse(true, XAException.XAER_PROTO, msg);            
+         }
+         
+         Transaction theTx = resourceManager.getTransaction(xid);
+         
+         if (theTx == null)
+         {
+            final String msg = "Cannot find xid in resource manager: " + xid;
+            
+            return new SessionXAResponse(true, XAException.XAER_NOTA, msg);
+         }
+         
+         if (theTx.isSuspended())
+         { 
+            return new SessionXAResponse(true, XAException.XAER_PROTO, "Cannot commit transaction, it is suspended " + xid);
+         }
+         
+         theTx.commit(onePhase, sp.getPersistenceManager());      
+         
+         boolean removed = resourceManager.removeTransaction(xid);
+         
+         if (!removed)
+         {
+            final String msg = "Failed to remove transaction: " + xid;
+            
+            return new SessionXAResponse(true, XAException.XAER_PROTO, msg);
+         }
+         
+         return new SessionXAResponse(false, XAResource.XA_OK, null);
+      }
+      catch (Exception e)
+      {
+         log.error("Failed to commit transaction branch", e);
+         
+         //Returning retry allows the tx manager to try again - otherwise heuristic action will
+         //be needed
+         return new SessionXAResponse(true, XAException.XA_RETRY, "Consult server logs for exception logging");
+      }
+   }
+   
+   private SessionXAResponse XAEnd(Xid xid, boolean failed)
+   {  
+      if (tx != null && tx.getXid().equals(xid))
+      {
+         if (tx.isSuspended())
+         {
+            final String msg = "Cannot end, transaction is suspended";
+            
+            return new SessionXAResponse(true, XAException.XAER_PROTO, msg);   
+         }
+         
+         tx = null;
+      }
+      else
+      {
+         //It's also legal for the TM to call end for a Xid in the suspended state
+         //See JTA 1.1 spec 3.4.4 - state diagram
+         //Although in practice TMs rarely do this.
+         Transaction theTx = resourceManager.getTransaction(xid);
+         
+         if (theTx == null)
+         {
+            final String msg = "Cannot find suspended transaction to end " + xid;
+            
+            return new SessionXAResponse(true, XAException.XAER_NOTA, msg);
+         }
+         
+         if (!theTx.isSuspended())
+         {
+            final String msg = "Transaction is not suspended " + xid;
+            
+            return new SessionXAResponse(true, XAException.XAER_PROTO, msg);
+         }
+         
+         theTx.resume();                  
+      }
+
+      return new SessionXAResponse(false, XAResource.XA_OK, null);
+   }
+   
+   private SessionXAResponse XAForget(Xid xid)
+   {      
+      //Do nothing since we don't support heuristic commits / rollback from the resource manager
+      
+      return new SessionXAResponse(false, XAResource.XA_OK, null);
+   }
+   
+   private SessionXAResponse XAJoin(Xid xid)
+   {   
+      try
+      {
+         Transaction theTx = resourceManager.getTransaction(xid);
+         
+         if (theTx == null)
+         {
+            final String msg = "Cannot find xid in resource manager: " + xid;
+            
+            return new SessionXAResponse(true, XAException.XAER_NOTA, msg);
+         }
+         
+         if (theTx.isSuspended())
+         {
+            return new SessionXAResponse(true, XAException.XAER_PROTO, "Cannot join tx, it is suspended " + xid);
+         }
+         
+         tx = theTx;
+         
+         return new SessionXAResponse(false, XAResource.XA_OK, null);
+      }
+      catch (Exception e)
+      {
+         log.error("Failed to join transaction branch", e);
+
+         return new SessionXAResponse(true, XAException.XAER_RMERR, "Consult server logs for exception logging");
+      }          
+   }
+   
+   private SessionXAResponse XAPrepare(Xid xid)
+   {      
+      try
+      {
+         if (tx != null)
+         {
+            final String msg = "Cannot commit, session is currently doing work in a transaction " + tx.getXid();
+            
+            return new SessionXAResponse(true, XAException.XAER_PROTO, msg);            
+         }
+         
+         Transaction theTx = resourceManager.getTransaction(xid);
+         
+         if (theTx == null)
+         {
+            final String msg = "Cannot find xid in resource manager: " + xid;
+            
+            return new SessionXAResponse(true, XAException.XAER_NOTA, msg);
+         }
+         
+         if (theTx.isSuspended())
+         { 
+            return new SessionXAResponse(true, XAException.XAER_PROTO, "Cannot prepare transaction, it is suspended " + xid);
+         }
+         
+         if (theTx.isEmpty())
+         {
+            //Nothing to do - remove it
+            
+            boolean removed = resourceManager.removeTransaction(xid);
+            
+            if (!removed)
+            {
+               final String msg = "Failed to remove transaction: " + xid;
+               
+               return new SessionXAResponse(true, XAException.XAER_PROTO, msg);
+            }
+            
+            return new SessionXAResponse(false, XAResource.XA_RDONLY, null);
+         }
+         else
+         {         
+            theTx.prepare(sp.getPersistenceManager());
+            
+            return new SessionXAResponse(false, XAResource.XA_OK, null);
+         }
+      }
+      catch (Exception e)
+      {
+         log.error("Failed to prepare transaction branch", e);
+         
+         return new SessionXAResponse(true, XAException.XAER_RMERR, "Consult server logs for exception logging");
+      }
+   }
+   
+   private SessionXAResponse XAResume(Xid xid)
+   {            
+      try
+      {
+         if (tx != null)
+         {
+            final String msg = "Cannot resume, session is currently doing work in a transaction " + tx.getXid();
+            
+            return new SessionXAResponse(true, XAException.XAER_PROTO, msg);            
+         }
+         
+         Transaction theTx = resourceManager.getTransaction(xid);
+         
+         if (theTx == null)
+         {
+            final String msg = "Cannot find xid in resource manager: " + xid;
+            
+            return new SessionXAResponse(true, XAException.XAER_NOTA, msg);
+         }
+         
+         if (!theTx.isSuspended())
+         { 
+            return new SessionXAResponse(true, XAException.XAER_PROTO, "Cannot resume transaction, it is not suspended " + xid);
+         }
+         
+         tx = theTx;
+         
+         tx.resume();
+         
+         return new SessionXAResponse(false, XAResource.XA_OK, null);
+      }
+      catch (Exception e)
+      {
+         log.error("Failed to join transaction branch", e);
+
+         return new SessionXAResponse(true, XAException.XAER_RMERR, "Consult server logs for exception logging");
+      }         
+   }
+    
+   private SessionXAResponse XARollback(Xid xid)
+   {      
+      try
+      {
+         if (tx != null)
+         {
+            final String msg = "Cannot roll back, session is currently doing work in a transaction " + tx.getXid();
+            
+            return new SessionXAResponse(true, XAException.XAER_PROTO, msg);            
+         }
+         
+         Transaction theTx = resourceManager.getTransaction(xid);
+         
+         if (theTx == null)
+         {
+            final String msg = "Cannot find xid in resource manager: " + xid;
+            
+            return new SessionXAResponse(true, XAException.XAER_NOTA, msg);
+         }
+         
+         if (theTx.isSuspended())
+         { 
+            return new SessionXAResponse(true, XAException.XAER_PROTO, "Cannot rollback transaction, it is suspended " + xid);
+         }
+                  
+         theTx.rollback(sp.getPersistenceManager());
+         
+         boolean removed = resourceManager.removeTransaction(xid);
+         
+         if (!removed)
+         {
+            final String msg = "Failed to remove transaction: " + xid;
+            
+            return new SessionXAResponse(true, XAException.XAER_PROTO, msg);
+         }
+         
+         return new SessionXAResponse(false, XAResource.XA_OK, null);                  
+      }
+      catch (Exception e)
+      {
+         log.error("Failed to roll back transaction branch", e);
+
+         return new SessionXAResponse(true, XAException.XAER_RMERR, "Consult server logs for exception logging");
+      }         
+   }
+   
+   private SessionXAResponse XAStart(Xid xid)
+   {      
+      if (tx != null)
+      {
+         final String msg = "Cannot start, session is already doing work in a transaction " + tx.getXid();
+         
+         return new SessionXAResponse(true, XAException.XAER_PROTO, msg);            
+      }
+      
+      tx = new TransactionImpl(xid);
+      
+      boolean added = resourceManager.putTransaction(xid, tx);
+      
+      if (!added)
+      {
+         final String msg = "Cannot start, there is already a xid " + tx.getXid();
+         
+         return new SessionXAResponse(true, XAException.XAER_DUPID, msg);          
+      }
+      
+      return new SessionXAResponse(false, XAResource.XA_OK, null);     
+   }
+   
+   private SessionXAResponse XASuspend() throws JMSException
+   {      
+      if (tx == null)
+      {
+         final String msg = "Cannot suspend, session is not doing work in a transaction " + tx.getXid();
+         
+         return new SessionXAResponse(true, XAException.XAER_PROTO, msg);            
+      }  
+      
+      if (tx.isSuspended())
+      {
+         final String msg = "Cannot suspend, transaction is already suspended " + tx.getXid();
+         
+         return new SessionXAResponse(true, XAException.XAER_PROTO, msg);   
+      }
+      
+      tx.suspend();
+      
+      tx = null;
+      
+      return new SessionXAResponse(false, XAResource.XA_OK, null);   
+   }
+   
+   private List<Xid> getInDoubtXids() throws JMSException
+   {
+      return null;
+   }
+   
+   private int getXATimeout()
+   {
+      return resourceManager.getTimeoutSeconds();
+   }
+   
+   private boolean setXATimeout(int timeoutSeconds)
+   {
+      return resourceManager.setTimeoutSeconds(timeoutSeconds);
+   }
+      
    // Protected ------------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------
@@ -1348,141 +1704,16 @@
          security.check(dest, CheckType.CREATE, this.getConnectionEndpoint());
       }
    }
+    
 
-
-   // Inner classes --------------------------------------------------------------------------------
-
-//   /*
-//    * Holds a record of a delivery - we need to store the consumer id as well
-//    * hence this class
-//    * We can't rely on the cancel being driven from the ClientConsumer since
-//    * the deliveries may have got lost in transit (ignored) since the consumer might have closed
-//    * when they were in transit.
-//    * In such a case we might otherwise end up with the consumer closing but not all it's deliveries being
-//    * cancelled, which would mean they wouldn't be cancelled until the session is closed which is too late
-//    *
-//    * We need to store various pieces of information, such as consumer id, dlq, expiry queue
-//    * since we need this at cancel time, but by then the actual consumer might have closed
-//    */
-//   private static class DeliveryRecord
-//   {
-//   	// We need to cache the attributes here  since the consumer may get gc'd BEFORE the delivery is acked
-//
-//      MessageReference ref;
-//
-//      Queue dlq;
-//
-//      Queue expiryQueue;
-//
-//      long redeliveryDelay;
-//
-//      int maxDeliveryAttempts;
-//
-//      WeakReference consumerRef;
-//
-//      String queueName;
-//
-//      long deliveryID;
-//
-//      ServerConsumerEndpoint getConsumer()
-//      {
-//      	if (consumerRef != null)
-//      	{
-//      		return (ServerConsumerEndpoint)consumerRef.get();
-//      	}
-//      	else
-//      	{
-//      		return null;
-//      	}
-//      }
-//
-//      private DeliveryRecord(MessageReference ref, Queue dlq, Queue expiryQueue, long redeliveryDelay, int maxDeliveryAttempts,
-//      		                 String queueName, long deliveryID)
-//      {
-//      	this.ref = ref;
-//
-//      	this.dlq = dlq;
-//
-//      	this.expiryQueue = expiryQueue;
-//
-//      	this.redeliveryDelay = redeliveryDelay;
-//
-//      	this.maxDeliveryAttempts = maxDeliveryAttempts;
-//
-//      	this.queueName = queueName;
-//
-//      	this.deliveryID = deliveryID;
-//      }
-//
-//      DeliveryRecord(MessageReference ref, ServerConsumerEndpoint consumer, long deliveryID)
-//      {
-//      	this (ref, consumer.getDLQ(), consumer.getExpiryQueue(), consumer.getRedliveryDelay(), consumer.getMaxDeliveryAttempts(),
-//      			consumer.getQueueName(), deliveryID);
-//
-//      	// We need to cache the attributes here  since the consumer may get gc'd BEFORE the delivery is acked
-//
-//
-//         //We hold a WeakReference to the consumer - this is only needed when replicating - where we store the delivery then wait
-//         //for the response to come back from the replicant before actually performing delivery
-//         //We need a weak ref since when the consumer closes deliveries may still and remain and we don't want that to prevent
-//         //the consumer being gc'd
-//
-//      	//FIXME - do we still need this??
-//         this.consumerRef = new WeakReference(consumer);
-//      }
-//
-//   	public String toString()
-//   	{
-//   		return "DeliveryRecord " + System.identityHashCode(this) + " ref: " + ref + " queueName: " + queueName;
-//   	}
-//   }
-
-//   /**
-//    *
-//    * The purpose of this class is to remove deliveries from the delivery list on commit
-//    * Each transaction has once instance of this per SCE
-//    *
-//    */
-//   private class DeliveryCallback implements TransactionSynchronization
-//   {
-//      private long deliveryId;
-//
-//      DeliveryCallback(long deliveryId)
-//      {
-//         this.deliveryId = deliveryId;
-//      }
-//
-//      public void afterCommit() throws Exception
-//      {
-//         //deliveries.remove(deliveryId);
-//      }
-//
-//      public void afterRollback() throws Exception
-//      {
-//       //One phase rollbacks never hit the server - they are dealt with locally only
-//         //so this would only ever be executed for a two phase rollback.
-//
-//         //We don't do anything since cancellation is driven from the client.
-//      }
-//
-//      public void beforeCommit() throws Exception
-//      {
-//      }
-//
-//      public void beforeRollback() throws Exception
-//      {
-//      }
-//   }
-//
-         
    public PacketHandler newHandler()
    {
       return new SessionAdvisedPacketHandler();
    }
 
+   
+   // Inner classes --------------------------------------------------------------------------------   
 
-   // INNER CLASSES
-
    private class SessionAdvisedPacketHandler implements PacketHandler
    {
       public SessionAdvisedPacketHandler()
@@ -1501,6 +1732,8 @@
             Packet response = null;
 
             PacketType type = packet.getType();
+            
+            //TODO use a switch for this
             if (type == MSG_SENDMESSAGE)
             {
                SessionSendMessage message = (SessionSendMessage) packet;
@@ -1575,6 +1808,74 @@
                SessionCancelMessage message = (SessionCancelMessage)packet;
                cancel(message.getDeliveryID(), message.isExpired());
             }
+            else if (type == PacketType.MSG_XA_COMMIT)
+            {
+               SessionXACommitMessage message = (SessionXACommitMessage)packet;
+               
+               response = XACommit(message.isOnePhase(), message.getXid());
+            }
+            else if (type == PacketType.MSG_XA_END)
+            { 
+               SessionXAEndMessage message = (SessionXAEndMessage)packet;
+               
+               response = XAEnd(message.getXid(), message.isFailed());
+            }
+            else if (type == PacketType.MSG_XA_FORGET)
+            {
+               SessionXAForgetMessage message = (SessionXAForgetMessage)packet;
+               
+               response = XAForget(message.getXid());
+            }
+            else if (type == PacketType.MSG_XA_JOIN)
+            {
+               SessionXAJoinMessage message = (SessionXAJoinMessage)packet;
+               
+               response = XAJoin(message.getXid());
+            }
+            else if (type == PacketType.MSG_XA_RESUME)
+            {
+               SessionXAResumeMessage message = (SessionXAResumeMessage)packet;
+               
+               response = XAResume(message.getXid());
+            }
+            else if (type == PacketType.MSG_XA_ROLLBACK)
+            {
+               SessionXARollbackMessage message = (SessionXARollbackMessage)packet;
+               
+               response = XARollback(message.getXid());
+            }
+            else if (type == PacketType.MSG_XA_START)
+            {
+               SessionXAStartMessage message = (SessionXAStartMessage)packet;
+               
+               response = XAStart(message.getXid());
+            }
+            else if (type == PacketType.MSG_XA_SUSPEND)
+            {
+               response = XASuspend();
+            }   
+            else if (type == PacketType.REQ_XA_PREPARE)
+            {
+               SessionXAPrepareMessage message = (SessionXAPrepareMessage)packet;
+               
+               response = XAPrepare(message.getXid());
+            }
+            else if (type == PacketType.REQ_XA_INDOUBT_XIDS)
+            {
+               List<Xid> xids = getInDoubtXids();
+               
+               response = new SessionXAGetInDoubtXidsResponse(xids);
+            }
+            else if (type == PacketType.MSG_XA_GET_TIMEOUT)
+            {
+               response = new SessionXAGetTimeoutResponse(getXATimeout());
+            }
+            else if (type == PacketType.MSG_XA_SET_TIMEOUT)
+            {
+               SessionXASetTimeoutMessage message = (SessionXASetTimeoutMessage)packet;
+               
+               response = new SessionXASetTimeoutResponse(setXATimeout(message.getTimeoutSeconds()));
+            }
             else
             {
                response = new JMSExceptionMessage(new MessagingJMSException(
@@ -1606,5 +1907,7 @@
          return "SessionAdvisedPacketHandler[id=" + id + "]";
       }
    }
+   
+   
 
 }

Modified: trunk/src/main/org/jboss/messaging/core/MessagingServer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/MessagingServer.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/MessagingServer.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -96,6 +96,8 @@
    void setJmsUserManager(JMSUserManager jmsUserManager);
 
    PostOffice getPostOffice();
+   
+   ResourceManager getResourceManager();
 
    HierarchicalRepository<HashSet<Role>> getSecurityRepository();
 

Added: trunk/src/main/org/jboss/messaging/core/ResourceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/ResourceManager.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/ResourceManager.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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 org.jboss.messaging.core;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * 
+ * A ResourceManager
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface ResourceManager
+{
+   boolean putTransaction(Xid xid, Transaction tx);
+   
+   Transaction getTransaction(Xid xid);
+   
+   boolean removeTransaction(Xid xid);
+   
+   int getTimeoutSeconds();
+   
+   boolean setTimeoutSeconds(int timeoutSeconds);
+}

Modified: trunk/src/main/org/jboss/messaging/core/Transaction.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/Transaction.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/Transaction.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -21,8 +21,10 @@
  */
 package org.jboss.messaging.core;
 
+import javax.transaction.xa.Xid;
 
 
+
 /**
  * 
  * A JBoss Messaging internal transaction
@@ -36,7 +38,7 @@
    
    void prepare(PersistenceManager persistenceManager) throws Exception;
    
-   void commit(PersistenceManager persistenceManager) throws Exception;
+   void commit(boolean onePhase, PersistenceManager persistenceManager) throws Exception;
    
    void rollback(PersistenceManager persistenceManager) throws Exception;   
    
@@ -45,4 +47,14 @@
    void addAcknowledgement(MessageReference acknowledgement);   
    
    int getAcknowledgementsCount();
+   
+   Xid getXid();
+   
+   boolean isEmpty();
+   
+   void suspend();
+   
+   void resume();
+   
+   boolean isSuspended();
 }

Deleted: trunk/src/main/org/jboss/messaging/core/TransactionStore.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/TransactionStore.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/TransactionStore.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -1,36 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * 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 org.jboss.messaging.core;
-
-/**
- * 
- * A TransactionStore
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public interface TransactionStore extends MessagingComponent
-{
-   Transaction getTransaction(Object id);
-   
-   void putTransaction(Transaction tx);      
-}

Modified: trunk/src/main/org/jboss/messaging/core/impl/BindingImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/BindingImpl.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/impl/BindingImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -79,6 +79,10 @@
      
    public boolean equals(Object other)
    {
+      if (this == other)
+      {
+         return true;
+      }
       Binding bother = (Binding)other;
       
       return (this.nodeID == bother.getNodeID()) && (this.allNodes == bother.isAllNodes()) &&

Modified: trunk/src/main/org/jboss/messaging/core/impl/ConditionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/ConditionImpl.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/impl/ConditionImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -67,6 +67,11 @@
    
    public boolean equals(Object other)
    {
+      if (this == other)
+      {
+         return true;
+      }
+      
       Condition cond = (Condition)other;
 
       return ((cond.getType() == this.type) && (cond.getKey().equals(this.key)));

Modified: trunk/src/main/org/jboss/messaging/core/impl/DestinationImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/DestinationImpl.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/impl/DestinationImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -101,6 +101,11 @@
    
    public boolean equals(Object other)
    {
+      if (this == other)
+      {
+         return true;
+      }
+      
       Destination dother = (Destination)other;
       
       return dother.getType() == this.type && dother.getName().equals(this.name) &&

Modified: trunk/src/main/org/jboss/messaging/core/impl/QueueImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/QueueImpl.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/impl/QueueImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -382,6 +382,11 @@
               
    public boolean equals(Object other)
    {
+      if (this == other)
+      {
+         return true;
+      }
+      
       QueueImpl qother = (QueueImpl)other;
       
       return name.equals(qother.name);

Added: trunk/src/main/org/jboss/messaging/core/impl/ResourceManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/ResourceManagerImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/impl/ResourceManagerImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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 org.jboss.messaging.core.impl;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.ResourceManager;
+import org.jboss.messaging.core.Transaction;
+
+/**
+ * 
+ * A ResourceManagerImpl
+ * 
+ * TODO - implement timeouts
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class ResourceManagerImpl implements ResourceManager
+{
+   private ConcurrentMap<Xid, Transaction> transactions = new ConcurrentHashMap<Xid, Transaction>();
+   
+   private int defaultTimeoutSeconds;
+   
+   private int timeoutSeconds;
+   
+   public ResourceManagerImpl(int defaultTimeoutSeconds)
+   {      
+      this.defaultTimeoutSeconds = defaultTimeoutSeconds;
+   }
+   
+   // ResourceManager implementation ---------------------------------------------
+   
+   public Transaction getTransaction(Xid xid)
+   {
+      return transactions.get(xid);
+   }
+
+   public boolean putTransaction(Xid xid, Transaction tx)
+   {
+      return transactions.putIfAbsent(xid, tx) == null;
+   }
+
+   public boolean removeTransaction(Xid xid)
+   {
+      return transactions.remove(xid) != null;
+   }
+   
+   public int getTimeoutSeconds()
+   {
+      return this.timeoutSeconds;
+   }
+   
+   public boolean setTimeoutSeconds(int timeoutSeconds)
+   {
+      if (timeoutSeconds == 0)
+      {
+         //reset to default
+         timeoutSeconds = defaultTimeoutSeconds;
+      }
+      else
+      {
+         this.timeoutSeconds = timeoutSeconds;
+      }      
+      
+      return true;
+   }
+}

Modified: trunk/src/main/org/jboss/messaging/core/impl/TransactionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/TransactionImpl.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/impl/TransactionImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -58,8 +58,10 @@
    
    private boolean containsPersistent;
    
-   private boolean prepared;
+   private volatile boolean prepared;
    
+   private volatile boolean suspended;
+   
    public TransactionImpl()
    {            
    }
@@ -90,8 +92,7 @@
          containsPersistent = true;
       }
    }
-   
-   
+      
    public void addSynchronization(TransactionSynchronization sync)
    {
       synchronizations.add(sync);
@@ -106,18 +107,18 @@
       else if (containsPersistent)
       {
          persistenceManager.prepareTransaction(xid, messagesToAdd, acknowledgements);
-         
-         prepared = true;
       }
+            
+      prepared = true;
    }
    
-   public void commit(PersistenceManager persistenceManager) throws Exception
+   public void commit(boolean onePhase, PersistenceManager persistenceManager) throws Exception
    {
       callSynchronizations(SyncType.BEFORE_COMMIT);
       
       if (containsPersistent)
       {
-         if (xid == null)
+         if (xid == null || onePhase)
          {
             //1PC commit
             
@@ -155,7 +156,7 @@
    {
       callSynchronizations(SyncType.BEFORE_ROLLBACK);
         
-      if (xid != null && containsPersistent)
+      if (prepared)
       {
          persistenceManager.unprepareTransaction(xid, messagesToAdd, acknowledgements);             
       }
@@ -172,6 +173,31 @@
       return acknowledgements.size();
    }
    
+   public void suspend()
+   {
+      suspended = true;
+   }
+   
+   public void resume()
+   {
+      suspended = false;
+   }
+   
+   public boolean isSuspended()
+   {
+      return suspended;
+   }
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+   
+   public boolean isEmpty()
+   {
+      return messagesToAdd.isEmpty() && acknowledgements.isEmpty();
+   }
+   
    // Private -------------------------------------------------------------------
    
    private void callSynchronizations(SyncType type) throws Exception

Added: trunk/src/main/org/jboss/messaging/core/impl/XidImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/XidImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/impl/XidImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,204 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * 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 org.jboss.messaging.core.impl;
+
+import java.io.Serializable;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * 
+ * Xid implementation
+ * 
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
+ * 
+ * @version $Revision 1.1 $
+ */
+public class XidImpl implements Xid, Serializable
+{
+   private static final long serialVersionUID = 407053232840068514L;
+
+   private byte[] branchQualifier;
+   
+   private int formatId;
+   
+   private byte[] globalTransactionId;
+   
+   private int hash;
+   
+   private boolean hashCalculated;
+   
+   /**
+    * For serialization only
+    */
+   public XidImpl()
+   {      
+   }
+   
+   /**
+    * Standard constructor
+    * @param branchQualifier
+    * @param formatId
+    * @param globalTransactionId
+    */
+   public XidImpl(byte[] branchQualifier, int formatId, byte[] globalTransactionId)
+   {
+      this.branchQualifier = branchQualifier;
+      this.formatId = formatId;
+      this.globalTransactionId = globalTransactionId;          
+   }
+   
+   /**
+    * Copy constructor
+    * @param other
+    */
+   public XidImpl(Xid other)
+   {
+      this.branchQualifier = copyBytes(other.getBranchQualifier());
+      this.formatId = other.getFormatId();
+      this.globalTransactionId = copyBytes(other.getGlobalTransactionId());
+   }
+
+   // Xid implementation ------------------------------------------------------------------
+   
+   public byte[] getBranchQualifier()
+   {
+      return branchQualifier;
+   }
+
+   public int getFormatId()
+   {
+      return formatId;
+   }
+
+   public byte[] getGlobalTransactionId()
+   {
+      return globalTransactionId;
+   }
+   
+   // Public -------------------------------------------------------------------------------
+            
+   public int hashCode()
+   {
+      if (!hashCalculated)
+      {
+         calcHash();
+      }
+      return hash;
+   }
+   
+   public boolean equals(Object other)
+   {
+      if (this == other)
+      {
+         return true;
+      }
+      if (!(other instanceof Xid))
+      {
+         return false;
+      }
+      Xid xother = (Xid)other;
+      if (xother.getFormatId() != formatId)
+      {
+         return false;
+      }
+      if (xother.getBranchQualifier().length != this.branchQualifier.length)
+      {
+         return false;
+      }
+      if (xother.getGlobalTransactionId().length != this.globalTransactionId.length)
+      {
+         return false;
+      }
+      for (int i = 0; i < this.branchQualifier.length; i++)
+      {
+         byte[] otherBQ = xother.getBranchQualifier();
+         if (this.branchQualifier[i] != otherBQ[i])
+         {
+            return false;
+         }         
+      }
+      for (int i = 0; i < this.globalTransactionId.length; i++)
+      {
+         byte[] otherGtx = xother.getGlobalTransactionId();
+         if (this.globalTransactionId[i] != otherGtx[i])
+         {
+            return false;
+         }
+      }
+      return true;
+   }
+
+   public String toString()
+   {
+     	return "XidImpl (" + System.identityHashCode(this) + " bq:" + stringRep(branchQualifier) +
+     	" formatID:" + formatId + " gtxid:" + stringRep(globalTransactionId);
+   }
+   
+   // Private -------------------------------------------------------------------------------
+   
+   private String stringRep(byte[] bytes)
+   {
+      StringBuffer buff = new StringBuffer();
+      for (int i = 0; i < bytes.length; i++)
+      {
+         byte b = bytes[i];
+         
+         buff.append(b);
+         
+         if (i != bytes.length - 1)
+         {
+            buff.append('.');
+         }
+      }
+      
+      return buff.toString();
+   }
+   
+   private void calcHash()
+   {
+      byte[] hashBytes = new byte[branchQualifier.length + globalTransactionId.length + 4];
+      System.arraycopy(branchQualifier, 0, hashBytes, 0, branchQualifier.length);
+      System.arraycopy(globalTransactionId, 0, hashBytes, branchQualifier.length, globalTransactionId.length);
+      byte[] intBytes = new byte[4];
+      for (int i = 0; i < 4; i++)
+      {
+         intBytes[i] = (byte)((formatId >> (i * 8)) % 0xFF);
+      }
+      System.arraycopy(intBytes, 0, hashBytes, branchQualifier.length + globalTransactionId.length, 4);
+      String s = new String(hashBytes);
+      hash = s.hashCode();
+      hashCalculated = true;
+   }
+   
+   private byte[] copyBytes(byte[] other)
+   {
+      byte[] bytes = new byte[other.length];
+      
+      System.arraycopy(other, 0, bytes, 0, other.length);
+      
+      return bytes;
+   }
+
+}

Modified: trunk/src/main/org/jboss/messaging/core/impl/filter/FilterImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/filter/FilterImpl.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/impl/filter/FilterImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -31,8 +31,19 @@
 /**
 * This class implements a JBoss Messaging filter
 * 
-* @author     <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
 * 
+* JBM filters have the same syntax as JMS 1.1 selectors, but the identifiers are different.
+* 
+* Valid identifiers that can be used are:
+* 
+* JBMessageID - the message id of the message
+* JBMPriority - the priority of the message
+* JBMTimestamp - the timestamp of the message
+* JBMDurable - "DURABLE" or "NON_DURABLE"
+* JBMExpiration - the expiration of the message
+* Any other identifers that appear in a filter expression represent header values for the message
+* 
 * Derived from JBoss MQ version by
 * 
 * @author <a href="mailto:Norbert.Lataille at m4x.org">Norbert Lataille</a>

Modified: trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerImpl.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -37,22 +37,35 @@
 import org.jboss.jms.server.connectionmanager.SimpleConnectionManager;
 import org.jboss.jms.server.endpoint.ConnectionFactoryAdvisedPacketHandler;
 import org.jboss.jms.server.endpoint.ServerSessionEndpoint;
+import org.jboss.jms.server.plugin.NullUserManager;
 import org.jboss.jms.server.plugin.contract.JMSUserManager;
-import org.jboss.jms.server.plugin.NullUserManager;
+import org.jboss.jms.server.security.NullAuthenticationManager;
 import org.jboss.jms.server.security.Role;
 import org.jboss.jms.server.security.SecurityMetadataStore;
-import org.jboss.jms.server.security.NullAuthenticationManager;
 import org.jboss.logging.Logger;
-import org.jboss.messaging.core.*;
+import org.jboss.messaging.core.Binding;
+import org.jboss.messaging.core.Condition;
+import org.jboss.messaging.core.Configuration;
+import org.jboss.messaging.core.DestinationType;
+import org.jboss.messaging.core.MemoryManager;
+import org.jboss.messaging.core.MessagingServer;
+import org.jboss.messaging.core.NullPersistenceManager;
+import org.jboss.messaging.core.PersistenceManager;
+import org.jboss.messaging.core.PostOffice;
+import org.jboss.messaging.core.Queue;
+import org.jboss.messaging.core.QueueFactory;
+import org.jboss.messaging.core.QueueSettings;
+import org.jboss.messaging.core.ResourceManager;
 import org.jboss.messaging.core.impl.ConditionImpl;
 import org.jboss.messaging.core.impl.QueueFactoryImpl;
+import org.jboss.messaging.core.impl.ResourceManagerImpl;
 import org.jboss.messaging.core.impl.memory.SimpleMemoryManager;
 import org.jboss.messaging.core.impl.messagecounter.MessageCounterManager;
 import org.jboss.messaging.core.impl.postoffice.PostOfficeImpl;
 import org.jboss.messaging.core.remoting.Interceptor;
+import org.jboss.messaging.core.remoting.RemotingConfiguration;
+import org.jboss.messaging.core.remoting.RemotingService;
 import org.jboss.messaging.core.remoting.impl.mina.MinaService;
-import org.jboss.messaging.core.remoting.RemotingService;
-import org.jboss.messaging.core.remoting.RemotingConfiguration;
 import org.jboss.messaging.deployers.queue.QueueSettingsDeployer;
 import org.jboss.messaging.deployers.security.SecurityDeployer;
 import org.jboss.messaging.util.ExceptionUtil;
@@ -116,7 +129,8 @@
    private Configuration configuration = new Configuration();
    private HierarchicalRepository<HashSet<Role>> securityRepository = new HierarchicalObjectRepository<HashSet<Role>>();
    private HierarchicalRepository<QueueSettings> queueSettingsRepository = new HierarchicalObjectRepository<QueueSettings>();
-   private QueueFactoryImpl queueFactory = new QueueFactoryImpl();
+   private QueueFactory queueFactory = new QueueFactoryImpl();
+   private ResourceManager resourceManager = new ResourceManagerImpl(0);
 
    // Constructors ---------------------------------------------------------------------------------
    /**
@@ -497,8 +511,12 @@
    {
       this.postOffice = postOffice;
    }
+   
+   public ResourceManager getResourceManager()
+   {
+      return resourceManager;
+   }
 
-
    public HierarchicalRepository<HashSet<Role>> getSecurityRepository()
    {
       return securityRepository;

Modified: trunk/src/main/org/jboss/messaging/core/remoting/codec/AbstractPacketCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/AbstractPacketCodec.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/AbstractPacketCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -17,11 +17,14 @@
 import java.io.DataOutputStream;
 import java.nio.charset.CharacterCodingException;
 
+import javax.transaction.xa.Xid;
+
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.messaging.core.Destination;
 import org.jboss.messaging.core.Message;
 import org.jboss.messaging.core.impl.DestinationImpl;
 import org.jboss.messaging.core.impl.MessageImpl;
+import org.jboss.messaging.core.impl.XidImpl;
 import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
 import org.jboss.messaging.core.remoting.wireformat.PacketType;
 import org.jboss.messaging.util.Logger;
@@ -45,8 +48,7 @@
 
    public static final int LONG_LENGTH = 8;
 
-   private static final Logger log = Logger
-         .getLogger(AbstractPacketCodec.class);
+   private static final Logger log = Logger.getLogger(AbstractPacketCodec.class);
 
    // Attributes ----------------------------------------------------
 
@@ -139,6 +141,11 @@
          // NULL_BYTE
       }
    }
+   
+   public static int getXidLength(Xid xid)
+   {
+      return 1 + 1 + xid.getBranchQualifier().length + 1 + xid.getGlobalTransactionId().length;
+   }
 
    // MessageDecoder implementation ---------------------------------
 
@@ -230,8 +237,8 @@
       packet.setOneWay(oneWay);
 
       return packet;
-   }
-
+   }   
+   
    // Protected -----------------------------------------------------
 
    protected abstract void encodeBody(P packet, RemotingBuffer buf)
@@ -266,6 +273,28 @@
       msg.read(new DataInputStream(bais));
       return msg;
    }
+   
+   protected static void encodeXid(Xid xid, RemotingBuffer out)
+   {
+      out.putInt(xid.getFormatId());
+      out.putInt(xid.getBranchQualifier().length);
+      out.put(xid.getBranchQualifier());
+      out.putInt(xid.getGlobalTransactionId().length);
+      out.put(xid.getGlobalTransactionId());
+   }
+   
+   protected static Xid decodeXid(RemotingBuffer in)
+   {
+      int formatID = in.getInt();
+      byte[] bq = new byte[in.getInt()];
+      in.get(bq);
+      byte[] gtxid = new byte[in.getInt()];
+      in.get(gtxid);      
+      Xid xid = new XidImpl(bq, formatID, gtxid);      
+      return xid;
+   }
+   
+   
 
    // Private -------------------------------------------------------
 

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXACommitMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXACommitMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXACommitMessageCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXACommitMessage;
+
+/**
+ * 
+ * A SessionXACommitMessageCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXACommitMessageCodec extends AbstractPacketCodec<SessionXACommitMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXACommitMessageCodec()
+   {
+      super(PacketType.MSG_XA_COMMIT);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXACommitMessage message, RemotingBuffer out) throws Exception
+   {      
+      Xid xid = message.getXid();
+      
+      int bodyLength = 1 + getXidLength(xid);
+      
+      out.putInt(bodyLength);
+      
+      out.putBoolean(message.isOnePhase());
+      
+      encodeXid(xid, out);      
+   }
+
+   @Override
+   protected SessionXACommitMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      boolean onePhase = in.getBoolean();
+            
+      Xid xid = decodeXid(in);
+            
+      return new SessionXACommitMessage(xid, onePhase);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAEndMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAEndMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAEndMessageCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAEndMessage;
+
+/**
+ * 
+ * A SessionXAEndMessageCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXAEndMessageCodec extends AbstractPacketCodec<SessionXAEndMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAEndMessageCodec()
+   {
+      super(PacketType.MSG_XA_END);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXAEndMessage message, RemotingBuffer out) throws Exception
+   {      
+      Xid xid = message.getXid();      
+      
+      int bodyLength = 1 + getXidLength(xid);
+      
+      out.putInt(bodyLength);
+      
+      out.putBoolean(message.isFailed());
+      
+      encodeXid(xid, out);            
+   }
+
+   @Override
+   protected SessionXAEndMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      boolean failed = in.getBoolean();
+                  
+      Xid xid = decodeXid(in);
+            
+      return new SessionXAEndMessage(xid, failed);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAForgetMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAForgetMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAForgetMessageCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAForgetMessage;
+
+/**
+ * 
+ * A SessionXAEndMessageCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXAForgetMessageCodec extends AbstractPacketCodec<SessionXAForgetMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAForgetMessageCodec()
+   {
+      super(PacketType.MSG_XA_FORGET);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXAForgetMessage message, RemotingBuffer out) throws Exception
+   {      
+      Xid xid = message.getXid();
+      
+      int bodyLength = getXidLength(xid);
+      
+      out.putInt(bodyLength);
+      
+      encodeXid(xid, out);
+   }
+
+   @Override
+   protected SessionXAForgetMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      Xid xid = decodeXid(in);
+      
+      return new SessionXAForgetMessage(xid);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAGetInDoubtXidsResponseCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAGetInDoubtXidsResponseCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAGetInDoubtXidsResponseCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsResponse;
+
+
+/**
+ * 
+ * A SessionXAGetInDoubtXidsResponseCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXAGetInDoubtXidsResponseCodec extends AbstractPacketCodec<SessionXAGetInDoubtXidsResponse>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAGetInDoubtXidsResponseCodec()
+   {
+      super(PacketType.REQ_XA_INDOUBT_XIDS);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXAGetInDoubtXidsResponse message, RemotingBuffer out) throws Exception
+   {      
+      int bodyLength = 1;
+      
+      for (Xid xid: message.getXids())
+      {
+         bodyLength += getXidLength(xid);
+      }
+       
+      out.putInt(bodyLength);
+      
+      out.putInt(message.getXids().size());
+      
+      for (Xid xid: message.getXids())
+      {
+        encodeXid(xid, out);
+      }
+      
+   }
+
+   @Override
+   protected SessionXAGetInDoubtXidsResponse decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      int size = in.getInt();
+      
+      List<Xid> xids = new ArrayList<Xid>(size);
+      
+      for (int i = 0; i < size; i++)
+      {
+         Xid xid = decodeXid(in);
+         
+         xids.add(xid);
+      }
+      
+      return new SessionXAGetInDoubtXidsResponse(xids);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAGetTimeoutResponseCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAGetTimeoutResponseCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAGetTimeoutResponseCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutResponse;
+
+
+/**
+ * 
+ * A SessionXAGetTimeoutResponseCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXAGetTimeoutResponseCodec extends AbstractPacketCodec<SessionXAGetTimeoutResponse>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAGetTimeoutResponseCodec()
+   {
+      super(PacketType.MSG_XA_GET_TIMEOUT_RESPONSE);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXAGetTimeoutResponse message, RemotingBuffer out) throws Exception
+   {      
+      int bodyLength = INT_LENGTH;
+      
+      out.putInt(bodyLength);
+      
+      out.putInt(message.getTimeoutSeconds());
+   }
+
+   @Override
+   protected SessionXAGetTimeoutResponse decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      int timeout = in.getInt();
+      
+      return new SessionXAGetTimeoutResponse(timeout);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAJoinMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAJoinMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAJoinMessageCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAJoinMessage;
+
+/**
+ * 
+ * A SessionXACommitMessageCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXAJoinMessageCodec extends AbstractPacketCodec<SessionXAJoinMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAJoinMessageCodec()
+   {
+      super(PacketType.MSG_XA_JOIN);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXAJoinMessage message, RemotingBuffer out) throws Exception
+   {      
+      Xid xid = message.getXid();
+      
+      int bodyLength = getXidLength(xid);
+      
+      out.putInt(bodyLength);
+      
+      encodeXid(xid, out);
+   }
+
+   @Override
+   protected SessionXAJoinMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      Xid xid = decodeXid(in);
+      
+      return new SessionXAJoinMessage(xid);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAPrepareMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAPrepareMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAPrepareMessageCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAPrepareMessage;
+
+/**
+ * 
+ * A SessionXACommitMessageCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXAPrepareMessageCodec extends AbstractPacketCodec<SessionXAPrepareMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAPrepareMessageCodec()
+   {
+      super(PacketType.REQ_XA_PREPARE);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXAPrepareMessage message, RemotingBuffer out) throws Exception
+   {      
+      Xid xid = message.getXid();
+      
+      int bodyLength = getXidLength(xid);
+      
+      out.putInt(bodyLength);
+      
+      encodeXid(xid, out);
+   }
+
+   @Override
+   protected SessionXAPrepareMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      Xid xid = decodeXid(in);
+      
+      return new SessionXAPrepareMessage(xid);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAResponseCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAResponseCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAResponseCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResponse;
+
+
+/**
+ * 
+ * A SessionXAResponseCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXAResponseCodec extends AbstractPacketCodec<SessionXAResponse>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAResponseCodec()
+   {
+      super(PacketType.RESP_XA);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXAResponse message, RemotingBuffer out) throws Exception
+   {      
+      int bodyLength = 1 + INT_LENGTH + sizeof(message.getMessage());
+      
+      out.putInt(bodyLength);
+      
+      out.putBoolean(message.isError());
+      
+      out.putInt(message.getResponseCode());
+      
+      out.putNullableString(message.getMessage());
+   }
+
+   @Override
+   protected SessionXAResponse decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      boolean isError = in.getBoolean();
+      
+      int responseCode = in.getInt();
+      
+      String message = in.getNullableString();
+      
+      return new SessionXAResponse(isError, responseCode, message);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAResumeMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAResumeMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAResumeMessageCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResumeMessage;
+
+/**
+ * 
+ * A SessionXAResumeMessageCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXAResumeMessageCodec extends AbstractPacketCodec<SessionXAResumeMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAResumeMessageCodec()
+   {
+      super(PacketType.MSG_XA_RESUME);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXAResumeMessage message, RemotingBuffer out) throws Exception
+   {      
+      Xid xid = message.getXid();
+      
+      int bodyLength = getXidLength(xid);
+      
+      out.putInt(bodyLength);
+      
+      encodeXid(xid, out);
+   }
+
+   @Override
+   protected SessionXAResumeMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      Xid xid = decodeXid(in);
+      
+      return new SessionXAResumeMessage(xid);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXARollbackMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXARollbackMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXARollbackMessageCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXARollbackMessage;
+
+public class SessionXARollbackMessageCodec extends AbstractPacketCodec<SessionXARollbackMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXARollbackMessageCodec()
+   {
+      super(PacketType.MSG_XA_ROLLBACK);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXARollbackMessage message, RemotingBuffer out) throws Exception
+   {      
+      Xid xid = message.getXid();
+      
+      int bodyLength = getXidLength(xid);
+      
+      out.putInt(bodyLength);
+      
+      encodeXid(xid, out);
+   }
+
+   @Override
+   protected SessionXARollbackMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      Xid xid = decodeXid(in);
+      
+      return new SessionXARollbackMessage(xid);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXASetTimeoutMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXASetTimeoutMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXASetTimeoutMessageCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutMessage;
+
+/**
+ * 
+ * A SessionXASetTimeoutMessageCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXASetTimeoutMessageCodec extends AbstractPacketCodec<SessionXASetTimeoutMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXASetTimeoutMessageCodec()
+   {
+      super(PacketType.MSG_XA_SET_TIMEOUT);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXASetTimeoutMessage message, RemotingBuffer out) throws Exception
+   {                 
+      int bodyLength = INT_LENGTH;
+      
+      out.putInt(bodyLength);
+      
+      out.putInt(message.getTimeoutSeconds());
+   }
+
+   @Override
+   protected SessionXASetTimeoutMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      int timeout = in.getInt();
+      
+      return new SessionXASetTimeoutMessage(timeout);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXASetTimeoutResponseCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXASetTimeoutResponseCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXASetTimeoutResponseCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutResponse;
+
+/**
+ * 
+ * A SessionXASetTimeoutResponseCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXASetTimeoutResponseCodec extends AbstractPacketCodec<SessionXASetTimeoutResponse>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXASetTimeoutResponseCodec()
+   {
+      super(PacketType.MSG_XA_SET_TIMEOUT_RESPONSE);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXASetTimeoutResponse message, RemotingBuffer out) throws Exception
+   {                 
+      int bodyLength = 1;
+      
+      out.putInt(bodyLength);
+      
+      out.putBoolean(message.isOK());
+   }
+
+   @Override
+   protected SessionXASetTimeoutResponse decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+      
+      boolean ok = in.getBoolean();
+      
+      return new SessionXASetTimeoutResponse(ok);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAStartMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAStartMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionXAStartMessageCodec.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAStartMessage;
+
+/**
+ * 
+ * A SessionXAStartMessageCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SessionXAStartMessageCodec extends AbstractPacketCodec<SessionXAStartMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAStartMessageCodec()
+   {
+      super(PacketType.MSG_XA_START);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(SessionXAStartMessage message, RemotingBuffer out) throws Exception
+   {      
+      Xid xid = message.getXid();      
+      
+      int bodyLength = getXidLength(xid);
+      
+      out.putInt(bodyLength);
+      
+      encodeXid(xid, out);
+   }
+
+   @Override
+   protected SessionXAStartMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+            
+      Xid xid = decodeXid(in);
+      
+      return new SessionXAStartMessage(xid);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -37,6 +37,19 @@
 import org.jboss.messaging.core.remoting.codec.SessionAcknowledgeMessageCodec;
 import org.jboss.messaging.core.remoting.codec.SessionCancelMessageCodec;
 import org.jboss.messaging.core.remoting.codec.SessionSendMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXACommitMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAEndMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAForgetMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAGetInDoubtXidsResponseCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAGetTimeoutResponseCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAJoinMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAPrepareMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAResponseCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAResumeMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXARollbackMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXASetTimeoutMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXASetTimeoutResponseCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAStartMessageCodec;
 import org.jboss.messaging.core.remoting.codec.SetClientIDMessageCodec;
 import org.jboss.messaging.core.remoting.codec.SetSessionIDMessageCodec;
 import org.jboss.messaging.core.remoting.codec.TextPacketCodec;
@@ -79,6 +92,22 @@
 import org.jboss.messaging.core.remoting.wireformat.SessionRecoverMessage;
 import org.jboss.messaging.core.remoting.wireformat.SessionRollbackMessage;
 import org.jboss.messaging.core.remoting.wireformat.SessionSendMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXACommitMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAEndMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAForgetMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsRequest;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAJoinMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAPrepareMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResumeMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXARollbackMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAStartMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASuspendMessage;
 import org.jboss.messaging.core.remoting.wireformat.SetClientIDMessage;
 import org.jboss.messaging.core.remoting.wireformat.SetSessionIDMessage;
 import org.jboss.messaging.core.remoting.wireformat.StartConnectionMessage;
@@ -175,8 +204,7 @@
       addCodecForEmptyPacket(PacketType.MSG_CLOSING, ClosingMessage.class);
       
       addCodecForEmptyPacket(PacketType.MSG_RECOVER, SessionRecoverMessage.class);
-      
-      
+            
       addCodecForEmptyPacket(PacketType.MSG_BROWSER_RESET,
             BrowserResetMessage.class);
 
@@ -205,6 +233,39 @@
 
       addCodec(DeleteTemporaryDestinationMessage.class,
             DeleteTemporaryDestinationMessageCodec.class);
+      
+      addCodec(SessionXACommitMessage.class, SessionXACommitMessageCodec.class);
+      
+      addCodec(SessionXAEndMessage.class, SessionXAEndMessageCodec.class);
+      
+      addCodec(SessionXAForgetMessage.class, SessionXAForgetMessageCodec.class);
+      
+      addCodecForEmptyPacket(PacketType.REQ_XA_INDOUBT_XIDS,
+            SessionXAGetInDoubtXidsRequest.class);
+      
+      addCodec(SessionXAGetInDoubtXidsResponse.class, SessionXAGetInDoubtXidsResponseCodec.class);
+      
+      addCodecForEmptyPacket(PacketType.MSG_XA_GET_TIMEOUT, SessionXAGetTimeoutMessage.class);
+      
+      addCodec(SessionXAGetTimeoutResponse.class, SessionXAGetTimeoutResponseCodec.class);
+      
+      addCodec(SessionXAJoinMessage.class, SessionXAJoinMessageCodec.class);
+      
+      addCodec(SessionXAPrepareMessage.class, SessionXAPrepareMessageCodec.class);
+      
+      addCodec(SessionXAResponse.class, SessionXAResponseCodec.class);
+      
+      addCodec(SessionXAResumeMessage.class, SessionXAResumeMessageCodec.class);
+      
+      addCodec(SessionXARollbackMessage.class, SessionXARollbackMessageCodec.class);
+      
+      addCodec(SessionXASetTimeoutMessage.class, SessionXASetTimeoutMessageCodec.class);
+      
+      addCodec(SessionXASetTimeoutResponse.class, SessionXASetTimeoutResponseCodec.class);
+      
+      addCodec(SessionXAStartMessage.class, SessionXAStartMessageCodec.class);
+      
+      addCodecForEmptyPacket(PacketType.MSG_XA_SUSPEND, SessionXASuspendMessage.class);
    }
 
    // Public --------------------------------------------------------

Modified: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/PacketType.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/PacketType.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/PacketType.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -55,25 +55,31 @@
    MSG_XA_START                   ((byte)56),
    MSG_XA_END                     ((byte)57),
    MSG_XA_COMMIT                  ((byte)58),
-   MSG_XA_PREPARE                 ((byte)59),
-   MSG_XA_ROLLBACK                ((byte)60),
-   MSG_XA_JOIN                    ((byte)61),
-   MSG_XA_RESUME                  ((byte)62),
-   MSG_XA_FORGET                  ((byte)63),
-   REQ_XA_INDOUBT_XIDS            ((byte)64),
-   RESP_XA_INDOUBT_XIDS           ((byte)65),
+   REQ_XA_PREPARE                 ((byte)59),
+   RESP_XA                        ((byte)60),
+   MSG_XA_ROLLBACK                ((byte)61),
+   MSG_XA_JOIN                    ((byte)62),
+   MSG_XA_SUSPEND                 ((byte)63),
+   MSG_XA_RESUME                  ((byte)64),
+   MSG_XA_FORGET                  ((byte)65),
+   REQ_XA_INDOUBT_XIDS            ((byte)66),
+   RESP_XA_INDOUBT_XIDS           ((byte)67),
+   MSG_XA_SET_TIMEOUT             ((byte)68),
+   MSG_XA_SET_TIMEOUT_RESPONSE    ((byte)69),
+   MSG_XA_GET_TIMEOUT             ((byte)70),
+   MSG_XA_GET_TIMEOUT_RESPONSE    ((byte)71),
    
    // ClientConsumer 
-   MSG_CHANGERATE                 ((byte)70),
+   MSG_CHANGERATE                 ((byte)80),
    
    // Browser
-   MSG_BROWSER_RESET              ((byte)80),
-   REQ_BROWSER_HASNEXTMESSAGE     ((byte)81),
-   RESP_BROWSER_HASNEXTMESSAGE    ((byte)82),
-   REQ_BROWSER_NEXTMESSAGEBLOCK   ((byte)83),
-   RESP_BROWSER_NEXTMESSAGEBLOCK  ((byte)84),
-   REQ_BROWSER_NEXTMESSAGE        ((byte)85),
-   RESP_BROWSER_NEXTMESSAGE       ((byte)86),
+   MSG_BROWSER_RESET              ((byte)90),
+   REQ_BROWSER_HASNEXTMESSAGE     ((byte)91),
+   RESP_BROWSER_HASNEXTMESSAGE    ((byte)92),
+   REQ_BROWSER_NEXTMESSAGEBLOCK   ((byte)93),
+   RESP_BROWSER_NEXTMESSAGEBLOCK  ((byte)94),
+   REQ_BROWSER_NEXTMESSAGE        ((byte)95),
+   RESP_BROWSER_NEXTMESSAGE       ((byte)96),
 
    // Misc
    MSG_CLOSING                    ((byte)90),  

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXACommitMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXACommitMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXACommitMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXACommitMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private boolean onePhase;
+   
+   private Xid xid;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXACommitMessage(Xid xid, boolean onePhase)
+   {
+      super(PacketType.MSG_XA_COMMIT);
+      
+      this.xid = xid;
+      
+      this.onePhase = onePhase;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+   
+   public boolean isOnePhase()
+   {
+      return onePhase;
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAEndMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAEndMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAEndMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAEndMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private Xid xid;
+   
+   private boolean failed;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAEndMessage(Xid xid, boolean failed)
+   {
+      super(PacketType.MSG_XA_END);
+      
+      this.xid = xid;
+      
+      this.failed = failed;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public boolean isFailed()
+   {
+      return failed;
+   }
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAForgetMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAForgetMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAForgetMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAForgetMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private Xid xid;
+      
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAForgetMessage(Xid xid)
+   {
+      super(PacketType.MSG_XA_FORGET);
+      
+      this.xid = xid;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetInDoubtXidsRequest.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetInDoubtXidsRequest.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetInDoubtXidsRequest.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAGetInDoubtXidsRequest extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAGetInDoubtXidsRequest()
+   {
+      super(PacketType.REQ_XA_INDOUBT_XIDS);
+   }
+
+   // Public --------------------------------------------------------
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetInDoubtXidsResponse.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetInDoubtXidsResponse.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetInDoubtXidsResponse.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import java.util.List;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAGetInDoubtXidsResponse extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private List<Xid> xids;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAGetInDoubtXidsResponse(List<Xid> xids)
+   {
+      super(PacketType.RESP_XA_INDOUBT_XIDS);
+      
+      this.xids = xids;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public List<Xid> getXids()
+   {
+      return xids;
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetTimeoutMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetTimeoutMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetTimeoutMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAGetTimeoutMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAGetTimeoutMessage()
+   {
+      super(PacketType.MSG_XA_GET_TIMEOUT);
+   }
+   
+   // Public --------------------------------------------------------
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetTimeoutResponse.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetTimeoutResponse.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAGetTimeoutResponse.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAGetTimeoutResponse extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private int timeoutSeconds;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAGetTimeoutResponse(int timeoutSeconds)
+   {
+      super(PacketType.MSG_XA_GET_TIMEOUT_RESPONSE);
+      
+      this.timeoutSeconds = timeoutSeconds;
+   }
+   
+
+   // Public --------------------------------------------------------
+   
+   public int getTimeoutSeconds()
+   {
+      return this.timeoutSeconds;
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAJoinMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAJoinMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAJoinMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAJoinMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private Xid xid;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAJoinMessage(Xid xid)
+   {
+      super(PacketType.MSG_XA_JOIN);
+      
+      this.xid = xid;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAPrepareMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAPrepareMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAPrepareMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAPrepareMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private Xid xid;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAPrepareMessage(Xid xid)
+   {
+      super(PacketType.REQ_XA_PREPARE);
+      
+      this.xid = xid;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAResponse.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAResponse.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAResponse.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAResponse extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private boolean error;
+   
+   private int responseCode;
+   
+   private String message;
+      
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAResponse(boolean isError, int responseCode, String message)
+   {
+      super(PacketType.RESP_XA);
+      
+      this.error = isError;
+      
+      this.responseCode = responseCode;
+      
+      this.message = message;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public boolean isError()
+   {
+      return error;
+   }
+   
+   public int getResponseCode()
+   {
+      return this.responseCode;
+   }
+   
+   public String getMessage()
+   {
+      return message;
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAResumeMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAResumeMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAResumeMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAResumeMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private Xid xid;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAResumeMessage(Xid xid)
+   {
+      super(PacketType.MSG_XA_RESUME);
+      
+      this.xid = xid;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXARollbackMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXARollbackMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXARollbackMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXARollbackMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private Xid xid;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXARollbackMessage(Xid xid)
+   {
+      super(PacketType.MSG_XA_ROLLBACK);
+      
+      this.xid = xid;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASetTimeoutMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASetTimeoutMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASetTimeoutMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXASetTimeoutMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private int timeoutSeconds;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXASetTimeoutMessage(int timeoutSeconds)
+   {
+      super(PacketType.MSG_XA_SET_TIMEOUT);
+      
+      this.timeoutSeconds = timeoutSeconds;
+   }
+   
+
+   // Public --------------------------------------------------------
+   
+   public int getTimeoutSeconds()
+   {
+      return this.timeoutSeconds;
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASetTimeoutResponse.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASetTimeoutResponse.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASetTimeoutResponse.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXASetTimeoutResponse extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private boolean ok;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXASetTimeoutResponse(boolean ok)
+   {
+      super(PacketType.MSG_XA_SET_TIMEOUT_RESPONSE);
+      
+      this.ok = ok;
+   }
+   
+   // Public --------------------------------------------------------
+   
+   public boolean isOK()
+   {
+      return ok;
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAStartMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAStartMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXAStartMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXAStartMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   private Xid xid;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXAStartMessage(Xid xid)
+   {
+      super(PacketType.MSG_XA_START);
+      
+      this.xid = xid;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Added: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASuspendMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASuspendMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionXASuspendMessage.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionXASuspendMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SessionXASuspendMessage()
+   {
+      super(PacketType.MSG_XA_SUSPEND);
+   }
+
+   // Public --------------------------------------------------------
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+

Modified: trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/BDBSpeedTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/BDBSpeedTest.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/BDBSpeedTest.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -556,7 +556,7 @@
 //   {      
 //      String id = java.util.UUID.randomUUID().toString();
 //      
-//      Xid xid = new MessagingXid("blah".getBytes(), 123, id.getBytes());
+//      Xid xid = new XidImpl("blah".getBytes(), 123, id.getBytes());
 //      
 //      return xid;
 //   }

Modified: trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -26,10 +26,10 @@
 
 import javax.transaction.xa.Xid;
 
+import org.jboss.messaging.core.impl.XidImpl;
 import org.jboss.messaging.core.impl.bdbje.BDBJEDatabase;
 import org.jboss.messaging.core.impl.bdbje.BDBJEEnvironment;
 import org.jboss.messaging.core.impl.bdbje.BDBJETransaction;
-import org.jboss.messaging.core.tx.MessagingXid;
 import org.jboss.messaging.test.unit.UnitTestCase;
 
 import com.sleepycat.je.DatabaseException;
@@ -789,7 +789,7 @@
       
       assertContainsPair(id2, bytes2, 2);
       
-      MessagingXid xid = generateXid();
+      XidImpl xid = generateXid();
       
       env.startWork(xid);
       
@@ -813,7 +813,7 @@
    }
    
    /*
-    * As above but we use different but equal() MessagingXid instances at each point
+    * As above but we use different but equal() XidImpl instances at each point
     */
    public void testPutAndRemoveMultipleXACommitWithCopy() throws Exception
    {
@@ -843,7 +843,7 @@
       
       assertContainsPair(id2, bytes2, 2);
       
-      MessagingXid xid = generateXid();
+      XidImpl xid = generateXid();
       
       env.startWork(xid);
       
@@ -855,15 +855,15 @@
       
       database.remove(null, id2);
       
-      xid = new MessagingXid(xid);
+      xid = new XidImpl(xid);
             
       env.endWork(xid, false);
       
-      xid = new MessagingXid(xid);      
+      xid = new XidImpl(xid);      
       
       env.prepare(xid);
       
-      xid = new MessagingXid(xid);
+      xid = new XidImpl(xid);
       
       env.commit(xid);
       
@@ -900,7 +900,7 @@
       
       assertContainsPair(id2, bytes2, 2);
       
-      final MessagingXid xid = generateXid();
+      final XidImpl xid = generateXid();
       
       env.startWork(xid);
       

Modified: trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -53,7 +53,7 @@
       
       EasyMock.replay(pm);
       
-      tx.commit(pm);
+      tx.commit(true, pm);
       
       EasyMock.verify(pm);
       
@@ -160,7 +160,7 @@
       
       EasyMock.replay(pm);
       
-      tx.commit(pm);
+      tx.commit(false, pm);
       
       EasyMock.verify(pm);
    }
@@ -189,7 +189,7 @@
       
       try
       {    
-         tx.commit(pm);
+         tx.commit(false, pm);
          
          fail ("Should throw exception");
       }
@@ -271,7 +271,7 @@
       
       EasyMock.replay(sync);
       
-      tx.commit(pm);
+      tx.commit(true, pm);
       
       EasyMock.verify(sync);
       
@@ -325,7 +325,7 @@
       EasyMock.replay(sync);
       
       tx.prepare(pm);
-      tx.commit(pm);
+      tx.commit(false, pm);
       
       EasyMock.verify(sync);
       

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -8,7 +8,7 @@
 
 import junit.framework.Assert;
 
-import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.messaging.core.impl.XidImpl;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -24,13 +24,13 @@
 
    // Static --------------------------------------------------------
 
-   static void assertSameXids(MessagingXid[] expected, MessagingXid[] actual)
+   static void assertSameXids(XidImpl[] expected, XidImpl[] actual)
    {
       assertEquals(expected.length, actual.length);
       for (int i = 0; i < expected.length; i++)
       {
-         MessagingXid expectedXid = expected[i];
-         MessagingXid actualXid = actual[i];
+         XidImpl expectedXid = expected[i];
+         XidImpl actualXid = actual[i];
          assertEqualsByteArrays(expectedXid.getBranchQualifier(), actualXid
                .getBranchQualifier());
          assertEquals(expectedXid.getFormatId(), actualXid.getFormatId());

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -68,12 +68,13 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.jms.InvalidDestinationException;
 import javax.jms.JMSException;
+import javax.transaction.xa.Xid;
 
-import junit.framework.TestCase;
-
 import org.apache.mina.common.IoBuffer;
 import org.jboss.jms.destination.JBossQueue;
 import org.jboss.jms.destination.JBossTopic;
@@ -108,6 +109,19 @@
 import org.jboss.messaging.core.remoting.codec.SessionAcknowledgeMessageCodec;
 import org.jboss.messaging.core.remoting.codec.SessionCancelMessageCodec;
 import org.jboss.messaging.core.remoting.codec.SessionSendMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXACommitMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAEndMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAForgetMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAGetInDoubtXidsResponseCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAGetTimeoutResponseCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAJoinMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAPrepareMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAResponseCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAResumeMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXARollbackMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXASetTimeoutMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXASetTimeoutResponseCodec;
+import org.jboss.messaging.core.remoting.codec.SessionXAStartMessageCodec;
 import org.jboss.messaging.core.remoting.codec.SetClientIDMessageCodec;
 import org.jboss.messaging.core.remoting.codec.SetSessionIDMessageCodec;
 import org.jboss.messaging.core.remoting.codec.TextPacketCodec;
@@ -152,12 +166,30 @@
 import org.jboss.messaging.core.remoting.wireformat.SessionRecoverMessage;
 import org.jboss.messaging.core.remoting.wireformat.SessionRollbackMessage;
 import org.jboss.messaging.core.remoting.wireformat.SessionSendMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXACommitMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAEndMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAForgetMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsRequest;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAJoinMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAPrepareMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAResumeMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXARollbackMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutResponse;
+import org.jboss.messaging.core.remoting.wireformat.SessionXAStartMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionXASuspendMessage;
 import org.jboss.messaging.core.remoting.wireformat.SetClientIDMessage;
 import org.jboss.messaging.core.remoting.wireformat.SetSessionIDMessage;
 import org.jboss.messaging.core.remoting.wireformat.StartConnectionMessage;
 import org.jboss.messaging.core.remoting.wireformat.StopConnectionMessage;
 import org.jboss.messaging.core.remoting.wireformat.TextPacket;
 import org.jboss.messaging.core.remoting.wireformat.UnsubscribeMessage;
+import org.jboss.messaging.test.unit.RandomUtil;
+import org.jboss.messaging.test.unit.UnitTestCase;
 import org.jboss.messaging.util.Logger;
 
 /**
@@ -165,7 +197,7 @@
  * 
  * @version <tt>$Revision$</tt>
  */
-public class PacketTypeTest extends TestCase
+public class PacketTypeTest extends UnitTestCase
 {
 
    // Constants -----------------------------------------------------
@@ -1161,7 +1193,7 @@
    {
       Destination destination = new DestinationImpl(DestinationType.QUEUE,
             "testDeleteTemporaryDestinationMessage", false);
-      ;
+      
       DeleteTemporaryDestinationMessage message = new DeleteTemporaryDestinationMessage(
             destination);
 
@@ -1177,7 +1209,339 @@
       assertEquals(MSG_DELETETEMPORARYDESTINATION, decodedMessage.getType());
       assertEquals(message.getDestination(), decodedMessage.getDestination());
    }
+   
+   public void testSesssionXACommitMessageOnePhase() throws Exception
+   {
+      this.testSessionXACommitMessage(true);
+   }
+   
+   public void testSessionXACommitMessageNotOnePhase() throws Exception
+   {
+      this.testSessionXACommitMessage(false);
+   }
+   
+   private void testSessionXACommitMessage(boolean onePhase) throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXACommitMessage message = new SessionXACommitMessage(xid, onePhase);
+      AbstractPacketCodec codec = new SessionXACommitMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXACommitMessage);
+      SessionXACommitMessage decodedMessage = (SessionXACommitMessage)decodedPacket;
+      assertEquals(PacketType.MSG_XA_COMMIT, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+      assertEquals(onePhase, decodedMessage.isOnePhase());
+   }
+   
+   public void testSessionXAEndMessageFailed() throws Exception
+   {
+      this.testSessionXAEndMessage(true);
+   }
+   
+   public void testSessionXAEndMessageNotFailed() throws Exception
+   {
+      this.testSessionXACommitMessage(false);
+   }
+   
+   private void testSessionXAEndMessage(boolean failed) throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAEndMessage message = new SessionXAEndMessage(xid, failed);
+      AbstractPacketCodec codec = new SessionXAEndMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAEndMessage);
+      SessionXAEndMessage decodedMessage = (SessionXAEndMessage)decodedPacket;
+      assertEquals(PacketType.MSG_XA_END, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+      assertEquals(failed, decodedMessage.isFailed());
+   }
+   
+   public void testSessionXAForgetMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAForgetMessage message = new SessionXAForgetMessage(xid);
+      AbstractPacketCodec codec = new SessionXAForgetMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAForgetMessage);
+      SessionXAForgetMessage decodedMessage = (SessionXAForgetMessage)decodedPacket;
+      assertEquals(PacketType.MSG_XA_FORGET, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXAGetInDoubtXidsMessage() throws Exception
+   {
+      SessionXAGetInDoubtXidsRequest request = new SessionXAGetInDoubtXidsRequest();
 
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            PacketType.REQ_XA_INDOUBT_XIDS, SessionXAGetInDoubtXidsRequest.class);
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionXAGetInDoubtXidsRequest);
+      assertEquals(PacketType.REQ_XA_INDOUBT_XIDS, decodedPacket.getType());            
+   }
+   
+   public void testSessionGetInDoubtXidsResponse() throws Exception
+   {
+      final int numXids = 10;
+      List<Xid> xids = new ArrayList<Xid>();
+      for (int i = 0; i < numXids; i++)
+      {
+         xids.add(generateXid());
+      }
+      
+      SessionXAGetInDoubtXidsResponse message = new SessionXAGetInDoubtXidsResponse(xids);
+      AbstractPacketCodec codec = new SessionXAGetInDoubtXidsResponseCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAGetInDoubtXidsResponse);
+      SessionXAGetInDoubtXidsResponse decodedMessage = (SessionXAGetInDoubtXidsResponse)decodedPacket;
+      assertEquals(PacketType.RESP_XA_INDOUBT_XIDS, decodedMessage.getType());
+           
+      List<Xid> decodedXids = decodedMessage.getXids();
+      assertNotNull(decodedXids);
+      assertEquals(xids.size(), decodedXids.size());
+      
+      for (int i = 0; i < numXids; i++)
+      {
+         assertEquals(xids.get(i), decodedXids.get(i));
+      }
+   }
+   
+   public void testSessionXAGetTimeoutMessage() throws Exception
+   {
+      SessionXAGetTimeoutMessage message = new SessionXAGetTimeoutMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            PacketType.MSG_XA_GET_TIMEOUT, SessionXAGetTimeoutMessage.class);
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionXAGetTimeoutMessage);
+      assertEquals(PacketType.MSG_XA_GET_TIMEOUT, decodedPacket.getType());     
+   }
+   
+   public void testSessionXAGetTimeoutResponse() throws Exception
+   {
+      final int timeout = RandomUtil.randomInt();
+      
+      SessionXAGetTimeoutResponse message = new SessionXAGetTimeoutResponse(timeout);
+      AbstractPacketCodec codec = new SessionXAGetTimeoutResponseCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAGetTimeoutResponse);
+      SessionXAGetTimeoutResponse decodedMessage = (SessionXAGetTimeoutResponse)decodedPacket;
+      assertEquals(PacketType.MSG_XA_GET_TIMEOUT_RESPONSE, decodedMessage.getType());
+           
+      assertEquals(timeout, decodedMessage.getTimeoutSeconds());
+   }
+
+   public void testSessionXAJoinMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAJoinMessage message = new SessionXAJoinMessage(xid);
+      AbstractPacketCodec codec = new SessionXAJoinMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAJoinMessage);
+      SessionXAJoinMessage decodedMessage = (SessionXAJoinMessage)decodedPacket;
+      assertEquals(PacketType.MSG_XA_JOIN, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXAPrepareMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAPrepareMessage message = new SessionXAPrepareMessage(xid);
+      AbstractPacketCodec codec = new SessionXAPrepareMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAPrepareMessage);
+      SessionXAPrepareMessage decodedMessage = (SessionXAPrepareMessage)decodedPacket;
+      assertEquals(PacketType.REQ_XA_PREPARE, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXAResponseErrorNullString() throws Exception
+   {
+      testSessionXAResponse(true, true);
+   }
+   
+   public void testSessionXAResponseErrorNotNullString() throws Exception
+   {
+      testSessionXAResponse(true, false);
+   }
+   
+   public void testSessionXAResponseNoErrorNullString() throws Exception
+   {
+      testSessionXAResponse(false, true);
+   }
+   
+   public void testSessionXAResponseNoErrorNotNullString() throws Exception
+   {
+      testSessionXAResponse(false, false);
+   }
+   
+   private void testSessionXAResponse(boolean error, boolean nullString) throws Exception
+   {
+      int responseCode = RandomUtil.randomInt();
+      
+      String str = nullString ? null : RandomUtil.randomString();
+      
+      SessionXAResponse message = new SessionXAResponse(error, responseCode, str);
+      AbstractPacketCodec codec = new SessionXAResponseCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAResponse);
+      SessionXAResponse decodedMessage = (SessionXAResponse)decodedPacket;
+      assertEquals(PacketType.RESP_XA, decodedMessage.getType());
+      assertEquals(error, decodedMessage.isError());
+      assertEquals(responseCode, decodedMessage.getResponseCode());
+      assertEquals(str, decodedMessage.getMessage());
+   }
+   
+   public void testSessionXAResumeMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAResumeMessage message = new SessionXAResumeMessage(xid);
+      AbstractPacketCodec codec = new SessionXAResumeMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAResumeMessage);
+      SessionXAResumeMessage decodedMessage = (SessionXAResumeMessage)decodedPacket;
+      assertEquals(PacketType.MSG_XA_RESUME, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXARollbackMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXARollbackMessage message = new SessionXARollbackMessage(xid);
+      AbstractPacketCodec codec = new SessionXARollbackMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXARollbackMessage);
+      SessionXARollbackMessage decodedMessage = (SessionXARollbackMessage)decodedPacket;
+      assertEquals(PacketType.MSG_XA_ROLLBACK, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXASetTimeoutMessage() throws Exception
+   {
+      final int timeout = RandomUtil.randomInt();
+      SessionXASetTimeoutMessage message = new SessionXASetTimeoutMessage(timeout);
+      AbstractPacketCodec codec = new SessionXASetTimeoutMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXASetTimeoutMessage);
+      SessionXASetTimeoutMessage decodedMessage = (SessionXASetTimeoutMessage)decodedPacket;
+      assertEquals(PacketType.MSG_XA_SET_TIMEOUT, decodedMessage.getType());
+      assertEquals(timeout, decodedMessage.getTimeoutSeconds());      
+   }
+   
+   public void testSessionXASetTimeoutResponseMessageOK() throws Exception
+   {
+      testSessionXASetTimeoutResponseMessage(true);
+   }
+   
+   public void testSessionXASetTimeoutResponseMessageNotOK() throws Exception
+   {
+      testSessionXASetTimeoutResponseMessage(false);
+   }
+   
+   private void testSessionXASetTimeoutResponseMessage(boolean ok) throws Exception
+   {
+      final int timeout = RandomUtil.randomInt();
+      SessionXASetTimeoutResponse message = new SessionXASetTimeoutResponse(ok);
+      AbstractPacketCodec codec = new SessionXASetTimeoutResponseCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXASetTimeoutResponse);
+      SessionXASetTimeoutResponse decodedMessage = (SessionXASetTimeoutResponse)decodedPacket;
+      assertEquals(PacketType.MSG_XA_SET_TIMEOUT_RESPONSE, decodedMessage.getType());
+      assertEquals(ok, decodedMessage.isOK());      
+   }
+   
+   public void testSessionXAStartMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAStartMessage message = new SessionXAStartMessage(xid);
+      AbstractPacketCodec codec = new SessionXAStartMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAStartMessage);
+      SessionXAStartMessage decodedMessage = (SessionXAStartMessage)decodedPacket;
+      assertEquals(PacketType.MSG_XA_START, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXASuspendMessage() throws Exception
+   {
+      SessionXASuspendMessage message = new SessionXASuspendMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            PacketType.MSG_XA_SUSPEND, SessionXASuspendMessage.class);
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionXASuspendMessage);
+      assertEquals(PacketType.MSG_XA_SUSPEND, decodedPacket.getType());     
+   }
+   
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------

Modified: trunk/tests/src/org/jboss/messaging/core/tx/test/unit/MessagingXidTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/tx/test/unit/MessagingXidTest.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/messaging/core/tx/test/unit/MessagingXidTest.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -28,7 +28,7 @@
 
 import javax.transaction.xa.Xid;
 
-import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.messaging.core.impl.XidImpl;
 import org.jboss.messaging.test.unit.RandomUtil;
 import org.jboss.messaging.test.unit.UnitTestCase;
 
@@ -43,7 +43,7 @@
 {
    public void testSerialize() throws Exception
    {
-      MessagingXid xid = new MessagingXid(RandomUtil.randomBytes(), RandomUtil.randomInt(),
+      XidImpl xid = new XidImpl(RandomUtil.randomBytes(), RandomUtil.randomInt(),
                                           RandomUtil.randomBytes());
       
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -58,9 +58,9 @@
       
       Object obj = ois.readObject();
       
-      assertTrue(obj instanceof MessagingXid);
+      assertTrue(obj instanceof XidImpl);
       
-      MessagingXid xid2 = (MessagingXid)obj;
+      XidImpl xid2 = (XidImpl)obj;
       
       assertXidsEquivalent(xid, xid2);
       
@@ -75,7 +75,7 @@
       
       int formatID = RandomUtil.randomInt();
       
-      MessagingXid xid1 = new MessagingXid(bq, formatID, globalTXID);
+      XidImpl xid1 = new XidImpl(bq, formatID, globalTXID);
       
       assertByteArraysEquivalent(bq, xid1.getBranchQualifier());
       
@@ -86,10 +86,10 @@
    
    public void testCopyConstructor()
    {
-      MessagingXid xid1 = new MessagingXid(RandomUtil.randomBytes(), RandomUtil.randomInt(),
+      XidImpl xid1 = new XidImpl(RandomUtil.randomBytes(), RandomUtil.randomInt(),
                                           RandomUtil.randomBytes());
       
-      MessagingXid xid2 = new MessagingXid(xid1);
+      XidImpl xid2 = new XidImpl(xid1);
       
       assertXidsEquivalent(xid1, xid2);
       
@@ -98,7 +98,7 @@
    
    public void testDefaultConstructor()
    {
-      MessagingXid xid1 = new MessagingXid();
+      XidImpl xid1 = new XidImpl();
       
       assertNull(xid1.getBranchQualifier());
       
@@ -109,7 +109,7 @@
    
    public void testEqualsWithForeign()
    {
-      MessagingXid xid1 = new MessagingXid(RandomUtil.randomBytes(), RandomUtil.randomInt(),
+      XidImpl xid1 = new XidImpl(RandomUtil.randomBytes(), RandomUtil.randomInt(),
             RandomUtil.randomBytes());
 
       Xid foreign = new ForeignXid(xid1.getBranchQualifier(), xid1.getFormatId(), xid1.getGlobalTransactionId());

Modified: trunk/tests/src/org/jboss/messaging/test/unit/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/test/unit/UnitTestCase.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/messaging/test/unit/UnitTestCase.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -38,7 +38,7 @@
 import org.jboss.messaging.core.MessageReference;
 import org.jboss.messaging.core.Queue;
 import org.jboss.messaging.core.impl.MessageImpl;
-import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.messaging.core.impl.XidImpl;
 
 /**
  * 
@@ -286,7 +286,7 @@
       }
    }
    
-   protected MessagingXid generateXid()
+   protected XidImpl generateXid()
    {      
       String id1 = java.util.UUID.randomUUID().toString();
       
@@ -294,7 +294,7 @@
       
       int id = (int)(Math.random() * 100);
       
-      MessagingXid xid = new MessagingXid(id1.getBytes(), id, id2.getBytes());
+      XidImpl xid = new XidImpl(id1.getBytes(), id, id2.getBytes());
       
       return xid;
    }

Modified: trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -42,7 +42,7 @@
 
 import org.jboss.jms.exception.MessagingXAException;
 import org.jboss.jms.server.security.Role;
-import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.messaging.core.impl.XidImpl;
 import org.jboss.messaging.util.Logger;
 import org.jboss.test.messaging.tools.ServerManagement;
 
@@ -1121,7 +1121,7 @@
 
          XASession xasession = xaconn.createXASession();
 
-         MessagingXid xid = new MessagingXid(new byte[]{1}, 1, new byte[]{1});
+         XidImpl xid = new XidImpl(new byte[]{1}, 1, new byte[]{1});
 
          XAResource resource = xasession.getXAResource();
 

Modified: trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -33,7 +33,7 @@
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.messaging.core.impl.XidImpl;
 
 import com.arjuna.ats.arjuna.common.Uid;
 import com.arjuna.ats.jta.xa.XidImple;
@@ -123,7 +123,7 @@
          
          XAResource res = sess2.getXAResource();
          
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
          
          res.start(xid1, XAResource.TMNOFLAGS);
          
@@ -355,7 +355,7 @@
          
          XAResource res = sess2.getXAResource();
          
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
          
          res.start(xid1, XAResource.TMNOFLAGS);
          
@@ -606,7 +606,7 @@
          
          XAResource res = sess2.getXAResource();
          
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
          
          res.start(xid1, XAResource.TMNOFLAGS);
          
@@ -874,7 +874,7 @@
          
          XAResource res = sess2.getXAResource();
          
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
          
          res.start(xid1, XAResource.TMNOFLAGS);
          
@@ -1131,7 +1131,7 @@
          
          XAResource res = sess2.getXAResource();
          
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
          
          res.start(xid1, XAResource.TMNOFLAGS);
          
@@ -1326,7 +1326,7 @@
          XAResource res1 = sess1.getXAResource();
    
          //Pretend to be a transaction manager by interacting through the XAResources
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
    
          log.trace("Sending message");
          
@@ -1460,7 +1460,7 @@
          XAResource res1 = sess1.getXAResource();
    
          //Pretend to be a transaction manager by interacting through the XAResources
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
    
          log.trace("Sending message");
          
@@ -1638,7 +1638,7 @@
          XAResource res1 = sess2.getXAResource();
    
          //Pretend to be a transaction manager by interacting through the XAResources
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
          
          res1.start(xid1, XAResource.TMNOFLAGS);
          
@@ -1775,7 +1775,7 @@
          XAResource res1 = sess2.getXAResource();
    
          //Pretend to be a transaction manager by interacting through the XAResources
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
          
          res1.start(xid1, XAResource.TMNOFLAGS);
          
@@ -1949,7 +1949,7 @@
          
          XAResource res = sess2.getXAResource();
          
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
          
          res.start(xid1, XAResource.TMNOFLAGS);
          
@@ -2208,7 +2208,7 @@
          
          XAResource res = sess2.getXAResource();
          
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
          
          res.start(xid1, XAResource.TMNOFLAGS);
          
@@ -2454,8 +2454,8 @@
          XAResource res2 = sess2.getXAResource();
    
          //Pretend to be a transaction manager by interacting through the XAResources
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
-         Xid xid2 = new MessagingXid("bq2".getBytes(), 42, "frigtard".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "eemeli".getBytes());
+         Xid xid2 = new XidImpl("bq2".getBytes(), 42, "frigtard".getBytes());
    
          log.trace("Sending messages");
          
@@ -2659,8 +2659,8 @@
          XAResource res2 = sess2.getXAResource();
    
          //Pretend to be a transaction manager by interacting through the XAResources
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "aapeli".getBytes());
-         Xid xid2 = new MessagingXid("bq2".getBytes(), 42, "belsebub".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 42, "aapeli".getBytes());
+         Xid xid2 = new XidImpl("bq2".getBytes(), 42, "belsebub".getBytes());
    
          //    Send a message in each tx
    
@@ -2961,8 +2961,8 @@
          XAResource res2 = sess2.getXAResource();
    
          //Pretend to be a transaction manager by interacting through the XAResources
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 123, "gbtxid1".getBytes());
-         Xid xid2 = new MessagingXid("bq2".getBytes(), 124, "gbtxid2".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 123, "gbtxid1".getBytes());
+         Xid xid2 = new XidImpl("bq2".getBytes(), 124, "gbtxid2".getBytes());
    
          //    Send a message in each tx
    
@@ -3102,8 +3102,8 @@
          XAResource res2 = sess2.getXAResource();
    
          //Pretend to be a transaction manager by interacting through the XAResources
-         Xid xid1 = new MessagingXid("bq1".getBytes(), 123, "gbtxid1".getBytes());
-         Xid xid2 = new MessagingXid("bq2".getBytes(), 124, "gbtxid2".getBytes());
+         Xid xid1 = new XidImpl("bq1".getBytes(), 123, "gbtxid1".getBytes());
+         Xid xid2 = new XidImpl("bq2".getBytes(), 124, "gbtxid2".getBytes());
    
          //    Send a message in each tx
    

Modified: trunk/tests/src/org/jboss/test/messaging/jms/XATest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XATest.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XATest.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -35,30 +35,22 @@
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.jms.XAConnection;
-import javax.jms.XAConnectionFactory;
 import javax.jms.XASession;
-import javax.naming.InitialContext;
 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.jms.client.JBossConnection;
 import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.jms.client.JBossSession;
-import org.jboss.jms.client.api.ClientConnection;
-import org.jboss.jms.client.api.ClientSession;
-import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.jms.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.impl.XidImpl;
 import org.jboss.messaging.util.Logger;
 import org.jboss.test.messaging.JBMServerTestCase;
 import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.test.messaging.tools.container.ServiceContainer;
-import org.jboss.tm.TransactionManagerLocator;
 import org.jboss.tm.TxUtils;
 
 import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
-import com.sun.naming.internal.ResourceManager;
 
 /**
  *
@@ -98,21 +90,12 @@
    public void setUp() throws Exception
    { 
       super.setUp();
+      
       cf = getConnectionFactory();
 
-      //Also need a local tx mgr if test is running remote
-      if (ServerManagement.isRemote())
-      {
-         tm = new TransactionManagerImple();
-      }
-      else
-      {
-         InitialContext localIc = getInitialContext();
+      tm = this.getTransactionManager();
+      
 
-         tm = (TransactionManager)localIc.lookup(ServiceContainer.TRANSACTION_MANAGER_JNDI_NAME);
-      }
-
-
       assertTrue(tm instanceof TransactionManagerImple);
      
       if (!ServerManagement.isRemote())
@@ -151,3116 +134,2359 @@
    }
 
    // Public --------------------------------------------------------
-//
-//   /* If there is no global tx present the send must behave as non transacted.
-//    * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
-//    * http://jira.jboss.com/jira/browse/JBMESSAGING-410
-//    * http://jira.jboss.com/jira/browse/JBMESSAGING-721
-//    * http://jira.jboss.org/jira/browse/JBMESSAGING-946
-//    */
-//   public void testSendNoGlobalTransaction() throws Exception
-//   {
-//      Transaction suspended = null;
-//
-//      try
-//      {
-//         // make sure there's no active JTA transaction
-//
-//         suspended = tm.suspend();
-//
-//         // send a message to the queue using an XASession that's not enlisted in a global tx
-//
-//         XAConnectionFactory xcf = (XAConnectionFactory)cf;
-//
-//         XAConnection xconn = xcf.createXAConnection();
-//
-//         XASession xs = xconn.createXASession();
-//         
-//         MessageProducer p = xs.createProducer(queue1);
-//         Message m = xs.createTextMessage("one");
-//
-//         p.send(m);
-//
-//         xconn.close();
-//
-//         // receive the message
-//         Connection conn = cf.createConnection();
-//         conn.start();
-//         Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer c = s.createConsumer(queue1);
-//         TextMessage rm = (TextMessage)c.receive(1000);
-//
-//         assertEquals("one", rm.getText());
-//
-//         conn.close();
-//      }
-//      finally
-//      {
-//         if (suspended != null)
-//         {
-//            TransactionManagerLocator.getInstance().locate().resume(suspended);
-//         }
-//      }
-//   }
-//
-//
-//   /*
-//    * If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
-//    * falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
-//    * 
-//    * There is one exception to this:
-//    * 
-//    * For transactional delivery of messages in an MDB using the old container invoker (non JCA 1.5 inflow) the message
-//    * is received from the JMS provider *before* the MDB container has a chance to enlist the session in a transaction.
-//    * (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration" of Mark Little's book Java Transaction
-//    * processing for a discussion of how different app servers deal with this)
-//    * This is not a problem specific to JBoss and was solved with JCA 1.5 message inflow.
-//    * Consequently, if we detect the session has a distinguised session listener (which it will if using ASF) then the behaviour
-//    * is to fall back to being a local transacted session. Later on, when the session is enlisted the work done in the local tx
-//    * is converted to the global tx brach.
-//    * 
-//    * We are testing the exceptional case here without a global tx here
-//    *
-//    * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
-//    * http://jira.jboss.com/jira/browse/JBMESSAGING-410
-//    * http://jira.jboss.com/jira/browse/JBMESSAGING-721
-//    * http://jira.jboss.org/jira/browse/JBMESSAGING-946
-//    *
-//    */
-//   public void testConsumeWithConnectionConsumerNoGlobalTransaction() throws Exception
-//   {
-//      // send a message to the queue
-//
-//      Connection conn = cf.createConnection();
-//      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//      MessageProducer p = s.createProducer(queue1);
-//      p.setDeliveryMode(DeliveryMode.PERSISTENT);
-//      Message m = s.createTextMessage("one");
-//      p.send(m);
-//      conn.close();
-//
-//      // make sure there's no active JTA transaction
-//
-//      Transaction suspended = tm.suspend();
-//
-//      XAConnection xaconn = null;
-//      try
-//      {
-//         Integer count = getMessageCountForQueue("Queue1");
-//         assertEquals(1, count.intValue());
-//
-//         // using XA with a ConnectionConsumer (testing the transaction behavior under MDBs)
-//
-//         XAConnectionFactory xacf = (XAConnectionFactory)cf;
-//         xaconn = xacf.createXAConnection();
-//         xaconn.start();
-//         XASession xasession = xaconn.createXASession();
-//         DummyListener listener = new DummyListener();
-//         xasession.setMessageListener(listener);
-//
-//         ServerSessionPool pool = new MockServerSessionPool(xasession);
-//
-//         xaconn.createConnectionConsumer(queue1, null, pool, 1);
-//
-//         Thread.sleep(1000);
-//         assertEquals(1, listener.messages.size());
-//
-//         // Message should still be on server
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(1, count.intValue());
-//
-//         XAResource resource = xasession.getXAResource();
-//
-//         // Starts a new transaction
-//         tm.begin();
-//
-//         Transaction trans = tm.getTransaction();
-//
-//         ClientSession clientSession = ((JBossSession)xasession).getDelegate();
-//                  
-//         // Validates TX convertion
-//         assertTrue(clientSession.getCurrentTxId() instanceof LocalTx);
-//
-//         // Enlist the transaction... as supposed to be happening on JBossAS with the
-//         // default listener (enlist happening after message is received)
-//         trans.enlistResource(resource);
-//
-//         // Validates TX convertion
-//         assertFalse(clientSession.getCurrentTxId() instanceof LocalTx);
-//
-//         trans.delistResource(resource, XAResource.TMSUCCESS);
-//
-//         trans.commit();
-//
-//         // After commit the message should be consumed
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(0, count.intValue());
-//      }
-//      finally
-//      {
-//         if (xaconn != null)
-//         {
-//            xaconn.close();
-//         }
-//         if (suspended != null)
-//         {
-//            TransactionManagerLocator.getInstance().locate().resume(suspended);
-//         }
-//      }
-//   }
-//   
-//   
-//   /*
-//    * If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
-//    * falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
-//    * 
-//    * There is one exception to this:
-//    * 
-//    * For transactional delivery of messages in an MDB using the old container invoker (non JCA 1.5 inflow) the message
-//    * is received from the JMS provider *before* the MDB container has a chance to enlist the session in a transaction.
-//    * (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration" of Mark Little's book Java Transaction
-//    * processing for a discussion of how different app servers deal with this)
-//    * This is not a problem specific to JBoss and was solved with JCA 1.5 message inflow.
-//    * Consequently, if we detect the session has a distinguised session listener (which it will if using ASF) then the behaviour
-//    * is to fall back to being a local transacted session. Later on, when the session is enlisted the work done in the local tx
-//    * is converted to the global tx brach.
-//    * 
-//    * We are testing the standard case without a global tx here
-//    *
-//    * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
-//    * http://jira.jboss.com/jira/browse/JBMESSAGING-410
-//    * http://jira.jboss.com/jira/browse/JBMESSAGING-721
-//    * http://jira.jboss.org/jira/browse/JBMESSAGING-946
-//    *
-//    */
-//   public void testConsumeWithoutConnectionConsumerNoGlobalTransaction() throws Exception
-//   {
-//      // send a message to the queue
-//
-//      Connection conn = cf.createConnection();
-//      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//      MessageProducer p = s.createProducer(queue1);
-//      p.setDeliveryMode(DeliveryMode.PERSISTENT);
-//      Message m = s.createTextMessage("one");
-//      p.send(m);
-//      conn.close();
-//
-//      // make sure there's no active JTA transaction
-//
-//      Transaction suspended = tm.suspend();
-//
-//      try
-//      {
-//         Integer count = getMessageCountForQueue("Queue1");
-//         assertEquals(1, count.intValue());
-//
-//         XAConnectionFactory xcf = (XAConnectionFactory)cf;
-//         XAConnection xconn = xcf.createXAConnection();
-//         xconn.start();
-//
-//         // no active JTA transaction here
-//
-//         XASession xs = xconn.createXASession();
-//
-//         MessageConsumer c = xs.createConsumer(queue1);
-//
-//         // the message should be store unacked in the local session
-//         TextMessage rm = (TextMessage)c.receive(1000);
-//
-//         assertEquals("one", rm.getText());
-//         
-//         // messages should be acked
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(0, count.intValue());
-//         
-//         xconn.close();
-//      }
-//      finally
-//      {
-//
-//         if (suspended != null)
-//         {
-//            TransactionManagerLocator.getInstance().locate().resume(suspended);
-//         }
-//      }
-//   }
-//   
-//
-//   /*
-//    * If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
-//    * falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
-//    * 
-//    * There is one exception to this:
-//    * 
-//    * For transactional delivery of messages in an MDB using the old container invoker (non JCA 1.5 inflow) the message
-//    * is received from the JMS provider *before* the MDB container has a chance to enlist the session in a transaction.
-//    * (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration" of Mark Little's book Java Transaction
-//    * processing for a discussion of how different app servers deal with this)
-//    * This is not a problem specific to JBoss and was solved with JCA 1.5 message inflow.
-//    * Consequently, if we detect the session has a distinguised session listener (which it will if using ASF) then the behaviour
-//    * is to fall back to being a local transacted session. Later on, when the session is enlisted the work done in the local tx
-//    * is converted to the global tx brach.
-//    * 
-//    * We are testing the case with a global tx here
-//    *
-//    * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
-//    * http://jira.jboss.com/jira/browse/JBMESSAGING-410
-//    * http://jira.jboss.com/jira/browse/JBMESSAGING-721
-//    * http://jira.jboss.org/jira/browse/JBMESSAGING-946
-//    *
-//    */
-//   public void testConsumeGlobalTransaction() throws Exception
-//   {
-//      XAConnection xaconn = null;
-//
-//      try
-//      {
-//         // send a message to the queue
-//
-//         Connection conn = cf.createConnection();
-//         Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer p = s.createProducer(queue1);
-//         p.setDeliveryMode(DeliveryMode.PERSISTENT);
-//         Message m = s.createTextMessage("one");
-//         p.send(m);
-//         conn.close();
-//
-//         Integer count = getMessageCountForQueue("Queue1");
-//         assertEquals(1, count.intValue());
-//
-//         tm.begin();
-//
-//         Transaction trans = tm.getTransaction();
-//
-//         XAConnectionFactory xacf = (XAConnectionFactory)cf;
-//
-//         xaconn = xacf.createXAConnection();
-//
-//         xaconn.start();
-//
-//         XASession xasession = xaconn.createXASession();
-//
-//         XAResource resouce = xasession.getXAResource();
-//
-//         trans.enlistResource(resouce);
-//
-//         MessageConsumer consumer = xasession.createConsumer(queue1);
-//
-//         TextMessage messageReceived = (TextMessage)consumer.receive(1000);
-//
-//         assertNotNull(messageReceived);
-//
-//         assertEquals("one", messageReceived.getText());
-//
-//         assertNull(consumer.receive(1000));
-//
-//         count = getMessageCountForQueue("Queue1");
-//
-//         assertEquals(1, count.intValue());
-//
-//         trans.delistResource(resouce, XAResource.TMSUCCESS);
-//
-//         tm.rollback();
-//
-//         tm.begin();
-//         trans = tm.getTransaction();
-//         trans.enlistResource(resouce);
-//
-//         messageReceived = (TextMessage)consumer.receive(1000);
-//
-//         assertNotNull(messageReceived);
-//
-//         assertEquals("one", messageReceived.getText());
-//
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(1, count.intValue());
-//
-//         trans.commit();
-//
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(0, count.intValue());
-//
-//      }
-//      finally
-//      {
-//         if (xaconn != null)
-//         {
-//            xaconn.close();
-//         }
-//      }
-//   }
-//
-//   /*
-//    *   This test will:
-//    *     - Send two messages over a producer
-//    *     - Receive one message over a consumer created used a XASession
-//    *     - Call Recover
-//    *     - Receive the second message
-//    *     - The queue should be empty after that 
-//    *   Verifies if messages are sent ok and ack properly when recovery is called
-//    *      NOTE: To accomodate TCK tests where Session/Consumers are being used without transaction enlisting
-//    *            we are processing those cases as nonTransactional/AutoACK, however if the session is being used
-//    *            to process MDBs we will consider the LocalTransaction convertion and process those as the comment above
-//    *            This was done as per: http://jira.jboss.org/jira/browse/JBMESSAGING-946
-//    *
-//    */
-//   public void testRecoverOnXA() throws Exception
-//   {
-//      XAConnection xaconn = null;
-//
-//      try
-//      {
-//         // send a message to the queue
-//
-//         Connection conn = cf.createConnection();
-//         Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer p = s.createProducer(queue1);
-//         p.setDeliveryMode(DeliveryMode.PERSISTENT);
-//         Message m = s.createTextMessage("one");
-//         p.send(m);
-//         m = s.createTextMessage("two");
-//         p.send(m);
-//         conn.close();
-//
-//         Integer count = getMessageCountForQueue("Queue1");
-//         assertEquals(2, count.intValue());
-//
-//         XAConnectionFactory xacf = (XAConnectionFactory)cf;
-//
-//         xaconn = xacf.createXAConnection();
-//
-//         xaconn.start();
-//
-//         XASession xasession = xaconn.createXASession();
-//
-//         MessageConsumer consumer = xasession.createConsumer(queue1);
-//
-//         TextMessage messageReceived = (TextMessage)consumer.receive(1000);
-//
-//         assertNotNull(messageReceived);
-//
-//         assertEquals("one", messageReceived.getText());
-//
-//         xasession.recover();
-//
-//         messageReceived = (TextMessage)consumer.receive(1000);
-//
-//         assertEquals("two", messageReceived.getText());
-//
-//         consumer.close();
-//
-//         // I can't call xasession.close for this test as JCA layer would cache the session
-//         // So.. keep this close commented!
-//         //xasession.close();
-//
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(0, count.intValue());
-//      }
-//      finally
-//      {
-//         if (xaconn != null)
-//         {
-//            xaconn.close();
-//         }
-//      }
-//   }
-//
-//   // http://jira.jboss.com/jira/browse/JBMESSAGING-721
-//   public void testConvertFromLocalTx() throws Exception
-//   {
-//      Connection conn = null;
-//
-//      XAConnection xaConn = null;
-//
-//      try
-//      {
-//
-//         //First send some messages to a queue
-//
-//         Integer count = getMessageCountForQueue("Queue1");
-//         assertEquals(0, count.intValue());
-//
-//         conn = cf.createConnection();
-//
-//         Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//
-//         MessageProducer prod = sessSend.createProducer(queue1);
-//
-//         TextMessage tm1 = sessSend.createTextMessage("message1");
-//
-//         TextMessage tm2 = sessSend.createTextMessage("message2");
-//
-//         prod.send(tm1);
-//
-//         prod.send(tm2);
-//
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(2, count.intValue());
-//
-//         xaConn = cf.createXAConnection();
-//
-//         XASession xaSession = xaConn.createXASession();
-//
-//         xaConn.start();
-//
-//         DummyListener listener = new DummyListener();
-//
-//         //We set the distinguised listener so it will convert
-//         xaSession.setMessageListener(listener);
-//
-//         ServerSessionPool pool = new MockServerSessionPool(xaSession);
-//
-//         xaConn.createConnectionConsumer(queue1, null, pool, 1);
-//
-//         Thread.sleep(1000);
-//
-//         assertEquals(2, listener.messages.size());
-//
-//         assertEquals("message1", ((TextMessage)(listener.messages.get(0))).getText());
-//         assertEquals("message2", ((TextMessage)(listener.messages.get(1))).getText());
-//
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(2, count.intValue());
-//
-//         listener.messages.clear();
-//
-//         //Now we enlist the session in an xa transaction
-//
-//         XAResource res = xaSession.getXAResource();
-//
-//         tm.begin();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//         //This should cause the work done previously to be converted into work done in the xa transaction
-//         //this is what an MDB does
-//         //There is a difficulty in transactional delivery with an MDB.
-//         //The message is received from the destination and then sent to the mdb container so
-//         //it can call onMessage.
-//         //For transactional delivery the receipt of the message should be in a transaction but by the time
-//         //the mdb container is invoked the message has already been received it is too late - the message
-//         //has already been received and passed on (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration"
-//         //of Mark Little's book Java Transaction processing
-//         //for a discussion of how different app serves deal with this)
-//         //The way jboss messaging (and jboss mq) deals with this is to convert any work done
-//         //prior to when the xasession is enlisted in the tx, into work done in the xa tx
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         //Now rollback the tx - this should cause redelivery of the two messages
-//         tm.rollback();
-//
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(2, count.intValue());
-//
-//         Thread.sleep(1000);
-//
-//         assertEquals(2, listener.messages.size());
-//
-//         listener.messages.clear();
-//
-//         tm.begin();
-//
-//         tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//         tm.commit();
-//
-//         Thread.sleep(1000);
-//
-//         assertEquals(0, listener.messages.size());
-//
-//         count = getMessageCountForQueue("Queue1");
-//         assertEquals(0, count.intValue());
-//
-//         assertNull(tm.getTransaction());
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//
-//         if (xaConn != null)
-//         {
-//            xaConn.close();
-//         }
-//
-//        /* if (suspended != null)
-//         {
-//            tm.resume(suspended);
-//         }*/
-//      }
-//   }
-//
-//   //http://jira.jboss.com/jira/browse/JBMESSAGING-721
-//   // Note: The behavior of this test was changed after http://jira.jboss.com/jira/browse/JBMESSAGING-946
-//   // When you have a XASession without a transaction enlisted we will behave the same way as non transactedSession, AutoAck
-//   public void testTransactionIdSetAfterCommit() throws Exception
-//   {
-//      Connection conn = null;
-//
-//      XAConnection xaConn = null;
-//
-//      try
-//      {
-//         //First send some messages to a queue
-//
-//         conn = cf.createConnection();
-//
-//         Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//
-//         MessageProducer prod = sessSend.createProducer(queue1);
-//
-//         TextMessage tm1 = sessSend.createTextMessage("message1");
-//
-//         TextMessage tm2 = sessSend.createTextMessage("message2");
-//
-//         prod.send(tm1);
-//
-//         prod.send(tm2);
-//
-//
-//         xaConn = cf.createXAConnection();
-//
-//         XASession xaSession = xaConn.createXASession();
-//
-//         xaConn.start();
-//
-//         MessageConsumer cons = xaSession.createConsumer(queue1);
-//
-//         //Now we enlist the session in an xa transaction
-//
-//         XAResource res = xaSession.getXAResource();
-//
-//         tm.begin();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         //Then we do a commit
-//         tm.commit();
-//
-//         // I have changed where this begin was originally set
-//         // as when you don't have a resource enlisted, XASessions will act as
-//         // non transacted + AutoAck
-//
-//         //And enlist again - this should convert the work done in the local tx
-//         //into the global branch
-//
-//         tx = tm.getTransaction();
-//
-//         tm.begin();
-//
-//         tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//         //Then we receive the messages outside the tx
-//
-//         TextMessage rm1 = (TextMessage)cons.receive(1000);
-//
-//         assertNotNull(rm1);
-//
-//         assertEquals("message1", rm1.getText());
-//
-//         TextMessage rm2 = (TextMessage)cons.receive(1000);
-//
-//         assertNotNull(rm2);
-//
-//         assertEquals("message2", rm2.getText());
-//
-//         Message rm3 = cons.receive(1000);
-//
-//         assertNull(rm3);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         //Now rollback the tx - this should cause redelivery of the two messages
-//         tx.rollback();
-//
-//         rm1 = (TextMessage)cons.receive(1000);
-//
-//         assertNotNull(rm1);
-//
-//         assertEquals("message1", rm1.getText());
-//
-//         rm2 = (TextMessage)cons.receive(1000);
-//
-//         assertNotNull(rm2);
-//
-//         assertEquals("message2", rm2.getText());
-//
-//         rm3 = cons.receive(1000);
-//
-//         assertNull(rm3);
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//
-//         if (xaConn != null)
-//         {
-//            xaConn.close();
-//         }
-//      }
-//
-//   }
-//
-//   //http://jira.jboss.com/jira/browse/JBMESSAGING-721
-//   public void testTransactionIdSetAfterRollback() throws Exception
-//   {
-//      Connection conn = null;
-//
-//      XAConnection xaConn = null;
-//
-//      try
-//      {
-//         //First send some messages to a queue
-//
-//         conn = cf.createConnection();
-//
-//         Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//
-//         MessageProducer prod = sessSend.createProducer(queue1);
-//
-//         TextMessage tm1 = sessSend.createTextMessage("message1");
-//
-//         TextMessage tm2 = sessSend.createTextMessage("message2");
-//
-//         prod.send(tm1);
-//
-//         prod.send(tm2);
-//
-//         xaConn = cf.createXAConnection();
-//
-//         XASession xaSession = xaConn.createXASession();
-//
-//         xaConn.start();
-//
-//         MessageConsumer cons = xaSession.createConsumer(queue1);
-//
-//         //Now we enlist the session in an xa transaction
-//
-//         XAResource res = xaSession.getXAResource();
-//
-//         tm.begin();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         //Then we do a rollback
-//         tm.rollback();
-//
-//         tm.begin();
-//
-//         //And enlist again - the work should then be converted into the global tx branch
-//
-//         // I have changed where this begin was originally set
-//         // as when you don't have a resource enlisted, XASessions will act as
-//         // non transacted + AutoAck
-//
-//         tx = tm.getTransaction();
-//
-//         tx.enlistResource(res);
-//
-//         //Then we receive the messages outside the global tx
-//
-//         TextMessage rm1 = (TextMessage)cons.receive(1000);
-//
-//         assertNotNull(rm1);
-//
-//         assertEquals("message1", rm1.getText());
-//
-//         TextMessage rm2 = (TextMessage)cons.receive(1000);
-//
-//         assertNotNull(rm2);
-//
-//         assertEquals("message2", rm2.getText());
-//
-//         Message rm3 = cons.receive(1000);
-//
-//         assertNull(rm3);
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         //Now rollback the tx - this should cause redelivery of the two messages
-//         tx.rollback();
-//
-//         rm1 = (TextMessage)cons.receive(1000);
-//
-//         assertNotNull(rm1);
-//
-//         assertEquals("message1", rm1.getText());
-//
-//         rm2 = (TextMessage)cons.receive(1000);
-//
-//         assertNotNull(rm2);
-//
-//         assertEquals("message2", rm2.getText());
-//
-//         rm3 = cons.receive(1000);
-//
-//         assertNull(rm3);
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//
-//         if (xaConn != null)
-//         {
-//            xaConn.close();
-//         }
-//      }
-//   }
-//
-//   // See http://jira.jboss.org/jira/browse/JBMESSAGING-825
-//   // Need to test that ids with trailing zeros are dealt with properly - sybase has the habit
-//   // of truncating trailing zeros in varbinary columns
-//   public void testXidsWithTrailingZeros() throws Exception
-//   {
-//      if (!ServerManagement.isRemote())
-//      {
-//         return;
-//      }
-//
-//      XAConnection conn1 = null;
-//
-//      try
-//      {
-//         conn1 = cf.createXAConnection();
-//
-//         XASession sess1 = conn1.createXASession();
-//
-//         XAResource res1 = sess1.getXAResource();
-//
-//         byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
-//
-//         byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
-//
-//         Xid trailing = new MessagingXid(branchQualifier, 12435, globalTxId);
-//
-//         res1.start(trailing, XAResource.TMNOFLAGS);
-//
-//         MessageProducer prod1 = sess1.createProducer(queue1);
-//
-//         TextMessage tm1 = sess1.createTextMessage("testing1");
-//
-//         prod1.send(tm1);
-//
-//         res1.end(trailing, XAResource.TMSUCCESS);
-//
-//         res1.prepare(trailing);
-//
-//         //Now "crash" the server
-//
-//         stopServerPeer();
-//
-//         startServerPeer();
-//
-//         deployAndLookupAdministeredObjects();
-//         
-//         conn1.close();
-//         
-//         conn1 = cf.createXAConnection();
-//
-//         XAResource res = conn1.createXASession().getXAResource();
-//
-//         Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
-//         assertEquals(1, xids.length);
-//
-//         Xid[] xids2 = res.recover(XAResource.TMENDRSCAN);
-//         assertEquals(0, xids2.length);
-//
-//         Xid trailing2 = xids[0];
-//
-//         assertTrue(trailing.getFormatId() == trailing2.getFormatId());
-//
-//         assertEqualByteArrays(trailing.getGlobalTransactionId(), trailing2.getGlobalTransactionId());
-//
-//         assertEqualByteArrays(trailing.getBranchQualifier(), trailing2.getBranchQualifier());
-//
-//         res.commit(trailing, false);
-//      }
-//      finally
-//      {
-//         removeAllMessages(queue1.getQueueName(), true, 0);
-//       
-//         if (conn1 != null)
-//         {
-//            try
-//            {
-//               conn1.close();
-//            }
-//            catch (Exception e)
-//            {
-//               //Ignore
-//            }
-//         }
-//      }
-//   }
-//
-//   public void test2PCSendCommit1PCOptimization() throws Exception
-//   {
-//      //Since both resources have same RM, TM will probably use 1PC optimization
-//
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         XAResource res = sess.getXAResource();
-//
-//         XAResource res2 = new DummyXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         MessageProducer prod = sess.createProducer(queue1);
-//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-//         Message m = sess.createTextMessage("XATest1");
-//         prod.send(queue1, m);
-//         m = sess.createTextMessage("XATest2");
-//         prod.send(queue1, m);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sessReceiver.createConsumer(queue1);
-//         TextMessage m2 = (TextMessage)cons.receive(1000);
-//         assertNotNull(m2);
-//         assertEquals("XATest1", m2.getText());
-//         m2 = (TextMessage)cons.receive(1000);
-//         assertNotNull(m2);
-//         assertEquals("XATest2", m2.getText());
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//
-//
-//   public void test2PCSendCommit() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//
-//         MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
-//         XAResource res2 = new DummyXAResource();
-//
-//         //To prevent 1PC optimization being used
-//         res.setPreventJoining(true);
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         MessageProducer prod = sess.createProducer(queue1);
-//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-//         Message m = sess.createTextMessage("XATest1");
-//         prod.send(queue1, m);
-//         m = sess.createTextMessage("XATest2");
-//         prod.send(queue1, m);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         log.info("Committing***");
-//         tm.commit();
-//         log.info("Committed****");
-//
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sessReceiver.createConsumer(queue1);
-//         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m2);
-//         assertEquals("XATest1", m2.getText());
-//         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m2);
-//         assertEquals("XATest2", m2.getText());
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//
-//   public void test2PCSendRollback1PCOptimization() throws Exception
-//   {
-//      //Since both resources have some RM, TM will probably use 1PC optimization
-//
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         XAResource res = sess.getXAResource();
-//
-//         XAResource res2 = new DummyXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         MessageProducer prod = sess.createProducer(queue1);
-//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-//         Message m = sess.createTextMessage("XATest1");
-//         prod.send(queue1, m);
-//         m = sess.createTextMessage("XATest2");
-//         prod.send(queue1, m);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.rollback();
-//
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sessReceiver.createConsumer(queue1);
-//         Message m2 = cons.receive(MIN_TIMEOUT);
-//         assertNull(m2);
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//
-//   public void test2PCSendFailOnPrepare() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
-//
-//         //prevent 1Pc optimisation
-//         res.setPreventJoining(true);
-//
-//         XAResource res2 = new DummyXAResource(true);
-//         XAResource res3 = new DummyXAResource();
-//         XAResource res4 = new DummyXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//         tx.enlistResource(res3);
-//         tx.enlistResource(res4);
-//
-//         MessageProducer prod = sess.createProducer(queue1);
-//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-//         Message m = sess.createTextMessage("XATest1");
-//         prod.send(queue1, m);
-//         m = sess.createTextMessage("XATest2");
-//         prod.send(queue1, m);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//         tx.delistResource(res3, XAResource.TMSUCCESS);
-//         tx.delistResource(res4, XAResource.TMSUCCESS);
-//
-//         try
-//         {
-//            tm.commit();
-//
-//            fail("should not get here");
-//         }
-//         catch (Exception e)
-//         {
-//            //We should expect this
-//         }
-//
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sessReceiver.createConsumer(queue1);
-//         Message m2 = cons.receive(MIN_TIMEOUT);
-//         assertNull(m2);
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//   public void test2PCSendRollback() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
-//
-//         //prevent 1Pc optimisation
-//         res.setPreventJoining(true);
-//
-//         XAResource res2 = new DummyXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         MessageProducer prod = sess.createProducer(queue1);
-//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-//         Message m = sess.createTextMessage("XATest1");
-//         prod.send(queue1, m);
-//         m = sess.createTextMessage("XATest2");
-//         prod.send(queue1, m);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.rollback();
-//
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sessReceiver.createConsumer(queue1);
-//         Message m2 = cons.receive(MIN_TIMEOUT);
-//         assertNull(m2);
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//   public void test2PCReceiveCommit1PCOptimization() throws Exception
-//   {
-//      //Since both resources have some RM, TM will probably use 1PC optimization
-//
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("XATest1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("XATest2");
-//         prod.send(m);
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         XAResource res = sess.getXAResource();
-//
-//         XAResource res2 = new DummyXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//
-//
-//         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m2);
-//         assertEquals("XATest1", m2.getText());
-//
-//         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m2);
-//         assertEquals("XATest2", m2.getText());
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//
-//         //New tx
-//         tm.begin();
-//         tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         Message m3 = cons.receive(MIN_TIMEOUT);
-//
-//         assertNull(m3);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//   public void test2PCReceiveCommit() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("XATest1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("XATest2");
-//         prod.send(m);
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
-//         res.setPreventJoining(true);
-//
-//         XAResource res2 = new DummyXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//
-//
-//         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m2);
-//         assertEquals("XATest1", m2.getText());
-//
-//         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m2);
-//         assertEquals("XATest2", m2.getText());
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//
-//         //New tx
-//         tm.begin();
-//         tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         Message m3 = cons.receive(MIN_TIMEOUT);
-//
-//         assertNull(m3);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//   public void test2PCReceiveRollback1PCOptimization() throws Exception
-//   {
-//      //Since both resources have some RM, TM will probably use 1PC optimization
-//
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("XATest1");
-//         prod.send(m);
-//
-//         m = sessProducer.createTextMessage("XATest2");
-//         prod.send(m);
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         XAResource res = sess.getXAResource();
-//
-//         XAResource res2 = new DummyXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//
-//
-//         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m2);
-//         assertEquals("XATest1", m2.getText());
-//         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m2);
-//         assertEquals("XATest2", m2.getText());
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.rollback();
-//
-//         //Message should be redelivered
-//
-//         //New tx
-//         tm.begin();
-//         tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m3);
-//         assertEquals("XATest1", m3.getText());
-//         m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m3);
-//         assertEquals("XATest2", m3.getText());
-//
-//         assertTrue(m3.getJMSRedelivered());
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//   public void test2PCReceiveRollback() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("XATest1");
-//         prod.send(m);
-//
-//         m = sessProducer.createTextMessage("XATest2");
-//         prod.send(m);
-//
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
-//         res.setPreventJoining(true);
-//
-//         XAResource res2 = new DummyXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//
-//
-//         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m2);
-//         assertEquals("XATest1", m2.getText());
-//         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m2);
-//         assertEquals("XATest2", m2.getText());
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.rollback();
-//
-//         //Message should be redelivered
-//
-//         //New tx
-//         tm.begin();
-//         tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//         tx.enlistResource(res2);
-//
-//         TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m3);
-//         assertEquals("XATest1", m3.getText());
-//         m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m3);
-//         assertEquals("XATest2", m3.getText());
-//
-//         assertTrue(m3.getJMSRedelivered());
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//
-//   public void test1PCSendCommit() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         XAResource res = sess.getXAResource();
-//
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//
-//         MessageProducer prod = sess.createProducer(queue1);
-//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-//         Message m = sess.createTextMessage("XATest1");
-//         prod.send(queue1, m);
-//         m = sess.createTextMessage("XATest2");
-//         prod.send(queue1, m);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sessReceiver.createConsumer(queue1);
-//         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m2);
-//         assertEquals("XATest1", m2.getText());
-//         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(m2);
-//         assertEquals("XATest2", m2.getText());
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//
-//   public void test1PCSendRollback() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         XAResource res = sess.getXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//         MessageProducer prod = sess.createProducer(queue1);
-//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-//         Message m = sess.createTextMessage("XATest1");
-//         prod.send(queue1, m);
-//         m = sess.createTextMessage("XATest2");
-//         prod.send(queue1, m);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         tm.rollback();
-//
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sessReceiver.createConsumer(queue1);
-//         Message m2 = cons.receive(MIN_TIMEOUT);
-//         assertNull(m2);
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//   public void test1PCReceiveCommit() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn2 = cf.createConnection();
-//         conn2.start();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("XATest1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("XATest2");
-//         prod.send(m);
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         XAResource res = sess.getXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//
-//
-//         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m2);
-//         assertEquals("XATest1", m2.getText());
-//         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m2);
-//         assertEquals("XATest2", m2.getText());
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//
-//         //New tx
-//         tm.begin();
-//         tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//         Message m3 = cons.receive(MIN_TIMEOUT);
-//
-//         assertNull(m3);
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//   public void test1PCReceiveRollback() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("XATest1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("XATest2");
-//         prod.send(m);
-//
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         XASession sess = conn.createXASession();
-//         XAResource res = sess.getXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//
-//
-//         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m2);
-//         assertEquals("XATest1", m2.getText());
-//
-//         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m2);
-//         assertEquals("XATest2", m2.getText());
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         tm.rollback();
-//
-//         //Message should be redelivered
-//
-//         //New tx
-//         tm.begin();
-//         tx = tm.getTransaction();
-//         tx.enlistResource(res);
-//
-//         TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m3);
-//         assertEquals("XATest1", m3.getText());
-//
-//         m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(m3);
-//         assertEquals("XATest2", m3.getText());
-//
-//         assertTrue(m3.getJMSRedelivered());
-//
-//         tx.delistResource(res, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//   public void testMultipleSessionsOneTxCommitAcknowledge1PCOptimization() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      //Since both resources have some RM, TM will probably use 1PC optimization
-//
-//      try
-//      {
-//         //First send 2 messages
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("jellyfish1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish2");
-//         prod.send(m);
-//
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         //Create 2 sessions and enlist them
-//         XASession sess1 = conn.createXASession();
-//         XAResource res1 = sess1.getXAResource();
-//         XASession sess2 = conn.createXASession();
-//         XAResource res2 = sess2.getXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res1);
-//         tx.enlistResource(res2);
-//
-//         //Receive the messages, one on each consumer
-//         MessageConsumer cons1 = sess1.createConsumer(queue1);
-//         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish1", r1.getText());
-//
-//         cons1.close();
-//
-//         MessageConsumer cons2 = sess2.createConsumer(queue1);
-//         TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r2);
-//         assertEquals("jellyfish2", r2.getText());
-//
-//         tx.delistResource(res1, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         //commit
-//         tm.commit();
-//
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         conn2.start();
-//
-//         TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
-//         assertNull(r3);
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//   public void testMultipleSessionsOneTxCommitAcknowledge() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         //First send 2 messages
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("jellyfish1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish2");
-//         prod.send(m);
-//
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         //Create 2 sessions and enlist them
-//         XASession sess1 = conn.createXASession();
-//         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
-//         XASession sess2 = conn.createXASession();
-//         MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
-//         res1.setPreventJoining(true);
-//         res2.setPreventJoining(true);
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res1);
-//         tx.enlistResource(res2);
-//
-//         //Receive the messages, one on each consumer
-//         MessageConsumer cons1 = sess1.createConsumer(queue1);
-//         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish1", r1.getText());
-//
-//         cons1.close();
-//
-//         MessageConsumer cons2 = sess2.createConsumer(queue1);
-//         TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r2);
-//         assertEquals("jellyfish2", r2.getText());
-//
-//         tx.delistResource(res1, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         //commit
-//         tm.commit();
-//
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         conn2.start();
-//
-//         TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
-//         assertNull(r3);
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//
-//   public void testMultipleSessionsOneTxRollbackAcknowledge1PCOptimization() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      //Since both resources have some RM, TM will probably use 1PC optimization
-//
-//      try
-//      {
-//         //First send 2 messages
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("jellyfish1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish2");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish3");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish4");
-//         prod.send(m);
-//
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         //Create 2 sessions and enlist them
-//         XASession sess1 = conn.createXASession();
-//         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
-//         XASession sess2 = conn.createXASession();
-//         MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res1);
-//         tx.enlistResource(res2);
-//
-//         //Receive the messages, two on each consumer
-//         MessageConsumer cons1 = sess1.createConsumer(queue1);
-//         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish1", r1.getText());
-//
-//         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish2", r1.getText());
-//
-//         cons1.close();
-//
-//         MessageConsumer cons2 = sess2.createConsumer(queue1);
-//         TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r2);
-//         assertEquals("jellyfish3", r2.getText());
-//
-//         r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r2);
-//         assertEquals("jellyfish4", r2.getText());
-//
-//         cons2.close();
-//
-//         //rollback
-//
-//         tx.delistResource(res1, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.rollback();
-//
-//         //Rollback causes cancel which is asynch
-//         Thread.sleep(1000);
-//
-//         //We cannot assume anything about the order in which the transaction manager rollsback
-//         //the sessions - this is implementation dependent
-//
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         conn2.start();
-//
-//         TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r);
-//
-//         boolean session1First = false;
-//
-//         if (r.getText().equals("jellyfish1"))
-//         {
-//            session1First = true;
-//         }
-//         else if (r.getText().equals("jellyfish3"))
-//         {
-//            session1First = false;
-//         }
-//         else
-//         {
-//            fail("Unexpected message");
-//         }
-//
-//         if (session1First)
-//         {
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish2", r.getText());
-//
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish3", r.getText());
-//
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish4", r.getText());
-//
-//
-//         }
-//         else
-//         {
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish4", r.getText());
-//
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish1", r.getText());
-//
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish2", r.getText());
-//         }
-//
-//         r = (TextMessage)cons.receive(MIN_TIMEOUT);
-//
-//         assertNull(r);
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//   public void testMultipleSessionsOneTxRollbackAcknowledge() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         //First send 2 messages
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("jellyfish1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish2");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish3");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish4");
-//         prod.send(m);
-//
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         //Create 2 sessions and enlist them
-//         XASession sess1 = conn.createXASession();
-//         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
-//         XASession sess2 = conn.createXASession();
-//         MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
-//         res1.setPreventJoining(true);
-//         res2.setPreventJoining(true);
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res1);
-//         tx.enlistResource(res2);
-//
-//         //Receive the messages, two on each consumer
-//         MessageConsumer cons1 = sess1.createConsumer(queue1);
-//         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish1", r1.getText());
-//
-//         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish2", r1.getText());
-//
-//         cons1.close();
-//
-//         //Cancel is asynch
-//         Thread.sleep(500);
-//
-//         MessageConsumer cons2 = sess2.createConsumer(queue1);
-//         TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r2);
-//         assertEquals("jellyfish3", r2.getText());
-//
-//         r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r2);
-//         assertEquals("jellyfish4", r2.getText());
-//
-//         //rollback
-//
-//         cons2.close();
-//
-//         tx.delistResource(res1, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         tm.rollback();
-//
-//         // Rollback causes cancel which is asynch
-//         Thread.sleep(1000);
-//
-//         //We cannot assume anything about the order in which the transaction manager rollsback
-//         //the sessions - this is implementation dependent
-//
-//
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         conn2.start();
-//
-//         TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r);
-//
-//         boolean session1First = false;
-//
-//         if (r.getText().equals("jellyfish1"))
-//         {
-//            session1First = true;
-//         }
-//         else if (r.getText().equals("jellyfish3"))
-//         {
-//            session1First = false;
-//         }
-//         else
-//         {
-//            fail("Unexpected message");
-//         }
-//
-//         if (session1First)
-//         {
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish2", r.getText());
-//
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish3", r.getText());
-//
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish4", r.getText());
-//
-//
-//         }
-//         else
-//         {
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish4", r.getText());
-//
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish1", r.getText());
-//
-//            r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//            assertNotNull(r);
-//
-//            assertEquals("jellyfish2", r.getText());
-//         }
-//
-//         r = (TextMessage)cons.receive(MIN_TIMEOUT);
-//
-//         assertNull(r);
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//   public void testMultipleSessionsOneTxRollbackAcknowledgeForceFailureInCommit() throws Exception
-//   {
-//      XAConnection conn = null;
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         //First send 4 messages
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//
-//         Message m = sessProducer.createTextMessage("jellyfish1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish2");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish3");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish4");
-//         prod.send(m);
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         XASession sess1 = conn.createXASession();
-//         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
-//         DummyXAResource res2 = new DummyXAResource(true);
-//         res1.setPreventJoining(true);
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res1);
-//         tx.enlistResource(res2);
-//
-//         MessageConsumer cons1 = sess1.createConsumer(queue1);
-//         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish1", r1.getText());
-//
-//         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish2", r1.getText());
-//
-//         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish3", r1.getText());
-//
-//         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r1);
-//         assertEquals("jellyfish4", r1.getText());
-//
-//         r1 = (TextMessage)cons1.receive(1000);
-//
-//         assertNull(r1);
-//
-//         cons1.close();
-//
-//
-//         //try and commit - and we're going to make the dummyxaresource throw an exception on commit,
-//         //which should cause rollback to be called on the other resource
-//
-//         tx.delistResource(res1, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         //rollback will cause an attemp to deliver messages locally to the original consumers.
-//         //the original consumer has closed, so it will cancelled to the server
-//         //the server cancel is asynch, so we need to sleep for a bit to make sure it completes
-//         log.trace("Forcing failure");
-//         try
-//         {
-//            tm.commit();
-//            fail("should not get here");
-//         }
-//         catch (Exception e)
-//         {
-//            //We should expect this
-//         }
-//
-//         Thread.sleep(1000);
-//
-//
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         conn2.start();
-//
-//         TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r);
-//
-//         assertEquals("jellyfish1", r.getText());
-//
-//         r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r);
-//
-//         assertEquals("jellyfish2", r.getText());
-//
-//         r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r);
-//
-//         assertEquals("jellyfish3", r.getText());
-//
-//         r = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r);
-//
-//         assertEquals("jellyfish4", r.getText());
-//
-//         r = (TextMessage)cons.receive(MIN_TIMEOUT);
-//
-//         assertNull(r);
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//
-//   }
-//
-//   public void testMultipleSessionsOneTxCommitSend1PCOptimization() throws Exception
-//   {
-//      //Since both resources have some RM, TM will probably use 1PC optimization
-//
-//      XAConnection conn = null;
-//
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         //Create 2 sessions and enlist them
-//         XASession sess1 = conn.createXASession();
-//         XAResource res1 = sess1.getXAResource();
-//         XASession sess2 = conn.createXASession();
-//         XAResource res2 = sess2.getXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res1);
-//         tx.enlistResource(res2);
-//
-//         // Send 2 messages - one from each session
-//
-//         MessageProducer prod1 = sess1.createProducer(queue1);
-//         MessageProducer prod2 = sess2.createProducer(queue1);
-//
-//         prod1.send(sess1.createTextMessage("echidna1"));
-//         prod2.send(sess2.createTextMessage("echidna2"));
-//
-//         tx.delistResource(res1, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         //commit
-//         tm.commit();
-//
-//         //Messages should be in queue
-//
-//         conn2 = cf.createConnection();
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         conn2.start();
-//
-//         TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r1);
-//         assertEquals("echidna1", r1.getText());
-//
-//         TextMessage r2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r2);
-//         assertEquals("echidna2", r2.getText());
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//   public void testMultipleSessionsOneTxCommitSend() throws Exception
-//   {
-//      //Since both resources have some RM, TM will probably use 1PC optimization
-//
-//      XAConnection conn = null;
-//
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         //Create 2 sessions and enlist them
-//         XASession sess1 = conn.createXASession();
-//         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
-//         XASession sess2 = conn.createXASession();
-//         MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
-//         res1.setPreventJoining(true);
-//         res2.setPreventJoining(true);
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res1);
-//         tx.enlistResource(res2);
-//
-//         // Send 2 messages - one from each session
-//
-//         MessageProducer prod1 = sess1.createProducer(queue1);
-//         MessageProducer prod2 = sess2.createProducer(queue1);
-//
-//         prod1.send(sess1.createTextMessage("echidna1"));
-//         prod2.send(sess2.createTextMessage("echidna2"));
-//
-//         tx.delistResource(res1, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         //commit
-//         tm.commit();
-//
-//         //Messages should be in queue
-//
-//         conn2 = cf.createConnection();
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         conn2.start();
-//
-//         TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r1);
-//         assertEquals("echidna1", r1.getText());
-//
-//         TextMessage r2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r2);
-//         assertEquals("echidna2", r2.getText());
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//
-//      }
-//
-//   }
-//
-//
-//   public void testMultipleSessionsOneTxRollbackSend1PCOptimization() throws Exception
-//   {
-//      //Since both resources have some RM, TM will probably use 1PC optimization
-//
-//      XAConnection conn = null;
-//
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         //Create 2 sessions and enlist them
-//         XASession sess1 = conn.createXASession();
-//         XAResource res1 = sess1.getXAResource();
-//         XASession sess2 = conn.createXASession();
-//         XAResource res2 = sess2.getXAResource();
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res1);
-//         tx.enlistResource(res2);
-//
-//         // Send 2 messages - one from each session
-//
-//         MessageProducer prod1 = sess1.createProducer(queue1);
-//         MessageProducer prod2 = sess2.createProducer(queue1);
-//
-//         prod1.send(sess1.createTextMessage("echidna1"));
-//         prod2.send(sess2.createTextMessage("echidna2"));
-//
-//         tx.delistResource(res1, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         //rollback
-//         tm.rollback();
-//
-//         //Messages should not be in queue
-//
-//         conn2 = cf.createConnection();
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         conn2.start();
-//
-//         TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
-//         assertNull(r1);
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//   public void testMultipleSessionsOneTxRollbackSend() throws Exception
-//   {
-//      XAConnection conn = null;
-//
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//
-//         conn = cf.createXAConnection();
-//         conn.start();
-//
-//         tm.begin();
-//
-//         //Create 2 sessions and enlist them
-//         XASession sess1 = conn.createXASession();
-//         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
-//         XASession sess2 = conn.createXASession();
-//         MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
-//         res1.setPreventJoining(true);
-//         res2.setPreventJoining(true);
-//
-//         Transaction tx = tm.getTransaction();
-//         tx.enlistResource(res1);
-//         tx.enlistResource(res2);
-//
-//         // Send 2 messages - one from each session
-//
-//         MessageProducer prod1 = sess1.createProducer(queue1);
-//         MessageProducer prod2 = sess2.createProducer(queue1);
-//
-//         prod1.send(sess1.createTextMessage("echidna1"));
-//         prod2.send(sess2.createTextMessage("echidna2"));
-//
-//         tx.delistResource(res1, XAResource.TMSUCCESS);
-//         tx.delistResource(res2, XAResource.TMSUCCESS);
-//
-//         //rollback
-//         tm.rollback();
-//
-//         //Messages should not be in queue
-//
-//         conn2 = cf.createConnection();
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         conn2.start();
-//
-//         TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
-//         assertNull(r1);
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//
-//   public void testOneSessionTwoTransactionsCommitAcknowledge() throws Exception
-//   {
-//      XAConnection conn = null;
-//
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         //First send 2 messages
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("jellyfish1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish2");
-//         prod.send(m);
-//
-//         conn = cf.createXAConnection();
-//
-//         //Create a session
-//         XASession sess1 = conn.createXASession();
-//         XAResource res1 = sess1.getXAResource();
-//
-//         conn.start();
-//         MessageConsumer cons1 = sess1.createConsumer(queue1);
-//
-//         tm.begin();
-//
-//         Transaction tx1 = tm.getTransaction();
-//         tx1.enlistResource(res1);
-//
-//         //Receive one message in one tx
-//
-//         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//         assertNotNull(r1);
-//         assertEquals("jellyfish1", r1.getText());
-//
-//         //suspend the tx
-//         Transaction suspended = tm.suspend();
-//
-//         tm.begin();
-//
-//         Transaction tx2 = tm.getTransaction();
-//         tx2.enlistResource(res1);
-//
-//         //Receive 2nd message in a different tx
-//         TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//         assertNotNull(r2);
-//         assertEquals("jellyfish2", r2.getText());
-//
-//         tx2.delistResource(res1, XAResource.TMSUCCESS);
-//
-//         //commit this transaction
-//         tm.commit();
-//
-//         //verify that no messages are available
-//         conn2.close();
-//         conn2 = cf.createConnection();
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         conn2.start();
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
-//         assertNull(r3);
-//
-//         //now resume the first tx and then commit it
-//         tm.resume(suspended);
-//
-//         tx1.delistResource(res1, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//      }
-//   }
-//
-//
-//   public void testOneSessionTwoTransactionsRollbackAcknowledge() throws Exception
-//   {
-//      XAConnection conn = null;
-//
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         //First send 2 messages
-//         conn2 = cf.createConnection();
-//         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         MessageProducer prod  = sessProducer.createProducer(queue1);
-//         Message m = sessProducer.createTextMessage("jellyfish1");
-//         prod.send(m);
-//         m = sessProducer.createTextMessage("jellyfish2");
-//         prod.send(m);
-//
-//         conn = cf.createXAConnection();
-//
-//         //Create a session
-//         XASession sess1 = conn.createXASession();
-//         XAResource res1 = sess1.getXAResource();
-//
-//         conn.start();
-//         MessageConsumer cons1 = sess1.createConsumer(queue1);
-//
-//         tm.begin();
-//
-//         Transaction tx1 = tm.getTransaction();
-//         tx1.enlistResource(res1);
-//
-//         //Receive one message in one tx
-//
-//         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//         assertNotNull(r1);
-//         assertEquals("jellyfish1", r1.getText());
-//
-//         //suspend the tx
-//         Transaction suspended = tm.suspend();
-//
-//         tm.begin();
-//
-//         Transaction tx2 = tm.getTransaction();
-//         tx2.enlistResource(res1);
-//
-//         //Receive 2nd message in a different tx
-//         TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-//         assertNotNull(r2);
-//         assertEquals("jellyfish2", r2.getText());
-//
-//         cons1.close();
-//
-//         tx1.delistResource(res1, XAResource.TMSUCCESS);
-//
-//         //rollback this transaction
-//         tm.rollback();
-//
-//         //verify that second message is available
-//         conn2.close();
-//         conn2 = cf.createConnection();
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         conn2.start();
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//
-//         TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//
-//         assertNotNull(r3);
-//         assertEquals("jellyfish2", r3.getText());
-//         r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
-//         assertNull(r3);
-//
-//
-//         //rollback the other tx
-//         tm.resume(suspended);
-//         tm.rollback();
-//
-//         //Verify the first message is now available
-//         r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r3);
-//         assertEquals("jellyfish1", r3.getText());
-//         r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
-//         assertNull(r3);
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//
-//      }
-//
-//   }
-//
-//
-//   public void testOneSessionTwoTransactionsCommitSend() throws Exception
-//   {
-//      XAConnection conn = null;
-//
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//         conn = cf.createXAConnection();
-//
-//         //Create a session
-//         XASession sess1 = conn.createXASession();
-//         XAResource res1 = sess1.getXAResource();
-//
-//         MessageProducer prod1 = sess1.createProducer(queue1);
-//
-//         tm.begin();
-//
-//         Transaction tx1 = tm.getTransaction();
-//         tx1.enlistResource(res1);
-//
-//         //Send a message
-//         prod1.send(sess1.createTextMessage("kangaroo1"));
-//
-//         //suspend the tx
-//         Transaction suspended = tm.suspend();
-//
-//         tm.begin();
-//
-//         //Send another message in another tx using the same session
-//         Transaction tx2 = tm.getTransaction();
-//         tx2.enlistResource(res1);
-//
-//         //Send a message
-//         prod1.send(sess1.createTextMessage("kangaroo2"));
-//
-//         tx2.delistResource(res1, XAResource.TMSUCCESS);
-//
-//         //commit this transaction
-//         tm.commit();
-//
-//         //verify only kangaroo2 message is sent
-//         conn2 = cf.createConnection();
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         conn2.start();
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r1);
-//         assertEquals("kangaroo2", r1.getText());
-//         TextMessage r2 = (TextMessage)cons.receive(MIN_TIMEOUT);
-//         assertNull(r2);
-//
-//         //now resume the first tx and then commit it
-//         tm.resume(suspended);
-//
-//         tx1.delistResource(res1, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//
-//         //verify that the first text message is received
-//         TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r3);
-//         assertEquals("kangaroo1", r3.getText());
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//
-//      }
-//
-//   }
-//
-//
-//   public void testOneSessionTwoTransactionsRollbackSend() throws Exception
-//   {
-//      XAConnection conn = null;
-//
-//      Connection conn2 = null;
-//
-//      try
-//      {
-//
-//         conn = cf.createXAConnection();
-//
-//         //Create a session
-//         XASession sess1 = conn.createXASession();
-//         XAResource res1 = sess1.getXAResource();
-//
-//         MessageProducer prod1 = sess1.createProducer(queue1);
-//
-//         tm.begin();
-//
-//         Transaction tx1 = tm.getTransaction();
-//         tx1.enlistResource(res1);
-//
-//         //Send a message
-//         prod1.send(sess1.createTextMessage("kangaroo1"));
-//
-//         //suspend the tx
-//         Transaction suspended = tm.suspend();
-//
-//         tm.begin();
-//
-//         //Send another message in another tx using the same session
-//         Transaction tx2 = tm.getTransaction();
-//         tx2.enlistResource(res1);
-//
-//         //Send a message
-//         prod1.send(sess1.createTextMessage("kangaroo2"));
-//
-//         tx2.delistResource(res1, XAResource.TMSUCCESS);
-//
-//         //rollback this transaction
-//         tm.rollback();
-//
-//         //verify no messages are sent
-//         conn2 = cf.createConnection();
-//         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-//         conn2.start();
-//         MessageConsumer cons = sess.createConsumer(queue1);
-//         TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
-//
-//         assertNull(r1);
-//
-//
-//         //now resume the first tx and then commit it
-//         tm.resume(suspended);
-//
-//         tx1.delistResource(res1, XAResource.TMSUCCESS);
-//
-//         tm.commit();
-//
-//         //verify that the first text message is received
-//         TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-//         assertNotNull(r3);
-//         assertEquals("kangaroo1", r3.getText());
-//
-//      }
-//      finally
-//      {
-//         if (conn != null)
-//         {
-//            conn.close();
-//         }
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//
-//      }
-//
-//   }
-//
-//   // Package protected ---------------------------------------------
-//
-//   // Protected -----------------------------------------------------
-//
-//   // Private -------------------------------------------------------
-//
-//   private void assertEqualByteArrays(byte[] b1, byte[] b2)
-//   {
-//      log.info("b1 length: " + b1.length + " b2 length " + b2.length);
-//
-//      if (b1.length != b2.length)
-//      {
-//         fail("Lengths not the same");
-//      }
-//
-//      for (int i = 0; i < b1.length; i++)
-//      {
-//         if (b1[i] != b2[i])
-//         {
-//            fail("Not same at index " + i);
-//         }
-//      }
-//   }
-//
-//   // Inner classes -------------------------------------------------
-//
-//
-//   static class DummyListener implements MessageListener
-//   {
-//
-//      protected Logger log = Logger.getLogger(getClass());
-//
-//      public ArrayList messages = new ArrayList();
-//
-//      public void onMessage(Message message)
-//      {
-//         log.info("Message received on DummyListener " + message);
-//         messages.add(message);
-//      }
-//   }
-//
-//   static class MockServerSessionPool implements ServerSessionPool
-//   {
-//      private ServerSession serverSession;
-//
-//      MockServerSessionPool(Session sess)
-//      {
-//         serverSession = new MockServerSession(sess);
-//      }
-//
-//      public ServerSession getServerSession() throws JMSException
-//      {
-//         return serverSession;
-//      }
-//   }
-//
-//   static class MockServerSession implements ServerSession
-//   {
-//      Session session;
-//
-//      MockServerSession(Session sess)
-//      {
-//         this.session = sess;
-//      }
-//
-//
-//      public Session getSession() throws JMSException
-//      {
-//         return session;
-//      }
-//
-//      public void start() throws JMSException
-//      {
-//         session.run();
-//      }
-//
-//   }
-//
-//
-//
-//   static class DummyXAResource implements XAResource
-//   {
-//      boolean failOnPrepare;
-//
-//      DummyXAResource()
-//      {
-//      }
-//
-//      DummyXAResource(boolean failOnPrepare)
-//      {
-//         this.failOnPrepare = failOnPrepare;
-//      }
-//
-//      public void commit(Xid arg0, boolean arg1) throws XAException
-//      {
-//      }
-//
-//      public void end(Xid arg0, int arg1) throws XAException
-//      {
-//      }
-//
-//      public void forget(Xid arg0) throws XAException
-//      {
-//      }
-//
-//      public int getTransactionTimeout() throws XAException
-//      {
-//          return 0;
-//      }
-//
-//      public boolean isSameRM(XAResource arg0) throws XAException
-//      {
-//         return false;
-//      }
-//
-//      public int prepare(Xid arg0) throws XAException
-//      {
-//         if (failOnPrepare)
-//         {
-//            throw new XAException(XAException.XAER_RMFAIL);
-//         }
-//         return XAResource.XA_OK;
-//      }
-//
-//      public Xid[] recover(int arg0) throws XAException
-//      {
-//         return null;
-//      }
-//
-//      public void rollback(Xid arg0) throws XAException
-//      {
-//      }
-//
-//      public boolean setTransactionTimeout(int arg0) throws XAException
-//      {
-//         return false;
-//      }
-//
-//      public void start(Xid arg0, int arg1) throws XAException
-//      {
-//
-//      }
-//
-//   }
 
+
+   // See http://jira.jboss.org/jira/browse/JBMESSAGING-825
+   // Need to test that ids with trailing zeros are dealt with properly - sybase has the habit
+   // of truncating trailing zeros in varbinary columns
+   public void testXidsWithTrailingZeros() throws Exception
+   {
+      if (!ServerManagement.isRemote())
+      {
+         return;
+      }
+
+      XAConnection conn1 = null;
+
+      try
+      {
+         conn1 = cf.createXAConnection();
+
+         XASession sess1 = conn1.createXASession();
+
+         XAResource res1 = sess1.getXAResource();
+
+         byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
+
+         byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
+
+         Xid trailing = new XidImpl(branchQualifier, 12435, globalTxId);
+
+         res1.start(trailing, XAResource.TMNOFLAGS);
+
+         MessageProducer prod1 = sess1.createProducer(queue1);
+
+         TextMessage tm1 = sess1.createTextMessage("testing1");
+
+         prod1.send(tm1);
+
+         res1.end(trailing, XAResource.TMSUCCESS);
+
+         res1.prepare(trailing);
+
+         //Now "crash" the server
+
+         stopServerPeer();
+
+         startServerPeer();
+
+         deployAndLookupAdministeredObjects();
+         
+         conn1.close();
+         
+         conn1 = cf.createXAConnection();
+
+         XAResource res = conn1.createXASession().getXAResource();
+
+         Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
+         assertEquals(1, xids.length);
+
+         Xid[] xids2 = res.recover(XAResource.TMENDRSCAN);
+         assertEquals(0, xids2.length);
+
+         Xid trailing2 = xids[0];
+
+         assertTrue(trailing.getFormatId() == trailing2.getFormatId());
+
+         assertEqualByteArrays(trailing.getGlobalTransactionId(), trailing2.getGlobalTransactionId());
+
+         assertEqualByteArrays(trailing.getBranchQualifier(), trailing2.getBranchQualifier());
+
+         res.commit(trailing, false);
+      }
+      finally
+      {
+         removeAllMessages(queue1.getQueueName(), true, 0);
+       
+         if (conn1 != null)
+         {
+            try
+            {
+               conn1.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+      }
+   }
+
+   public void test2PCSendCommit1PCOptimization() throws Exception
+   {
+      //Since both resources have same RM, TM will probably use 1PC optimization
+
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         conn = cf.createXAConnection();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+         XAResource res2 = new DummyXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         MessageProducer prod = sess.createProducer(queue1);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         Message m = sess.createTextMessage("XATest1");
+         prod.send(queue1, m);
+         m = sess.createTextMessage("XATest2");
+         prod.send(queue1, m);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.commit();
+
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sessReceiver.createConsumer(queue1);
+         TextMessage m2 = (TextMessage)cons.receive(1000);
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+         m2 = (TextMessage)cons.receive(1000);
+         assertNotNull(m2);
+         assertEquals("XATest2", m2.getText());
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+
+
+   public void test2PCSendCommit() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         conn = cf.createXAConnection();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+
+         XAResource res = sess.getXAResource();
+         XAResource res2 = new DummyXAResource();
+
+         //To prevent 1PC optimization being used
+         //res.setForceNotSameRM(true);
+
+         Transaction tx = tm.getTransaction();
+         
+         log.info("res is " + res);
+         log.info("res2 is " + res2);
+         
+         log.info("Enlisting reousrce1");
+         tx.enlistResource(res);
+                           
+         log.info("enlisting resource2");
+         tx.enlistResource(res2);
+
+         MessageProducer prod = sess.createProducer(queue1);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         Message m = sess.createTextMessage("XATest1");
+         prod.send(queue1, m);
+         m = sess.createTextMessage("XATest2");
+         prod.send(queue1, m);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         log.info("Committing***");
+         tm.commit();
+         log.info("Committed****");
+
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sessReceiver.createConsumer(queue1);
+         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m2);
+         assertEquals("XATest2", m2.getText());
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+
+   public void test2PCSendRollback1PCOptimization() throws Exception
+   {
+      //Since both resources have some RM, TM will probably use 1PC optimization
+
+      XAConnection conn = null;
+      Connection conn2 = null;
+      try
+      {
+         conn = cf.createXAConnection();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+         XAResource res2 = new DummyXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         MessageProducer prod = sess.createProducer(queue1);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         Message m = sess.createTextMessage("XATest1");
+         prod.send(queue1, m);
+         m = sess.createTextMessage("XATest2");
+         prod.send(queue1, m);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.rollback();
+
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sessReceiver.createConsumer(queue1);
+         Message m2 = cons.receive(MIN_TIMEOUT);
+         assertNull(m2);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+
+   public void test2PCSendFailOnPrepare() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+      try
+      {
+         conn = cf.createXAConnection();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+         //prevent 1Pc optimisation
+         //res.setForceNotSameRM(true);
+
+         XAResource res2 = new DummyXAResource(true);
+         XAResource res3 = new DummyXAResource();
+         XAResource res4 = new DummyXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+         tx.enlistResource(res3);
+         tx.enlistResource(res4);
+
+         MessageProducer prod = sess.createProducer(queue1);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         Message m = sess.createTextMessage("XATest1");
+         prod.send(queue1, m);
+         m = sess.createTextMessage("XATest2");
+         prod.send(queue1, m);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+         tx.delistResource(res3, XAResource.TMSUCCESS);
+         tx.delistResource(res4, XAResource.TMSUCCESS);
+
+         try
+         {
+            tm.commit();
+
+            fail("should not get here");
+         }
+         catch (Exception e)
+         {
+            //We should expect this
+         }
+
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sessReceiver.createConsumer(queue1);
+         Message m2 = cons.receive(MIN_TIMEOUT);
+         assertNull(m2);
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+   public void test2PCSendRollback() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+      try
+      {
+         conn = cf.createXAConnection();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+         //prevent 1Pc optimisation
+         //res.setForceNotSameRM(true);
+
+         XAResource res2 = new DummyXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         MessageProducer prod = sess.createProducer(queue1);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         Message m = sess.createTextMessage("XATest1");
+         prod.send(queue1, m);
+         m = sess.createTextMessage("XATest2");
+         prod.send(queue1, m);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.rollback();
+
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sessReceiver.createConsumer(queue1);
+         Message m2 = cons.receive(MIN_TIMEOUT);
+         assertNull(m2);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+   public void test2PCReceiveCommit1PCOptimization() throws Exception
+   {
+      //Since both resources have some RM, TM will probably use 1PC optimization
+
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("XATest1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("XATest2");
+         prod.send(m);
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+         XAResource res2 = new DummyXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         MessageConsumer cons = sess.createConsumer(queue1);
+
+
+         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+
+         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest2", m2.getText());
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.commit();
+
+         //New tx
+         tm.begin();
+         tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         Message m3 = cons.receive(MIN_TIMEOUT);
+
+         assertNull(m3);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.commit();
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+   public void test2PCReceiveCommit() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("XATest1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("XATest2");
+         prod.send(m);
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = (XAResource)sess.getXAResource();
+         //res.setForceNotSameRM(true);
+
+         XAResource res2 = new DummyXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         MessageConsumer cons = sess.createConsumer(queue1);
+
+
+         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+
+         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest2", m2.getText());
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.commit();
+
+         //New tx
+         tm.begin();
+         tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         Message m3 = cons.receive(MIN_TIMEOUT);
+
+         assertNull(m3);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.commit();
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+   public void test2PCReceiveRollback1PCOptimization() throws Exception
+   {
+      //Since both resources have some RM, TM will probably use 1PC optimization
+
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("XATest1");
+         prod.send(m);
+
+         m = sessProducer.createTextMessage("XATest2");
+         prod.send(m);
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+         XAResource res2 = new DummyXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         MessageConsumer cons = sess.createConsumer(queue1);
+
+
+         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m2);
+         assertEquals("XATest2", m2.getText());
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         log.info("rolling back");
+         tm.rollback();
+
+         //Message should be redelivered
+
+         //New tx
+         tm.begin();
+         tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m3);
+         assertEquals("XATest1", m3.getText());
+         m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m3);
+         assertEquals("XATest2", m3.getText());
+
+         assertTrue(m3.getJMSRedelivered());
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.commit();
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+   public void test2PCReceiveRollback() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("XATest1");
+         prod.send(m);
+
+         m = sessProducer.createTextMessage("XATest2");
+         prod.send(m);
+
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+         //res.setForceNotSameRM(true);
+
+         XAResource res2 = new DummyXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         MessageConsumer cons = sess.createConsumer(queue1);
+
+
+         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m2);
+         assertEquals("XATest2", m2.getText());
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.rollback();
+
+         //Message should be redelivered
+
+         //New tx
+         tm.begin();
+         tx = tm.getTransaction();
+         tx.enlistResource(res);
+         tx.enlistResource(res2);
+
+         TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m3);
+         assertEquals("XATest1", m3.getText());
+         m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m3);
+         assertEquals("XATest2", m3.getText());
+
+         assertTrue(m3.getJMSRedelivered());
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.commit();
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+
+   public void test1PCSendCommit() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         conn = cf.createXAConnection();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+
+
+         MessageProducer prod = sess.createProducer(queue1);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         Message m = sess.createTextMessage("XATest1");
+         prod.send(queue1, m);
+         m = sess.createTextMessage("XATest2");
+         prod.send(queue1, m);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+
+         tm.commit();
+
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sessReceiver.createConsumer(queue1);
+         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(m2);
+         assertEquals("XATest2", m2.getText());
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+
+   public void test1PCSendRollback() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+      try
+      {
+         conn = cf.createXAConnection();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+
+         MessageProducer prod = sess.createProducer(queue1);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         Message m = sess.createTextMessage("XATest1");
+         prod.send(queue1, m);
+         m = sess.createTextMessage("XATest2");
+         prod.send(queue1, m);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+
+         tm.rollback();
+
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sessReceiver.createConsumer(queue1);
+         Message m2 = cons.receive(MIN_TIMEOUT);
+         assertNull(m2);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+   public void test1PCReceiveCommit() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         conn2 = cf.createConnection();
+         conn2.start();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("XATest1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("XATest2");
+         prod.send(m);
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+
+         MessageConsumer cons = sess.createConsumer(queue1);
+
+
+         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest2", m2.getText());
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+
+         tm.commit();
+
+         //New tx
+         tm.begin();
+         tx = tm.getTransaction();
+         tx.enlistResource(res);
+
+         Message m3 = cons.receive(MIN_TIMEOUT);
+
+         assertNull(m3);
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+
+         tm.commit();
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+   public void test1PCReceiveRollback() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("XATest1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("XATest2");
+         prod.send(m);
+
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         XASession sess = conn.createXASession();
+         XAResource res = sess.getXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res);
+
+         MessageConsumer cons = sess.createConsumer(queue1);
+
+
+         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+
+         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest2", m2.getText());
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+
+         tm.rollback();
+
+         //Message should be redelivered
+
+         //New tx
+         tm.begin();
+         tx = tm.getTransaction();
+         tx.enlistResource(res);
+
+         TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m3);
+         assertEquals("XATest1", m3.getText());
+
+         m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(m3);
+         assertEquals("XATest2", m3.getText());
+
+         assertTrue(m3.getJMSRedelivered());
+
+         tx.delistResource(res, XAResource.TMSUCCESS);
+
+         tm.commit();
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+   public void testMultipleSessionsOneTxCommitAcknowledge1PCOptimization() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      //Since both resources have some RM, TM will probably use 1PC optimization
+
+      try
+      {
+         //First send 2 messages
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("jellyfish1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish2");
+         prod.send(m);
+
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         //Create 2 sessions and enlist them
+         XASession sess1 = conn.createXASession();
+         XAResource res1 = sess1.getXAResource();
+         XASession sess2 = conn.createXASession();
+         XAResource res2 = sess2.getXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         //Receive the messages, one on each consumer
+         MessageConsumer cons1 = sess1.createConsumer(queue1);
+         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish1", r1.getText());
+
+         cons1.close();
+
+         MessageConsumer cons2 = sess2.createConsumer(queue1);
+         TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+
+         assertNotNull(r2);
+         assertEquals("jellyfish2", r2.getText());
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         //commit
+         tm.commit();
+
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sess.createConsumer(queue1);
+         conn2.start();
+
+         TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+         assertNull(r3);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+   public void testMultipleSessionsOneTxCommitAcknowledge() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         //First send 2 messages
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("jellyfish1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish2");
+         prod.send(m);
+
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         //Create 2 sessions and enlist them
+         XASession sess1 = conn.createXASession();
+         ClientSessionImpl res1 = (ClientSessionImpl)sess1.getXAResource();
+         XASession sess2 = conn.createXASession();
+         ClientSessionImpl res2 = (ClientSessionImpl)sess2.getXAResource();
+         res1.setForceNotSameRM(true);
+         res2.setForceNotSameRM(true);
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         //Receive the messages, one on each consumer
+         MessageConsumer cons1 = sess1.createConsumer(queue1);
+         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish1", r1.getText());
+
+         cons1.close();
+
+         MessageConsumer cons2 = sess2.createConsumer(queue1);
+         TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+
+         assertNotNull(r2);
+         assertEquals("jellyfish2", r2.getText());
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         //commit
+         tm.commit();
+
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sess.createConsumer(queue1);
+         conn2.start();
+
+         TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+         assertNull(r3);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+
+   public void testMultipleSessionsOneTxRollbackAcknowledge1PCOptimization() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      //Since both resources have some RM, TM will probably use 1PC optimization
+
+      try
+      {
+         //First send 2 messages
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("jellyfish1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish2");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish3");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish4");
+         prod.send(m);
+
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         //Create 2 sessions and enlist them
+         XASession sess1 = conn.createXASession();
+         ClientSessionImpl res1 = (ClientSessionImpl)sess1.getXAResource();
+         XASession sess2 = conn.createXASession();
+         ClientSessionImpl res2 = (ClientSessionImpl)sess2.getXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         //Receive the messages, two on each consumer
+         MessageConsumer cons1 = sess1.createConsumer(queue1);
+         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish1", r1.getText());
+
+         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish2", r1.getText());
+
+         cons1.close();
+
+         MessageConsumer cons2 = sess2.createConsumer(queue1);
+         TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+
+         assertNotNull(r2);
+         assertEquals("jellyfish3", r2.getText());
+
+         r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+
+         assertNotNull(r2);
+         assertEquals("jellyfish4", r2.getText());
+
+         cons2.close();
+
+         //rollback
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.rollback();
+
+         //Rollback causes cancel which is asynch
+         Thread.sleep(1000);
+
+         //We cannot assume anything about the order in which the transaction manager rollsback
+         //the sessions - this is implementation dependent
+
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sess.createConsumer(queue1);
+         conn2.start();
+
+         TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r);
+
+         boolean session1First = false;
+
+         if (r.getText().equals("jellyfish1"))
+         {
+            session1First = true;
+         }
+         else if (r.getText().equals("jellyfish3"))
+         {
+            session1First = false;
+         }
+         else
+         {
+            fail("Unexpected message");
+         }
+
+         if (session1First)
+         {
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish2", r.getText());
+
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish3", r.getText());
+
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish4", r.getText());
+
+
+         }
+         else
+         {
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish4", r.getText());
+
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish1", r.getText());
+
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish2", r.getText());
+         }
+
+         r = (TextMessage)cons.receive(MIN_TIMEOUT);
+
+         assertNull(r);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+   public void testMultipleSessionsOneTxRollbackAcknowledge() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         //First send 2 messages
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("jellyfish1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish2");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish3");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish4");
+         prod.send(m);
+
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         //Create 2 sessions and enlist them
+         XASession sess1 = conn.createXASession();
+         ClientSessionImpl res1 = (ClientSessionImpl)sess1.getXAResource();
+         XASession sess2 = conn.createXASession();
+         ClientSessionImpl res2 = (ClientSessionImpl)sess2.getXAResource();
+         res1.setForceNotSameRM(true);
+         res2.setForceNotSameRM(true);
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         //Receive the messages, two on each consumer
+         MessageConsumer cons1 = sess1.createConsumer(queue1);
+         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish1", r1.getText());
+
+         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish2", r1.getText());
+
+         cons1.close();
+
+         //Cancel is asynch
+         Thread.sleep(500);
+
+         MessageConsumer cons2 = sess2.createConsumer(queue1);
+         TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+
+         assertNotNull(r2);
+         assertEquals("jellyfish3", r2.getText());
+
+         r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+
+         assertNotNull(r2);
+         assertEquals("jellyfish4", r2.getText());
+
+         //rollback
+
+         cons2.close();
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.rollback();
+
+         // Rollback causes cancel which is asynch
+         Thread.sleep(1000);
+
+         //We cannot assume anything about the order in which the transaction manager rollsback
+         //the sessions - this is implementation dependent
+
+
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sess.createConsumer(queue1);
+         conn2.start();
+
+         TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r);
+
+         boolean session1First = false;
+
+         if (r.getText().equals("jellyfish1"))
+         {
+            session1First = true;
+         }
+         else if (r.getText().equals("jellyfish3"))
+         {
+            session1First = false;
+         }
+         else
+         {
+            fail("Unexpected message");
+         }
+
+         if (session1First)
+         {
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish2", r.getText());
+
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish3", r.getText());
+
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish4", r.getText());
+
+
+         }
+         else
+         {
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish4", r.getText());
+
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish1", r.getText());
+
+            r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+            assertNotNull(r);
+
+            assertEquals("jellyfish2", r.getText());
+         }
+
+         r = (TextMessage)cons.receive(MIN_TIMEOUT);
+
+         assertNull(r);
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+   public void testMultipleSessionsOneTxRollbackAcknowledgeForceFailureInCommit() throws Exception
+   {
+      XAConnection conn = null;
+      Connection conn2 = null;
+
+      try
+      {
+         //First send 4 messages
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+
+         Message m = sessProducer.createTextMessage("jellyfish1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish2");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish3");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish4");
+         prod.send(m);
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         XASession sess1 = conn.createXASession();
+         XAResource res1 = sess1.getXAResource();
+         DummyXAResource res2 = new DummyXAResource(true);
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         MessageConsumer cons1 = sess1.createConsumer(queue1);
+         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish1", r1.getText());
+
+         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish2", r1.getText());
+
+         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish3", r1.getText());
+
+         r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(r1);
+         assertEquals("jellyfish4", r1.getText());
+
+         r1 = (TextMessage)cons1.receive(1000);
+
+         assertNull(r1);
+
+         cons1.close();
+
+
+         //try and commit - and we're going to make the dummyxaresource throw an exception on commit,
+         //which should cause rollback to be called on the other resource
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         //rollback will cause an attemp to deliver messages locally to the original consumers.
+         //the original consumer has closed, so it will cancelled to the server
+         //the server cancel is asynch, so we need to sleep for a bit to make sure it completes
+         log.trace("Forcing failure");
+         try
+         {
+            tm.commit();
+            fail("should not get here");
+         }
+         catch (Exception e)
+         {
+            //We should expect this
+         }
+
+         Thread.sleep(1000);
+
+
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sess.createConsumer(queue1);
+         conn2.start();
+
+         TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(r);
+
+         assertEquals("jellyfish1", r.getText());
+
+         r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(r);
+
+         assertEquals("jellyfish2", r.getText());
+
+         r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(r);
+
+         assertEquals("jellyfish3", r.getText());
+
+         r = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(r);
+
+         assertEquals("jellyfish4", r.getText());
+
+         r = (TextMessage)cons.receive(MIN_TIMEOUT);
+
+         assertNull(r);
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+
+   }
+
+   public void testMultipleSessionsOneTxCommitSend1PCOptimization() throws Exception
+   {
+      //Since both resources have some RM, TM will probably use 1PC optimization
+
+      XAConnection conn = null;
+
+      Connection conn2 = null;
+
+      try
+      {
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         //Create 2 sessions and enlist them
+         XASession sess1 = conn.createXASession();
+         XAResource res1 = sess1.getXAResource();
+         XASession sess2 = conn.createXASession();
+         XAResource res2 = sess2.getXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         // Send 2 messages - one from each session
+
+         MessageProducer prod1 = sess1.createProducer(queue1);
+         MessageProducer prod2 = sess2.createProducer(queue1);
+
+         prod1.send(sess1.createTextMessage("echidna1"));
+         prod2.send(sess2.createTextMessage("echidna2"));
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         //commit
+         tm.commit();
+
+         //Messages should be in queue
+
+         conn2 = cf.createConnection();
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sess.createConsumer(queue1);
+         conn2.start();
+
+         TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r1);
+         assertEquals("echidna1", r1.getText());
+
+         TextMessage r2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r2);
+         assertEquals("echidna2", r2.getText());
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+   public void testMultipleSessionsOneTxCommitSend() throws Exception
+   {
+      //Since both resources have some RM, TM will probably use 1PC optimization
+
+      XAConnection conn = null;
+
+      Connection conn2 = null;
+
+      try
+      {
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         //Create 2 sessions and enlist them
+         XASession sess1 = conn.createXASession();
+         ClientSessionImpl res1 = (ClientSessionImpl)sess1.getXAResource();
+         XASession sess2 = conn.createXASession();
+         ClientSessionImpl res2 = (ClientSessionImpl)sess2.getXAResource();
+         res1.setForceNotSameRM(true);
+         res2.setForceNotSameRM(true);
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         // Send 2 messages - one from each session
+
+         MessageProducer prod1 = sess1.createProducer(queue1);
+         MessageProducer prod2 = sess2.createProducer(queue1);
+
+         prod1.send(sess1.createTextMessage("echidna1"));
+         prod2.send(sess2.createTextMessage("echidna2"));
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         //commit
+         tm.commit();
+
+         //Messages should be in queue
+
+         conn2 = cf.createConnection();
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sess.createConsumer(queue1);
+         conn2.start();
+
+         TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r1);
+         assertEquals("echidna1", r1.getText());
+
+         TextMessage r2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r2);
+         assertEquals("echidna2", r2.getText());
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+
+      }
+
+   }
+
+
+   public void testMultipleSessionsOneTxRollbackSend1PCOptimization() throws Exception
+   {
+      //Since both resources have some RM, TM will probably use 1PC optimization
+
+      XAConnection conn = null;
+
+      Connection conn2 = null;
+
+      try
+      {
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         //Create 2 sessions and enlist them
+         XASession sess1 = conn.createXASession();
+         XAResource res1 = sess1.getXAResource();
+         XASession sess2 = conn.createXASession();
+         XAResource res2 = sess2.getXAResource();
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         // Send 2 messages - one from each session
+
+         MessageProducer prod1 = sess1.createProducer(queue1);
+         MessageProducer prod2 = sess2.createProducer(queue1);
+
+         prod1.send(sess1.createTextMessage("echidna1"));
+         prod2.send(sess2.createTextMessage("echidna2"));
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         //rollback
+         tm.rollback();
+
+         //Messages should not be in queue
+
+         conn2 = cf.createConnection();
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sess.createConsumer(queue1);
+         conn2.start();
+
+         TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
+         assertNull(r1);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+   public void testMultipleSessionsOneTxRollbackSend() throws Exception
+   {
+      XAConnection conn = null;
+
+      Connection conn2 = null;
+
+      try
+      {
+
+         conn = cf.createXAConnection();
+         conn.start();
+
+         tm.begin();
+
+         //Create 2 sessions and enlist them
+         XASession sess1 = conn.createXASession();
+         ClientSessionImpl res1 = (ClientSessionImpl)sess1.getXAResource();
+         XASession sess2 = conn.createXASession();
+         ClientSessionImpl res2 = (ClientSessionImpl)sess2.getXAResource();
+         res1.setForceNotSameRM(true);
+         res2.setForceNotSameRM(true);
+
+         Transaction tx = tm.getTransaction();
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         // Send 2 messages - one from each session
+
+         MessageProducer prod1 = sess1.createProducer(queue1);
+         MessageProducer prod2 = sess2.createProducer(queue1);
+
+         prod1.send(sess1.createTextMessage("echidna1"));
+         prod2.send(sess2.createTextMessage("echidna2"));
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         //rollback
+         tm.rollback();
+
+         //Messages should not be in queue
+
+         conn2 = cf.createConnection();
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = sess.createConsumer(queue1);
+         conn2.start();
+
+         TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
+         assertNull(r1);
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+
+   public void testOneSessionTwoTransactionsCommitAcknowledge() throws Exception
+   {
+      XAConnection conn = null;
+
+      Connection conn2 = null;
+
+      try
+      {
+         //First send 2 messages
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("jellyfish1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish2");
+         prod.send(m);
+
+         conn = cf.createXAConnection();
+
+         //Create a session
+         XASession sess1 = conn.createXASession();
+         XAResource res1 = sess1.getXAResource();
+
+         conn.start();
+         MessageConsumer cons1 = sess1.createConsumer(queue1);
+
+         tm.begin();
+
+         Transaction tx1 = tm.getTransaction();
+         tx1.enlistResource(res1);
+
+         //Receive one message in one tx
+
+         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+         assertNotNull(r1);
+         assertEquals("jellyfish1", r1.getText());
+         
+         tx1.delistResource(res1, XAResource.TMSUCCESS);
+
+         //suspend the tx
+         log.info("Calling suspend");
+         Transaction suspended = tm.suspend();
+         log.info("Called suspend");
+
+         tm.begin();
+
+         Transaction tx2 = tm.getTransaction();
+         tx2.enlistResource(res1);
+
+         //Receive 2nd message in a different tx
+         TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+         assertNotNull(r2);
+         assertEquals("jellyfish2", r2.getText());
+
+         tx2.delistResource(res1, XAResource.TMSUCCESS);
+
+         //commit this transaction
+         tm.commit();
+
+         //verify that no messages are available
+         conn2.close();
+         conn2 = cf.createConnection();
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         conn2.start();
+         MessageConsumer cons = sess.createConsumer(queue1);
+         TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+         assertNull(r3);
+
+         //now resume the first tx and then commit it
+         tm.resume(suspended);
+
+         tm.commit();
+         
+         log.info("Got to end");
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+      }
+   }
+
+
+   public void testOneSessionTwoTransactionsRollbackAcknowledge() throws Exception
+   {
+      XAConnection conn = null;
+
+      Connection conn2 = null;
+
+      try
+      {
+         //First send 2 messages
+         conn2 = cf.createConnection();
+         Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod  = sessProducer.createProducer(queue1);
+         Message m = sessProducer.createTextMessage("jellyfish1");
+         prod.send(m);
+         m = sessProducer.createTextMessage("jellyfish2");
+         prod.send(m);
+
+         conn = cf.createXAConnection();
+
+         //Create a session
+         XASession sess1 = conn.createXASession();
+         XAResource res1 = sess1.getXAResource();
+
+         conn.start();
+         MessageConsumer cons1 = sess1.createConsumer(queue1);
+
+         tm.begin();
+
+         Transaction tx1 = tm.getTransaction();
+         tx1.enlistResource(res1);
+
+         //Receive one message in one tx
+
+         TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+         assertNotNull(r1);
+         assertEquals("jellyfish1", r1.getText());
+         
+         tx1.delistResource(res1, XAResource.TMSUCCESS);
+
+         //suspend the tx
+         Transaction suspended = tm.suspend();
+
+         tm.begin();
+
+         Transaction tx2 = tm.getTransaction();
+         tx2.enlistResource(res1);
+
+         //Receive 2nd message in a different tx
+         TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+         assertNotNull(r2);
+         assertEquals("jellyfish2", r2.getText());
+
+         cons1.close();
+
+         tx2.delistResource(res1, XAResource.TMSUCCESS);
+
+         //rollback this transaction
+         tm.rollback();
+
+         //verify that second message is available
+         conn2.close();
+         conn2 = cf.createConnection();
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         conn2.start();
+         MessageConsumer cons = sess.createConsumer(queue1);
+
+         TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+
+         assertNotNull(r3);
+         assertEquals("jellyfish2", r3.getText());
+         r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+         assertNull(r3);
+
+
+         //rollback the other tx
+         tm.resume(suspended);
+         tm.rollback();
+
+         //Verify the first message is now available
+         r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r3);
+         assertEquals("jellyfish1", r3.getText());
+         r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+         assertNull(r3);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+
+      }
+
+   }
+
+
+   public void testOneSessionTwoTransactionsCommitSend() throws Exception
+   {
+      XAConnection conn = null;
+
+      Connection conn2 = null;
+
+      try
+      {
+         conn = cf.createXAConnection();
+
+         //Create a session
+         XASession sess1 = conn.createXASession();
+         XAResource res1 = sess1.getXAResource();
+
+         MessageProducer prod1 = sess1.createProducer(queue1);
+
+         tm.begin();
+
+         Transaction tx1 = tm.getTransaction();
+         tx1.enlistResource(res1);
+
+         //Send a message
+         prod1.send(sess1.createTextMessage("kangaroo1"));
+         
+         tx1.delistResource(res1, XAResource.TMSUCCESS);
+
+         //suspend the tx
+         Transaction suspended = tm.suspend();
+
+         tm.begin();
+
+         //Send another message in another tx using the same session
+         Transaction tx2 = tm.getTransaction();
+         tx2.enlistResource(res1);
+
+         //Send a message
+         prod1.send(sess1.createTextMessage("kangaroo2"));
+
+         tx2.delistResource(res1, XAResource.TMSUCCESS);
+
+         //commit this transaction
+         tm.commit();
+
+         //verify only kangaroo2 message is sent
+         conn2 = cf.createConnection();
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         conn2.start();
+         MessageConsumer cons = sess.createConsumer(queue1);
+         TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r1);
+         assertEquals("kangaroo2", r1.getText());
+         TextMessage r2 = (TextMessage)cons.receive(MIN_TIMEOUT);
+         assertNull(r2);
+
+         //now resume the first tx and then commit it
+         tm.resume(suspended);
+
+         tm.commit();
+
+         //verify that the first text message is received
+         TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r3);
+         assertEquals("kangaroo1", r3.getText());
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+
+      }
+
+   }
+
+
+   public void testOneSessionTwoTransactionsRollbackSend() throws Exception
+   {
+      XAConnection conn = null;
+
+      Connection conn2 = null;
+
+      try
+      {
+
+         conn = cf.createXAConnection();
+
+         //Create a session
+         XASession sess1 = conn.createXASession();
+         XAResource res1 = sess1.getXAResource();
+
+         MessageProducer prod1 = sess1.createProducer(queue1);
+
+         tm.begin();
+
+         Transaction tx1 = tm.getTransaction();
+         tx1.enlistResource(res1);
+
+         //Send a message
+         prod1.send(sess1.createTextMessage("kangaroo1"));
+
+         //suspend the tx
+         Transaction suspended = tm.suspend();
+
+         tm.begin();
+
+         //Send another message in another tx using the same session
+         Transaction tx2 = tm.getTransaction();
+         tx2.enlistResource(res1);
+
+         //Send a message
+         prod1.send(sess1.createTextMessage("kangaroo2"));
+
+         tx2.delistResource(res1, XAResource.TMSUCCESS);
+
+         //rollback this transaction
+         tm.rollback();
+
+         //verify no messages are sent
+         conn2 = cf.createConnection();
+         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         conn2.start();
+         MessageConsumer cons = sess.createConsumer(queue1);
+         TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
+
+         assertNull(r1);
+
+
+         //now resume the first tx and then commit it
+         tm.resume(suspended);
+
+         tx1.delistResource(res1, XAResource.TMSUCCESS);
+
+         tm.commit();
+
+         //verify that the first text message is received
+         TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+         assertNotNull(r3);
+         assertEquals("kangaroo1", r3.getText());
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+
+      }
+
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private void assertEqualByteArrays(byte[] b1, byte[] b2)
+   {
+      log.info("b1 length: " + b1.length + " b2 length " + b2.length);
+
+      if (b1.length != b2.length)
+      {
+         fail("Lengths not the same");
+      }
+
+      for (int i = 0; i < b1.length; i++)
+      {
+         if (b1[i] != b2[i])
+         {
+            fail("Not same at index " + i);
+         }
+      }
+   }
+
+   // Inner classes -------------------------------------------------
+
+
+   static class DummyListener implements MessageListener
+   {
+
+      protected Logger log = Logger.getLogger(getClass());
+
+      public ArrayList messages = new ArrayList();
+
+      public void onMessage(Message message)
+      {
+         log.info("Message received on DummyListener " + message);
+         messages.add(message);
+      }
+   }
+
+   static class MockServerSessionPool implements ServerSessionPool
+   {
+      private ServerSession serverSession;
+
+      MockServerSessionPool(Session sess)
+      {
+         serverSession = new MockServerSession(sess);
+      }
+
+      public ServerSession getServerSession() throws JMSException
+      {
+         return serverSession;
+      }
+   }
+
+   static class MockServerSession implements ServerSession
+   {
+      Session session;
+
+      MockServerSession(Session sess)
+      {
+         this.session = sess;
+      }
+
+
+      public Session getSession() throws JMSException
+      {
+         return session;
+      }
+
+      public void start() throws JMSException
+      {
+         session.run();
+      }
+
+   }
+
+
+
+   static class DummyXAResource implements XAResource
+   {
+      boolean failOnPrepare;
+
+      DummyXAResource()
+      {
+      }
+
+      DummyXAResource(boolean failOnPrepare)
+      {
+         this.failOnPrepare = failOnPrepare;
+      }
+
+      public void commit(Xid arg0, boolean arg1) throws XAException
+      {
+      }
+
+      public void end(Xid arg0, int arg1) throws XAException
+      {
+      }
+
+      public void forget(Xid arg0) throws XAException
+      {
+      }
+
+      public int getTransactionTimeout() throws XAException
+      {
+          return 0;
+      }
+
+      public boolean isSameRM(XAResource arg0) throws XAException
+      {
+         return false;
+      }
+
+      public int prepare(Xid arg0) throws XAException
+      {
+         if (failOnPrepare)
+         {
+            throw new XAException(XAException.XAER_RMFAIL);
+         }
+         return XAResource.XA_OK;
+      }
+
+      public Xid[] recover(int arg0) throws XAException
+      {
+         return null;
+      }
+
+      public void rollback(Xid arg0) throws XAException
+      {
+      }
+
+      public boolean setTransactionTimeout(int arg0) throws XAException
+      {
+         return false;
+      }
+
+      public void start(Xid arg0, int arg1) throws XAException
+      {
+
+      }
+
+   }
+
 }

Modified: trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCReceiver.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCReceiver.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCReceiver.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -26,7 +26,7 @@
 import javax.jms.XASession;
 import javax.transaction.xa.XAResource;
 
-import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.messaging.core.impl.XidImpl;
 import org.jboss.messaging.util.Logger;
 import org.jboss.util.id.GUID;
 
@@ -84,9 +84,9 @@
       {      
          int iterations = numMessages / commitSize;
          
-         MessagingXid xid = null;
+         XidImpl xid = null;
          
-         xid = new MessagingXid("bq1".getBytes(), 1, new GUID().toString().getBytes());
+         xid = new XidImpl("bq1".getBytes(), 1, new GUID().toString().getBytes());
          xaResource.start(xid, XAResource.TMNOFLAGS);
          
          for (int outerCount = 0; outerCount < iterations; outerCount++)
@@ -141,7 +141,7 @@
                   xaResource.commit(xid, false);
                                     
                   //Starting new tx
-                  xid = new MessagingXid("bq1".getBytes(), 1, new GUID().toString().getBytes());
+                  xid = new XidImpl("bq1".getBytes(), 1, new GUID().toString().getBytes());
                   xaResource.start(xid, XAResource.TMNOFLAGS);
                  
                }
@@ -201,7 +201,7 @@
                   xaResource.prepare(xid);
                   xaResource.rollback(xid);
                   
-                  xid = new MessagingXid("bq1".getBytes(), 1, new GUID().toString().getBytes());
+                  xid = new XidImpl("bq1".getBytes(), 1, new GUID().toString().getBytes());
                   xaResource.start(xid, XAResource.TMNOFLAGS);
                }
                processingDone();

Modified: trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCSender.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCSender.java	2008-01-31 15:28:11 UTC (rev 3654)
+++ trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCSender.java	2008-01-31 20:26:32 UTC (rev 3655)
@@ -26,7 +26,7 @@
 import javax.jms.XASession;
 import javax.transaction.xa.XAResource;
 
-import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.messaging.core.impl.XidImpl;
 import org.jboss.messaging.util.Logger;
 import org.jboss.util.id.GUID;
 
@@ -75,10 +75,10 @@
       {
          for (int outerCount = 0; outerCount < iterations; outerCount++)
          {
-            MessagingXid xid = null;
+            XidImpl xid = null;
             if (commitSize > 0)
             {
-               xid = new MessagingXid("bq1".getBytes(), 1, new GUID().toString().getBytes());
+               xid = new XidImpl("bq1".getBytes(), 1, new GUID().toString().getBytes());
                xaResource.start(xid, XAResource.TMNOFLAGS);
             }
             for (int innerCount = 0; innerCount < commitSize; innerCount++)
@@ -96,7 +96,7 @@
             }
             if (rollbackSize > 0)
             {
-               xid = new MessagingXid("bq1".getBytes(), 1, new GUID().toString().getBytes());
+               xid = new XidImpl("bq1".getBytes(), 1, new GUID().toString().getBytes());
                xaResource.start(xid, XAResource.TMNOFLAGS);
             }
             for (int innerCount = 0; innerCount < rollbackSize; innerCount++)




More information about the jboss-cvs-commits mailing list