[jbosscache-commits] JBoss Cache SVN: r5736 - in core/trunk/src/main/java/org/jboss/cache: commands/remote and 5 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Apr 28 14:56:13 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-28 14:56:13 -0400 (Mon, 28 Apr 2008)
New Revision: 5736

Removed:
   core/trunk/src/main/java/org/jboss/cache/transaction/GlobalTransactionContainer.java
Modified:
   core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
   core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java
   core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
   core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
   core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
Log:
Consolidated GlobalTransactionContainer and TransactionTable

Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -13,7 +13,7 @@
 import org.jboss.cache.lock.NodeLock;
 import org.jboss.cache.marshall.MethodCall;
 import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.GlobalTransactionContainer;
+import org.jboss.cache.transaction.TransactionTable;
 
 import javax.transaction.Transaction;
 import java.util.ArrayList;
@@ -452,7 +452,7 @@
 
    public boolean isValidTransaction()
    {
-      return transaction != null && GlobalTransactionContainer.isValid(transaction);
+      return transaction != null && TransactionTable.isValid(transaction);
    }
 
    public void throwIfNeeded(Throwable e) throws Throwable

Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -14,7 +14,7 @@
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.interceptors.InterceptorChain;
 import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.GlobalTransactionContainer;
+import org.jboss.cache.transaction.TransactionTable;
 
 import java.util.List;
 
@@ -33,7 +33,7 @@
 
    /* dependencies */
    private BuddyManager buddyManager;
-   private GlobalTransactionContainer transactionHelper;
+   private TransactionTable transactionTable;
    private InterceptorChain invoker;
    private CommandsFactory commandsFactory;
    private DataContainer dataContainer;
@@ -60,12 +60,12 @@
    }
 
    @Inject
