[jbosscache-commits] JBoss Cache SVN: r6070 - in core/trunk/src/main/java/org/jboss/cache: transaction and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Jun 26 17:42:59 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-06-26 17:42:58 -0400 (Thu, 26 Jun 2008)
New Revision: 6070

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/transaction/PessimisticTransactionContext.java
   core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java
Log:
Moved pessimistic lock specific rollback code to the PLI and away from the TransactionContext


Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java	2008-06-26 21:42:34 UTC (rev 6069)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java	2008-06-26 21:42:58 UTC (rev 6070)
@@ -10,6 +10,7 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.NodeSPI;
 import org.jboss.cache.commands.DataCommand;
+import org.jboss.cache.commands.ReversibleCommand;
 import org.jboss.cache.commands.VisitableCommand;
 import org.jboss.cache.commands.read.GetChildrenNamesCommand;
 import org.jboss.cache.commands.read.GetKeyValueCommand;
@@ -39,8 +40,10 @@
 import org.jboss.cache.transaction.GlobalTransaction;
 import org.jboss.cache.transaction.TransactionContext;
 
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Map;
 
 /*
@@ -160,7 +163,8 @@
             dataContainer.removeFromDataStructure(fqn, false);
          }
          // 1. Revert the modifications by running the undo-op list in reverse. This *cannot* throw any exceptions !
-         transactionContext.undoOperations();
+
+         undoOperations(transactionContext);
       }
       if (trace)
       {
@@ -171,6 +175,38 @@
       return retVal;
    }
 
+   private void undoOperations(TransactionContext transactionContext)
+   {
+      List<ReversibleCommand> modificationList = transactionContext.getModifications();
+
+      if (modificationList.isEmpty())
+      {
+         if (trace) log.trace("Modification list is null, no modifications in this transaction!");
+         return;
+      }
+
+      if (trace) log.trace("undoOperations " + modificationList);
+
+      ArrayList<ReversibleCommand> copy;
+      copy = new ArrayList<ReversibleCommand>(modificationList);
+      RuntimeException exc = null;
+      for (ListIterator i = copy.listIterator(copy.size()); i.hasPrevious();)
+      {
+         Object undoOp = i.previous();
+         ReversibleCommand txCommand = (ReversibleCommand) undoOp;
+         if (log.isDebugEnabled()) log.debug("Calling rollback() on command " + undoOp);
+         try
+         {
+            txCommand.rollback();
+         }
+         catch (RuntimeException re)
+         {
+            exc = re;
+         }
+      }
+      if (exc != null) throw exc;
+   }
+
    @Override
    protected Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
    {

Modified: core/trunk/src/main/java/org/jboss/cache/transaction/PessimisticTransactionContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/PessimisticTransactionContext.java	2008-06-26 21:42:34 UTC (rev 6069)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/PessimisticTransactionContext.java	2008-06-26 21:42:58 UTC (rev 6070)
@@ -22,7 +22,6 @@
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.ListIterator;
 
 /**
  * Information associated with a {@link GlobalTransaction} about the transaction state.
@@ -204,32 +203,6 @@
       }
    }
 
-
-   public void undoOperations()
-   {
-      if (modificationList == null)
-      {
-         if (trace) log.trace("Modification list is null, no modifications in this transaction!");
-         return;
-      }
-
-      if (trace) log.trace("undoOperations " + modificationList);
-
-      ArrayList<ReversibleCommand> copy;
-//      synchronized (modificationList)
-//      {
-      // no need to sync?  Only one thread would access a transaction at any given time?
-      copy = new ArrayList<ReversibleCommand>(modificationList);
-//      }
-      for (ListIterator i = copy.listIterator(copy.size()); i.hasPrevious();)
-      {
-         Object undoOp = i.previous();
-         ReversibleCommand txCommand = (ReversibleCommand) undoOp;
-         if (log.isDebugEnabled()) log.debug("Calling rollback() on command " + undoOp);
-         txCommand.rollback();
-      }
-   }
-
    /**
     * Returns debug information about this transaction.
     */

Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java	2008-06-26 21:42:34 UTC (rev 6069)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java	2008-06-26 21:42:58 UTC (rev 6070)
@@ -194,11 +194,6 @@
    void setForceSyncReplication(boolean forceSyncReplication);
 
    /**
-    * Calls a rollback on all modifications in reverse order.
-    */
-   void undoOperations();
-
-   /**
     * Adds an Fqn to the list of uninitialized nodes created by the cache loader.
     *
     * @param fqn fqn to add.  Must not be null.




More information about the jbosscache-commits mailing list