[Jboss-cvs] JBoss Messaging SVN: r1343 - branches/Branch_1_0/src/main/org/jboss/messaging/core/tx

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 21 22:05:19 EDT 2006


Author: clebert.suconic at jboss.com
Date: 2006-09-21 22:05:17 -0400 (Thu, 21 Sep 2006)
New Revision: 1343

Modified:
   branches/Branch_1_0/src/main/org/jboss/messaging/core/tx/Transaction.java
   branches/Branch_1_0/src/main/org/jboss/messaging/core/tx/TransactionRepository.java
Log:
JBMESSAGING-545 - deleting XA transactions from repository after its completion (rollback or commit)

Modified: branches/Branch_1_0/src/main/org/jboss/messaging/core/tx/Transaction.java
===================================================================
--- branches/Branch_1_0/src/main/org/jboss/messaging/core/tx/Transaction.java	2006-09-21 22:40:34 UTC (rev 1342)
+++ branches/Branch_1_0/src/main/org/jboss/messaging/core/tx/Transaction.java	2006-09-22 02:05:17 UTC (rev 1343)
@@ -56,6 +56,12 @@
    
    protected Xid xid;
    
+   /** 
+    * If this is a XA transaction, when a commit is executed the transaction has to be removed from the transaction repository.
+    * This reference will guarantee the reference back to the repository where the transaction was created
+    * */
+   protected TransactionRepository transactionRepository;
+   
    protected List callbacks;
    
    protected List keyedCallbacks;
@@ -74,7 +80,7 @@
 
    public static final int STATE_ROLLBACK_ONLY = 4;
 
-   public String stateToString(int state)
+   public static String stateToString(int state)
    {
       if (state == STATE_ACTIVE)
       {
@@ -113,10 +119,11 @@
       keyedCallbackMap = new HashMap();
    }
    
-   Transaction(long id, Xid xid)
+   Transaction(long id, Xid xid, TransactionRepository repository)
    {
       this(id);
       this.xid = xid;
+      this.transactionRepository=repository;
    }
    
    // Public --------------------------------------------------------
@@ -198,8 +205,13 @@
       
       keyedCallbacks = null;
       
-      keyedCallbackMap = null;      
+      keyedCallbackMap = null;
       
+      if (transactionRepository!=null)
+      {
+    	  transactionRepository.deleteTransaction(this);
+      }
+      
       if (trace) { log.trace("commit process complete " + this); }
    }
    
@@ -281,6 +293,11 @@
       callbacks = null;
       keyedCallbacks = null;
       keyedCallbackMap = null;
+
+      if (transactionRepository!=null)
+      {
+    	  transactionRepository.deleteTransaction(this);
+      }
       
       if (trace) { log.trace("rollback process complete " + this); }
    }

Modified: branches/Branch_1_0/src/main/org/jboss/messaging/core/tx/TransactionRepository.java
===================================================================
--- branches/Branch_1_0/src/main/org/jboss/messaging/core/tx/TransactionRepository.java	2006-09-21 22:40:34 UTC (rev 1342)
+++ branches/Branch_1_0/src/main/org/jboss/messaging/core/tx/TransactionRepository.java	2006-09-22 02:05:17 UTC (rev 1343)
@@ -135,13 +135,36 @@
       return tx;
    }
    
+   public void deleteTransaction(Transaction transaction) throws Exception
+   {
+	   final Xid id = transaction.getXid();
+	   final int state = transaction.getState();
+	   
+	   if (id==null)
+	   {
+		   Exception ex = new Exception();
+		   log.warn("DeleteTransaction was called for non XA transaction",ex);
+		   return;
+	   }
+
+	   if (state!=Transaction.STATE_COMMITTED && state!=Transaction.STATE_ROLLEDBACK)
+	   {
+		   throw new TransactionException("Transaction with xid " + id + " can't be removed as it's not yet commited or rolledback: (Current state is " + Transaction.stateToString(state));
+	   }
+	   
+	   globalToLocalMap.remove(id);
+	   
+	   
+	   
+   }
+   
    public Transaction createTransaction(Xid xid) throws Exception
    {
       if (globalToLocalMap.containsKey(xid))
       {
          throw new TransactionException("There is already a local tx for global tx " + xid);
       }
-      Transaction tx = new Transaction(idManager.getId(), xid);
+      Transaction tx = new Transaction(idManager.getId(), xid, this);
       
       if (trace) { log.trace("created transaction " + tx); }
       
@@ -158,6 +181,13 @@
       return tx;
    }
    
+   
+   /** To be used only by testcases */
+   public int getNumberOfRegisteredTransactions()
+   {
+	  return this.globalToLocalMap.size();   
+   }
+   
    // Package protected ---------------------------------------------
    
    // Protected -----------------------------------------------------         




More information about the jboss-cvs-commits mailing list