-   public void initialize(BuddyManager buddyManager, InterceptorChain invoker, GlobalTransactionContainer transactionHelper,
+   public void initialize(BuddyManager buddyManager, InterceptorChain invoker, TransactionTable transactionTable,
                           CommandsFactory commandsFactory, DataContainer dataContainer)
    {
       this.buddyManager = buddyManager;
       this.invoker = invoker;
-      this.transactionHelper = transactionHelper;
+      this.transactionTable = transactionTable;
       this.commandsFactory = commandsFactory;
       this.dataContainer = dataContainer;
    }
@@ -77,7 +77,7 @@
          if (trace)
             log.trace("DataGravitationCleanup: Removing primary (" + fqn + ") and backup (" + backup + ")");
 
-         GlobalTransaction gtx = transactionHelper.getCurrentTransaction();
+         GlobalTransaction gtx = transactionTable.getCurrentTransaction();
          if (!executeRemove(gtx, fqn))
          {
             // only attempt to clean up the backup if the primary did not exist - a waste of a call otherwise.

Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -13,7 +13,6 @@
 import org.jboss.cache.notifications.Notifier;
 import org.jboss.cache.remoting.jgroups.ChannelMessageListener;
 import org.jboss.cache.statetransfer.StateTransferManager;
-import org.jboss.cache.transaction.GlobalTransactionContainer;
 import org.jboss.cache.transaction.TransactionTable;
 
 /**
@@ -22,10 +21,10 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 2.1.0
  */
- at DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class,
+ at DefaultFactoryFor(classes = {StateTransferManager.class, RegionManager.class, Notifier.class,
       ChannelMessageListener.class, CacheLoaderManager.class, Marshaller.class,
       InvocationContextContainer.class, CacheInvocationDelegate.class,
-      GlobalTransactionContainer.class, DataContainer.class, CommandsFactory.class, LockManager.class})
+      TransactionTable.class, DataContainer.class, CommandsFactory.class, LockManager.class})
 public class EmptyConstructorFactory extends ComponentFactory
 {
    @Override

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -34,7 +34,7 @@
    private BuddyManager buddyManager;
    private boolean usingBuddyReplication;
    private ReplicationQueue replicationQueue;
-   private TransactionTable txTable;
+   protected TransactionTable txTable;
    private CommandsFactory commandsFactory;
 
    protected RPCManager rpcManager;

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -8,9 +8,6 @@
 
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InvocationContext;
-import org.jboss.cache.RPCManager;
-import org.jboss.cache.buddyreplication.BuddyManager;
-import org.jboss.cache.cluster.ReplicationQueue;
 import org.jboss.cache.commands.AbstractVisitor;
 import org.jboss.cache.commands.ReversibleCommand;
 import org.jboss.cache.commands.VisitableCommand;
@@ -34,7 +31,6 @@
 import org.jboss.cache.optimistic.TransactionWorkspace;
 import org.jboss.cache.optimistic.WorkspaceNode;
 import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.GlobalTransactionContainer;
 import org.jboss.cache.transaction.OptimisticTransactionEntry;
 import org.jboss.cache.transaction.TransactionEntry;
 import org.jboss.cache.transaction.TransactionTable;
@@ -64,28 +60,18 @@
 public class InvalidationInterceptor extends BaseRpcInterceptor implements InvalidationInterceptorMBean
 {
    private long invalidations = 0;
-   protected TransactionTable txTable;
    protected Map<GlobalTransaction, List<ReversibleCommand>> txMods;
    protected boolean optimistic;
    private CommandsFactory commandsFactory;
 
-   @Override
    @Inject
-   public void injectComponents(RPCManager rpcManager, BuddyManager buddyManager, ReplicationQueue replicationQueue,
-                                Configuration config, TransactionTable txTable, CommandsFactory commandsFactory)
+   public void injectDependencies(Configuration config, CommandsFactory commandsFactory)
    {
-      super.injectComponents(rpcManager, buddyManager, replicationQueue, config, txTable, commandsFactory);
       optimistic = config.isNodeLockingOptimistic();
       if (optimistic) txMods = new ConcurrentHashMap<GlobalTransaction, List<ReversibleCommand>>();
       this.commandsFactory = commandsFactory;
    }
 
-   @Inject
-   private void injectDependencies(TransactionTable txTable)
-   {
-      this.txTable = txTable;
-   }
-
    private boolean skipInvalidation(InvocationContext ctx)
    {
       Option optionOverride = ctx.getOptionOverrides();
@@ -230,7 +216,7 @@
       if (!fqns.isEmpty())
       {
          // could be potentially TRANSACTIONAL.  Ignore if it is, until we see a prepare().
-         if (tx == null || !GlobalTransactionContainer.isValid(tx))
+         if (tx == null || !TransactionTable.isValid(tx))
          {
             // the no-tx case:
             //replicate an evict call.

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -21,7 +21,7 @@
 import org.jboss.cache.config.Option;
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.GlobalTransactionContainer;
+import org.jboss.cache.transaction.TransactionTable;
 
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
@@ -33,13 +33,11 @@
  */
 public class InvocationContextInterceptor extends BaseTransactionalContextInterceptor implements InvocationContextInterceptorMBean
 {
-   private GlobalTransactionContainer txHelper;
    private RPCManager rpcManager;
 
    @Inject
-   public void setDependencies(GlobalTransactionContainer cth, RPCManager rpcManager)
+   public void setDependencies(RPCManager rpcManager)
    {
-      this.txHelper = cth;
       this.rpcManager = rpcManager;
    }
 
@@ -174,7 +172,7 @@
          }
          else
          {
-            if (ctx.getTransaction() != null && (GlobalTransactionContainer.isValid(ctx.getTransaction())))
+            if (ctx.getTransaction() != null && (TransactionTable.isValid(ctx.getTransaction())))
             {
                copyInvocationScopeOptionsToTxScope(ctx);
             }
@@ -188,7 +186,7 @@
 
    private GlobalTransaction getGlobalTransaction(Transaction tx, GlobalTransaction gtx)
    {
-      if (gtx == null) gtx = txHelper.getCurrentTransaction(tx, false);
+      if (gtx == null) gtx = txTable.getCurrentTransaction(tx, false);
       if (gtx != null) gtx.setRemote(isRemoteGlobalTx(gtx));
       return gtx;
    }

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -22,7 +22,6 @@
 import org.jboss.cache.optimistic.WorkspaceNode;
 import org.jboss.cache.transaction.GlobalTransaction;
 import org.jboss.cache.transaction.TransactionEntry;
-import org.jboss.cache.transaction.TransactionTable;
 
 /**
  * Locks nodes during transaction boundaries.  Only affects prepare/commit/rollback method calls; other method calls
@@ -34,13 +33,11 @@
 public class OptimisticLockingInterceptor extends OptimisticInterceptor
 {
    private long lockAcquisitionTimeout;
-   private TransactionTable txTable;
    private Configuration configuration;
 
    @Inject
-   public void initialize(TransactionTable transactionTable, Configuration configuration)
+   public void initialize(Configuration configuration)
    {
-      this.txTable = transactionTable;
       this.configuration = configuration;
       lockAcquisitionTimeout = configuration.getLockAcquisitionTimeout();
    }

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -36,7 +36,6 @@
 import org.jboss.cache.optimistic.WorkspaceNode;
 import org.jboss.cache.transaction.GlobalTransaction;
 import org.jboss.cache.transaction.OptimisticTransactionEntry;
-import org.jboss.cache.transaction.TransactionTable;
 import org.jboss.cache.util.concurrent.ConcurrentHashSet;
 
 import java.util.ArrayList;
@@ -63,15 +62,12 @@
 
    private CommandsFactory commandsFactory;
 
-   private TransactionTable transactionTable;
-
    private Configuration configuration;
 
    @Inject
-   public void initialize(CommandsFactory commandsFactory, TransactionTable transactionTable, Configuration configuration)
+   public void initialize(CommandsFactory commandsFactory, Configuration configuration)
    {
       this.commandsFactory = commandsFactory;
-      this.transactionTable = transactionTable;
       this.configuration = configuration;
    }
 
@@ -177,7 +173,7 @@
          return invokeNextInterceptor(ctx, command);
       }
       GlobalTransaction gtx = getGlobalTransaction(ctx);
-      if (command.isPutForExternalRead()) transactionTable.get(gtx).setForceAsyncReplication(true);
+      if (command.isPutForExternalRead()) txTable.get(gtx).setForceAsyncReplication(true);
       return invokeNextInterceptor(ctx, command);
    }
 
@@ -397,7 +393,7 @@
 
    protected TransactionWorkspace getTransactionWorkspace(GlobalTransaction gtx) throws CacheException
    {
-      OptimisticTransactionEntry transactionEntry = (OptimisticTransactionEntry) transactionTable.get(gtx);
+      OptimisticTransactionEntry transactionEntry = (OptimisticTransactionEntry) txTable.get(gtx);
       if (transactionEntry == null)
       {
          throw new CacheException("unable to map global transaction " + gtx + " to transaction entry");

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -13,9 +13,7 @@
 import org.jboss.cache.commands.write.RemoveNodeCommand;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.config.Option;
-import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.TransactionTable;
 
 /**
  * Takes care of replicating modifications to other nodes in a cluster. Also
@@ -27,14 +25,7 @@
  */
 public class ReplicationInterceptor extends BaseRpcInterceptor
 {
-   private TransactionTable transactionTable;
 
-   @Inject
-   public void setDependencies(TransactionTable txTable)
-   {
-      this.transactionTable = txTable;
-   }
-
    protected boolean skipReplication(InvocationContext ctx)
    {
       Option optionOverride = ctx.getOptionOverrides();
@@ -81,7 +72,7 @@
          Object returnValue = invokeNextInterceptor(ctx, command);
          if (command.isPutForExternalRead())
          {
-            transactionTable.get(command.getGlobalTransaction()).setForceAsyncReplication(true);
+            txTable.get(command.getGlobalTransaction()).setForceAsyncReplication(true);
          }
          return returnValue;
       }

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -34,9 +34,9 @@
 import org.jboss.cache.invocation.InvocationContextContainer;
 import org.jboss.cache.notifications.Notifier;
 import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.GlobalTransactionContainer;
 import org.jboss.cache.transaction.OptimisticTransactionEntry;
 import org.jboss.cache.transaction.TransactionEntry;
+import org.jboss.cache.transaction.TransactionTable;
 
 import javax.transaction.InvalidTransactionException;
 import javax.transaction.Status;
@@ -66,7 +66,6 @@
    private Configuration configuration;
    private CommandsFactory commandsFactory;
    private RPCManager rpcManager;
-   private GlobalTransactionContainer transactionHelper;
    private Notifier notifier;
    private InvocationContextContainer invocationContextContainer;
    private LifecycleManager lifecycleManager;
@@ -85,13 +84,12 @@
 
    @Inject
    public void intialize(Configuration configuration, RPCManager rpcManager,
-                         GlobalTransactionContainer transactionHelper, Notifier notifier, InvocationContextContainer icc,
+                         Notifier notifier, InvocationContextContainer icc,
                          LifecycleManager lifecycleManager, CommandsFactory factory)
    {
       this.configuration = configuration;
       this.commandsFactory = factory;
       this.rpcManager = rpcManager;
-      this.transactionHelper = transactionHelper;
       this.notifier = notifier;
       this.invocationContextContainer = icc;
       this.lifecycleManager = lifecycleManager;
@@ -533,7 +531,7 @@
       replayVisitorWithInject.visitCollection(ctx, command.getModifications());
       retval = invokeNextInterceptor(ctx, command);
       // JBCACHE-361 Confirm that the transaction is ACTIVE
-      if (!GlobalTransactionContainer.isActive(ltx))
+      if (!TransactionTable.isActive(ltx))
       {
          throw new ReplicationException("prepare() failed -- local transaction status is not STATUS_ACTIVE;" +
                " is " + ltx.getStatus());
@@ -710,7 +708,7 @@
       private void assertTxIsActive(InvocationContext ctx)
             throws SystemException
       {
-         if (!GlobalTransactionContainer.isActive(ctx.getTransaction()))
+         if (!TransactionTable.isActive(ctx.getTransaction()))
          {
             throw new ReplicationException("prepare() failed -- " + "local transaction status is not STATUS_ACTIVE; is " + ctx.getTransaction().getStatus());
          }
@@ -980,9 +978,9 @@
    private GlobalTransaction registerTransaction(Transaction tx, InvocationContext ctx) throws Exception
    {
       GlobalTransaction gtx;
-      if (GlobalTransactionContainer.isValid(tx) && transactions.put(tx, NULL) == null)
+      if (TransactionTable.isValid(tx) && transactions.put(tx, NULL) == null)
       {
-         gtx = transactionHelper.getCurrentTransaction(tx, true);
+         gtx = txTable.getCurrentTransaction(tx, true);
          if (gtx.isRemote())
          {
             // should be no need to register a handler since this a remotely initiated globalTransaction

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -25,7 +25,6 @@
 import org.jboss.cache.notifications.Notifier;
 import org.jboss.cache.statetransfer.StateTransferManager;
 import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.GlobalTransactionContainer;
 import org.jboss.cache.transaction.TransactionTable;
 import org.jgroups.Address;
 
@@ -58,14 +57,13 @@
    private RegionManager regionManager;
    private Marshaller marshaller;
    private DataContainer dataContainer;
-   private CommandsFactory commandsFactory;// tu be built here and imjected within any CacheCommand instance. Also pass this to the interceptor chain
-   private GlobalTransactionContainer transactionHelper;
+   private CommandsFactory commandsFactory;
 
    @Inject
    public void initialize(StateTransferManager stateTransferManager, CacheLoaderManager cacheLoaderManager, Notifier notifier,
                           TransactionManager transactionManager, BuddyManager buddyManager, TransactionTable transactionTable,
                           RPCManager rpcManager, RegionManager regionManager, Marshaller marshaller,
-                          GlobalTransactionContainer transactionHelper, CommandsFactory commandsFactory, DataContainer dataContainer)
+                          CommandsFactory commandsFactory, DataContainer dataContainer)
    {
       this.stateTransferManager = stateTransferManager;
       this.cacheLoaderManager = cacheLoaderManager;
@@ -78,7 +76,6 @@
       this.marshaller = marshaller;
       this.dataContainer = dataContainer;
       this.commandsFactory = commandsFactory;
-      this.transactionHelper = transactionHelper;
    }
 
    private void reset()
@@ -187,12 +184,12 @@
 
    public GlobalTransaction getCurrentTransaction(Transaction tx, boolean createIfNotExists)
    {
-      return transactionHelper.getCurrentTransaction(tx, createIfNotExists);
+      return transactionTable.getCurrentTransaction(tx, createIfNotExists);
    }
 
    public GlobalTransaction getCurrentTransaction()
    {
-      return transactionHelper.getCurrentTransaction();
+      return transactionTable.getCurrentTransaction();
    }
 
    public Set<Fqn> getInternalFqns()
@@ -389,7 +386,7 @@
       {
          InvocationContext ctx = invocationContextContainer.get();
          cacheStatusCheck(ctx);
-         GlobalTransaction tx = transactionHelper.getCurrentTransaction();
+         GlobalTransaction tx = transactionTable.getCurrentTransaction();
          RemoveNodeCommand command = commandsFactory.buildRemoveNodeCommand(tx, fqn, false, false, true);
          Object retval = invoker.invoke(ctx, command);
          return retval != null && (Boolean) retval;
@@ -418,7 +415,7 @@
    {
       InvocationContext ctx = invocationContextContainer.get();
       cacheStatusCheck(ctx);
-      GlobalTransaction tx = transactionHelper.getCurrentTransaction();
+      GlobalTransaction tx = transactionTable.getCurrentTransaction();
       RemoveKeyCommand command = commandsFactory.buildRemoveKeyCommand(tx, fqn, key, true);
       return (V) invoker.invoke(ctx, command);
    }
@@ -464,7 +461,7 @@
    {
       InvocationContext ctx = invocationContextContainer.get();
       cacheStatusCheck(ctx);
-      GlobalTransaction tx = transactionHelper.getCurrentTransaction();
+      GlobalTransaction tx = transactionTable.getCurrentTransaction();
       PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(tx, fqn, key, value, false, false);
       return (V) invoker.invoke(ctx, command);
    }

Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -11,7 +11,6 @@
 import org.jboss.cache.factories.CommandsFactory;
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.GlobalTransactionContainer;
 import org.jboss.cache.transaction.TransactionEntry;
 import org.jboss.cache.transaction.TransactionTable;
 
@@ -84,7 +83,7 @@
     *
     * @param createIfNotExists  if true, then missing nodes will be cretaed on the fly. If false, method returns if we
     *                           reach a node that does not exists
-    * @param reverseRemoveCheck see {@link #manageReverseRemove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.NodeSPI, boolean)}
+    * @param reverseRemoveCheck see {@link #manageReverseRemove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.NodeSPI, boolean, java.util.List)}
     * @param createdNodes       a list to which any nodes created can register their Fqns so that calling code is aware of which nodes have been newly created.
     * @param skipNotification
     */
@@ -96,10 +95,8 @@
       GlobalTransaction gtx = ctx.getGlobalTransaction();
       boolean created = false;
       // if the tx associated with the current thread is rolling back, barf! JBCACHE-923
-      if (gtx != null)
-      {
-         GlobalTransactionContainer.assertTransactionValid(ctx);
-      }
+      if (gtx != null) TransactionTable.assertTransactionValid(ctx);
+
       Object owner = (gtx != null) ? gtx : currentThread;
       NodeSPI currentNode;
       if (log.isTraceEnabled()) log.trace("Attempting to lock node " + fqn + " for owner " + owner);
@@ -258,14 +255,15 @@
       if (gtx != null) //if no tx then reverse remove does not make sense
       {
          Fqn fqn = childNode.getFqn();
-         boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && txTable.isNodeRemovedInTx(gtx, fqn);
+         TransactionEntry entry = txTable.get(gtx);
+         boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && isNodeRemovedInCurrentTransaction(entry, fqn);
          if (!needToReverseRemove) return;
          childNode.markAsDeleted(false);
          //if we'll rollback the tx data should be added to the node again
          Map oldData = new HashMap(childNode.getDataDirect());
          PutDataMapCommand command = commandsFactory.buildPutDataMapCommand(gtx, fqn, oldData, false, false);
          // txTable.get(gtx).addUndoOperation(command); --- now need to make sure this is added to the normal mods list instead
-         txTable.get(gtx).addModification(command);
+         entry.addModification(command);
          //we're prepared for rollback, now reset the node
          childNode.clearDataDirect();
          if (createdNodes != null)
@@ -275,6 +273,11 @@
       }
    }
 
+   private boolean isNodeRemovedInCurrentTransaction(TransactionEntry entry, Fqn fqn)
+   {
+      return entry != null && entry.getRemovedNodes().contains(fqn);
+   }
+
    public void acquireLocksOnChildren(NodeSPI parentNode, NodeLock.LockType lockType, InvocationContext ctx) throws InterruptedException
    {
       acquireLocksOnChildren(parentNode, lockType, ctx, null, false);

Deleted: core/trunk/src/main/java/org/jboss/cache/transaction/GlobalTransactionContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/GlobalTransactionContainer.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/GlobalTransactionContainer.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -1,236 +0,0 @@
-package org.jboss.cache.transaction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.RPCManager;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jgroups.Address;
-
-import javax.transaction.Status;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-/**
- * A container class that holds, retrieves or creates {@link GlobalTransaction} objects and associates them with {@link Transaction} objects.
- *
- * @author Mircea.Markus at jboss.com
- * @since 2.2
- */
-public class GlobalTransactionContainer
-{
-   // TODO: 2.2.0: Can this be combined with TransactionTable?
-   private static final Log log = LogFactory.getLog(GlobalTransactionContainer.class);
-
-   /**
-    * Maintains mapping of transactions (keys) and Modifications/Undo-Operations
-    */
-   private TransactionTable transactionTable;
-
-   /**
-    * Used to get the Transaction associated with the current thread
-    */
-   private TransactionManager transactionManager = null;
-
-   private RPCManager rpcManager;
-
-   private boolean isOptimisticLocking;
-
-   @Inject
-   public void initialize(TransactionTable transactionTable, TransactionManager transactionManager,
-                          RPCManager rpcManager, Configuration configuration)
-   {
-      this.transactionTable = transactionTable;
-      this.transactionManager = transactionManager;
-      this.rpcManager = rpcManager;
-      isOptimisticLocking = configuration.isNodeLockingOptimistic();
-   }
-
-   /**
-    * Returns the transaction associated with the current thread.
-    * If a local transaction exists, but doesn't yet have a mapping to a
-    * GlobalTransaction, a new GlobalTransaction will be created and mapped to
-    * the local transaction.  Note that if a local transaction exists, but is
-    * not ACTIVE or PREPARING, null is returned.
-    *
-    * @return A GlobalTransaction, or null if no (local) transaction was associated with the current thread
-    */
-   public GlobalTransaction getCurrentTransaction()
-   {
-      return getCurrentTransaction(true);
-   }
-
-
-   /**
-    * Returns the transaction associated with the thread; optionally creating
-    * it if is does not exist.
-    */
-   public GlobalTransaction getCurrentTransaction(boolean createIfNotExists)
-   {
-      Transaction tx;
-
-      if ((tx = getLocalTransaction()) == null)
-      {// no transaction is associated with the current thread
-         return null;
-      }
-
-      if (!isValid(tx))
-      {// we got a non-null transaction, but it is not active anymore
-         int status = -1;
-         try
-         {
-            status = tx.getStatus();
-         }
-         catch (SystemException e)
-         {
-         }
-
-         // JBCACHE-982 -- don't complain if COMMITTED
-         if (status != Status.STATUS_COMMITTED)
-         {
-            log.warn("status is " + status + " (not ACTIVE or PREPARING); returning null)");
-         }
-         else
-         {
-            log.trace("status is COMMITTED; returning null");
-         }
-
-         return null;
-      }
-
-      return getCurrentTransaction(tx, createIfNotExists);
-   }
-
-   /**
-    * Returns the transaction associated with the current thread. We get the
-    * initial context and a reference to the TransactionManager to get the
-    * transaction. This method is used by {@link #getCurrentTransaction()}
-    */
-   protected Transaction getLocalTransaction()
-   {
-      if (transactionManager == null)
-      {
-         return null;
-      }
-      try
-      {
-         return transactionManager.getTransaction();
-      }
-      catch (Throwable t)
-      {
-         return null;
-      }
-   }
-
-   /**
-    * Returns true if transaction is ACTIVE, false otherwise
-    */
-   public static boolean isActive(Transaction tx)
-   {
-      if (tx == null) return false;
-      int status = -1;
-      try
-      {
-         status = tx.getStatus();
-         return status == Status.STATUS_ACTIVE;
-      }
-      catch (SystemException e)
-      {
-         return false;
-      }
-   }
-
-   /**
-    * Returns true if transaction is PREPARING, false otherwise
-    */
-   public static boolean isPreparing(Transaction tx)
-   {
-      if (tx == null) return false;
-      int status = -1;
-      try
-      {
-         status = tx.getStatus();
-         return status == Status.STATUS_PREPARING;
-      }
-      catch (SystemException e)
-      {
-         return false;
-      }
-   }
-
-   /**
-    * Return s true of tx's status is ACTIVE or PREPARING
-    *
-    * @param tx
-    * @return true if the tx is active or preparing
-    */
-   public static boolean isValid(Transaction tx)
-   {
-      return isActive(tx) || isPreparing(tx);
-   }
-
-   /**
-    * Tests whether the caller is in a valid transaction.  If not, will throw a CacheException.
-    */
-   public static void assertTransactionValid(InvocationContext ctx)
-   {
-      Transaction tx = ctx.getTransaction();
-      if (!isValid(tx)) try
-      {
-         throw new CacheException("Invalid transaction " + tx + ", status = " + (tx == null ? null : tx.getStatus()));
-      }
-      catch (SystemException e)
-      {
-         throw new CacheException("Exception trying to analyse status of transaction " + tx, e);
-      }
-   }
-
-
-   /**
-    * Returns the global transaction for this local transaction.
-    */
-   public GlobalTransaction getCurrentTransaction(Transaction tx)
-   {
-      return getCurrentTransaction(tx, true);
-   }
-
-   /**
-    * Returns the global transaction for this local transaction.
-    *
-    * @param createIfNotExists if true, if a global transaction is not found; one is created
-    */
-   public GlobalTransaction getCurrentTransaction(Transaction tx, boolean createIfNotExists)
-   {
-      // removed synchronization on txTable because underlying implementation is thread safe
-      // and JTA spec (section 3.4.3 Thread of Control, par 2) says that only one thread may
-      // operate on the transaction at one time so no concern about 2 threads trying to call
-      // this method for the same Transaction instance at the same time
-      //
-      GlobalTransaction gtx = transactionTable.get(tx);
-      if (gtx == null && createIfNotExists)
-      {
-         Address addr = rpcManager.getLocalAddress();
-         gtx = GlobalTransaction.create(addr);
-         transactionTable.put(tx, gtx);
-         TransactionEntry ent = null;
-         try
-         {
-            ent = isOptimisticLocking ? new OptimisticTransactionEntry(tx) : new TransactionEntry(tx);
-         }
-         catch (Exception e)
-         {
-            throw new CacheException("Unable to create a transaction entry!", e);
-         }
-
-         transactionTable.put(gtx, ent);
-         if (log.isTraceEnabled())
-         {
-            log.trace("created new GTX: " + gtx + ", local TX=" + tx);
-         }
-      }
-      return gtx;
-   }
-}

Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java	2008-04-28 18:31:24 UTC (rev 5735)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java	2008-04-28 18:56:13 UTC (rev 5736)
@@ -9,11 +9,18 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.CacheException;
-import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.RPCManager;
 import org.jboss.cache.commands.ReversibleCommand;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.lock.NodeLock;
+import org.jgroups.Address;
 
+import javax.transaction.Status;
+import javax.transaction.SystemException;
 import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
 import java.util.Collection;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -28,6 +35,7 @@
 public class TransactionTable
 {
    private static final Log log = LogFactory.getLog(TransactionTable.class);
+   private static boolean trace;
 
    /**
     * Mapping between local (javax.transaction.Transaction)
@@ -41,6 +49,21 @@
     */
    protected final Map<GlobalTransaction, TransactionEntry> gtx2EntryMap = new ConcurrentHashMap<GlobalTransaction, TransactionEntry>();
 
+   private TransactionManager transactionManager = null;
+
+   private RPCManager rpcManager;
+
+   private boolean isOptimisticLocking;
+
+   @Inject
+   public void initialize(TransactionManager transactionManager, RPCManager rpcManager, Configuration configuration)
+   {
+      this.transactionManager = transactionManager;
+      this.rpcManager = rpcManager;
+      isOptimisticLocking = configuration.isNodeLockingOptimistic();
+      trace = log.isTraceEnabled();
+   }
+
    /**
     * Returns the number of local transactions.
     */
@@ -234,7 +257,7 @@
 
    public void cleanup(GlobalTransaction gtx)
    {
-      if (log.isTraceEnabled()) log.trace("Cleaning up locks for globalTransaction " + gtx);
+      if (trace) log.trace("Cleaning up locks for globalTransaction " + gtx);
       TransactionEntry entry = this.get(gtx);
       // Let's do it in stack style, LIFO
       if (entry != null)
@@ -297,9 +320,188 @@
       }
    }
 
-   public boolean isNodeRemovedInTx(GlobalTransaction gtx, Fqn fqn)
+   /**
+    * Returns the transaction associated with the current thread.
+    * If a local transaction exists, but doesn't yet have a mapping to a
+    * GlobalTransaction, a new GlobalTransaction will be created and mapped to
+    * the local transaction.  Note that if a local transaction exists, but is
+    * not ACTIVE or PREPARING, null is returned.
+    *
+    * @return A GlobalTransaction, or null if no (local) transaction was associated with the current thread
+    */
+   public GlobalTransaction getCurrentTransaction()
    {
-      TransactionEntry te = get(gtx);
-      return te != null && te.getRemovedNodes().contains(fqn);
+      return getCurrentTransaction(true);
    }
+
+
+   /**
+    * Returns the transaction associated with the thread; optionally creating
+    * it if is does not exist.
+    */
+   public GlobalTransaction getCurrentTransaction(boolean createIfNotExists)
+   {
+      Transaction tx;
+
+      if ((tx = getLocalTransaction()) == null)
+      {// no transaction is associated with the current thread
+         return null;
+      }
+
+      if (!isValid(tx))
+      {// we got a non-null transaction, but it is not active anymore
+         int status = -1;
+         try
+         {
+            status = tx.getStatus();
+         }
+         catch (SystemException e)
+         {
+         }
+
+         // JBCACHE-982 -- don't complain if COMMITTED
+         if (status != Status.STATUS_COMMITTED)
+         {
+            log.warn("status is " + status + " (not ACTIVE or PREPARING); returning null)");
+         }
+         else
+         {
+            log.trace("status is COMMITTED; returning null");
+         }
+
+         return null;
+      }
+
+      return getCurrentTransaction(tx, createIfNotExists);
+   }
+
+   /**
+    * Returns the transaction associated with the current thread. We get the
+    * initial context and a reference to the TransactionManager to get the
+    * transaction. This method is used by {@link #getCurrentTransaction()}
+    */
+   protected Transaction getLocalTransaction()
+   {
+      if (transactionManager == null)
+      {
+         return null;
+      }
+      try
+      {
+         return transactionManager.getTransaction();
+      }
+      catch (Throwable t)
+      {
+         return null;
+      }
+   }
+
+   /**
+    * Returns true if transaction is ACTIVE, false otherwise
+    */
+   public static boolean isActive(Transaction tx)
+   {
+      if (tx == null) return false;
+      int status = -1;
+      try
+      {
+         status = tx.getStatus();
+         return status == Status.STATUS_ACTIVE;
+      }
+      catch (SystemException e)
+      {
+         return false;
+      }
+   }
+
+   /**
+    * Returns true if transaction is PREPARING, false otherwise
+    */
+   public static boolean isPreparing(Transaction tx)
+   {
+      if (tx == null) return false;
+      int status = -1;
+      try
+      {
+         status = tx.getStatus();
+         return status == Status.STATUS_PREPARING;
+      }
+      catch (SystemException e)
+      {
+         return false;
+      }
+   }
+
+   /**
+    * Return s true of tx's status is ACTIVE or PREPARING
+    *
+    * @param tx
+    * @return true if the tx is active or preparing
+    */
+   public static boolean isValid(Transaction tx)
+   {
+      return isActive(tx) || isPreparing(tx);
+   }
+
+   /**
+    * Tests whether the caller is in a valid transaction.  If not, will throw a CacheException.
+    */
+   public static void assertTransactionValid(InvocationContext ctx)
+   {
+      Transaction tx = ctx.getTransaction();
+      if (!isValid(tx)) try
+      {
+         throw new CacheException("Invalid transaction " + tx + ", status = " + (tx == null ? null : tx.getStatus()));
+      }
+      catch (SystemException e)
+      {
+         throw new CacheException("Exception trying to analyse status of transaction " + tx, e);
+      }
+   }
+
+
+   /**
+    * Returns the global transaction for this local transaction.
+    */
+   public GlobalTransaction getCurrentTransaction(Transaction tx)
+   {
+      return getCurrentTransaction(tx, true);
+   }
+
+   /**
+    * Returns the global transaction for this local transaction.
+    *
+    * @param createIfNotExists if true, if a global transaction is not found; one is created
+    */
+   public GlobalTransaction getCurrentTransaction(Transaction tx, boolean createIfNotExists)
+   {
+      // removed synchronization on txTable because underlying implementation is thread safe
+      // and JTA spec (section 3.4.3 Thread of Control, par 2) says that only one thread may
+      // operate on the transaction at one time so no concern about 2 threads trying to call
+      // this method for the same Transaction instance at the same time
+      //
+      GlobalTransaction gtx = get(tx);
+      if (gtx == null && createIfNotExists)
+      {
+         Address addr = rpcManager.getLocalAddress();
+         gtx = GlobalTransaction.create(addr);
+         put(tx, gtx);
+         TransactionEntry ent;
+         try
+         {
+            ent = isOptimisticLocking ? new OptimisticTransactionEntry(tx) : new TransactionEntry(tx);
+         }
+         catch (Exception e)
+         {
+            throw new CacheException("Unable to create a transaction entry!", e);
+         }
+
+         put(gtx, ent);
+         if (trace)
+         {
+            log.trace("created new GTX: " + gtx + ", local TX=" + tx);
+         }
+      }
+      return gtx;
+   }
 }




More information about the jbosscache-commits mailing list