[jbosscache-commits] JBoss Cache SVN: r6059 - core/trunk/src/main/java/org/jboss/cache.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Jun 26 12:32:57 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-06-26 12:32:57 -0400 (Thu, 26 Jun 2008)
New Revision: 6059

Removed:
   core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
Log:


Deleted: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java	2008-06-26 15:44:26 UTC (rev 6058)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java	2008-06-26 16:32:57 UTC (rev 6059)
@@ -1,609 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.commands.VisitableCommand;
-import org.jboss.cache.config.Option;
-import org.jboss.cache.lock.NodeLock;
-import org.jboss.cache.marshall.MethodCall;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.TransactionContext;
-import org.jboss.cache.transaction.TransactionTable;
-
-import javax.transaction.Transaction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-
-/**
- * This context holds information specific to a method invocation.
- *
- * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
- */
- at SuppressWarnings("deprecation")
-public class InvocationContext
-{
-   private static final Log log = LogFactory.getLog(InvocationContext.class);
-   private static final boolean trace = log.isTraceEnabled();
-
-   private Transaction transaction;
-   private GlobalTransaction globalTransaction;
-   private TransactionContext transactionContext;
-   private Option optionOverrides;
-   // defaults to true.
-   private boolean originLocal = true;
-   private boolean txHasMods;
-   private boolean localRollbackOnly;
-   @Deprecated
-   private MethodCall methodCall;
-   @Deprecated
-   private VisitableCommand command;
-
-   /**
-    * LinkedHashSet of locks acquired by the invocation. We use a LinkedHashSet because we need efficient Set semantics
-    * but also need guaranteed ordering for use by lock release code (see JBCCACHE-874).
-    * <p/>
-    * This needs to be unchecked since we support both MVCC (Fqns held here) or legacy Opt/Pess locking (NodeLocks held here).
-    * once we drop support for opt/pess locks we can genericise this to contain Fqns. - Manik Surtani, June 2008
-    */
-   private LinkedHashSet invocationLocks;
-
-   private final Map<Fqn, NodeSPI> lookedUpNodes = new HashMap<Fqn, NodeSPI>();
-
-   /**
-    * Retrieves a node from the registry of looked up nodes in the current scope.
-    * <p/>
-    * If a transaction is in progress, this method will delegate to {@link org.jboss.cache.transaction.TransactionContext#lookUpNode(Fqn)}
-    * <p/>
-    *
-    * @param fqn fqn to look up
-    * @return a node, or null if it cannot be found.
-    * @since 3.0.
-    */
-   public NodeSPI lookUpNode(Fqn fqn)
-   {
-      if (transactionContext != null) return transactionContext.lookUpNode(fqn);
-      return lookedUpNodes.get(fqn);
-   }
-
-   /**
-    * Puts an entry in the registry of looked up nodes in the current scope.
-    * <p/>
-    * If a transaction is in progress, this method will delegate to {@link org.jboss.cache.transaction.TransactionContext#putLookedUpNode(Fqn, NodeSPI)}
-    * <p/>
-    *
-    * @param f fqn to add
-    * @param n node to add
-    * @since 3.0.
-    */
-   public void putLookedUpNode(Fqn f, NodeSPI n)
-   {
-      if (transactionContext != null)
-         transactionContext.putLookedUpNode(f, n);
-      else
-         lookedUpNodes.put(f, n);
-   }
-
-   /**
-    * Clears the registry of looked up nodes.
-    * <p/>
-    * If a transaction is in progress, this method will delegate to {@link org.jboss.cache.transaction.TransactionContext#clearLookedUpNodes()}.
-    * <p/>
-    *
-    * @since 3.0.
-    */
-   public void clearLookedUpNodes()
-   {
-      if (transactionContext != null)
-         transactionContext.clearLookedUpNodes();
-      else
-         lookedUpNodes.clear();
-   }
-
-   /**
-    * Retrieves a map of nodes looked up within the current invocation's scope.
-    * <p/>
-    * If a transaction is in progress, this method will delegate to {@link org.jboss.cache.transaction.TransactionContext#getLookedUpNodes()}.
-    * <p/>
-    *
-    * @return a map of looked up nodes.
-    * @since 3.0
-    */
-   public Map<Fqn, NodeSPI> getLookedUpNodes()
-   {
-      if (transactionContext != null) return transactionContext.getLookedUpNodes();
-      return lookedUpNodes;
-   }
-
-   public void setLocalRollbackOnly(boolean localRollbackOnly)
-   {
-      this.localRollbackOnly = localRollbackOnly;
-   }
-
-   /**
-    * Retrieves the transaction associated with this invocation
-    *
-    * @return The transaction associated with this invocation
-    */
-   public Transaction getTransaction()
-   {
-      return transaction;
-   }
-
-   /**
-    * Sets the transaction associated with this invocation
-    *
-    * @param transaction
-    */
-   public void setTransaction(Transaction transaction)
-   {
-      this.transaction = transaction;
-   }
-
-   /**
-    * @return the transaction entry associated with the current transaction, or null if the current thread is not associated with a transaction.
-    * @since 2.2.0
-    */
-   public TransactionContext getTransactionContext()
-   {
-      return transactionContext;
-   }
-
-   /**
-    * Sets the transaction entry to be associated with the current thread.
-    *
-    * @param transactionContext transaction entry to set
-    * @since 2.2.0
-    */
-   public void setTransactionContext(TransactionContext transactionContext)
-   {
-      this.transactionContext = transactionContext;
-   }
-
-   /**
-    * Retrieves the global transaction associated with this invocation
-    *
-    * @return the global transaction associated with this invocation
-    */
-   public GlobalTransaction getGlobalTransaction()
-   {
-      return globalTransaction;
-   }
-
-   /**
-    * Sets the global transaction associated with this invocation
-    *
-    * @param globalTransaction
-    */
-   public void setGlobalTransaction(GlobalTransaction globalTransaction)
-   {
-      this.globalTransaction = globalTransaction;
-   }
-
-   /**
-    * Retrieves the option overrides associated with this invocation
-    *
-    * @return the option overrides associated with this invocation
-    */
-   public Option getOptionOverrides()
-   {
-      if (optionOverrides == null)
-      {
-         optionOverrides = new Option();
-      }
-      return optionOverrides;
-   }
-
-   public boolean isOptionsUninitialised()
-   {
-      return optionOverrides == null;
-   }
-
-   /**
-    * Sets the option overrides associated with this invocation
-    *
-    * @param optionOverrides
-    */
-   public void setOptionOverrides(Option optionOverrides)
-   {
-      this.optionOverrides = optionOverrides;
-   }
-
-   /**
-    * Tests if this invocation originated locally or from a remote cache.
-    *
-    * @return true if the invocation originated locally.
-    */
-   public boolean isOriginLocal()
-   {
-      return originLocal;
-   }
-
-   /**
-    * Returns an immutable,  defensive copy of the List of locks currently maintained for the current scope.
-    * <p/>
-    * Note that if a transaction is in scope, these locks are retrieved from the {@link org.jboss.cache.transaction.TransactionContext} rather than
-    * this {@link org.jboss.cache.InvocationContext}.  Retrieving locks from here will ensure they are retrieved from  the appropriate
-    * scope.
-    * <p/>
-    * Note that currently (as of 3.0.0) this list is unchecked.  This is to allow support for both MVCC (which uses Fqns as locks)
-    * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link NodeLock} as locks).  Once support for
-    * legacy node locking schemes are dropped, this method will be more strongly typed to return <tt>List<Fqn></tt>.
-    *
-    * @return locks held in current scope.
-    */
-   @SuppressWarnings("unchecked")
-   public List getLocks()
-   {
-      // first check transactional scope
-      if (transactionContext != null) return transactionContext.getLocks();
-      return invocationLocks == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList(invocationLocks));
-   }
-
-   /**
-    * Adds a List of locks to the currently maintained collection of locks acquired.
-    * <p/>
-    * Note that if a transaction is in scope, these locks are recorded on the {@link org.jboss.cache.transaction.TransactionContext} rather than
-    * this {@link org.jboss.cache.InvocationContext}.  Adding locks here will ensure they are promoted to the appropriate
-    * scope.
-    * <p/>
-    * Note that currently (as of 3.0.0) this list is unchecked.  This is to allow support for both MVCC (which uses Fqns as locks)
-    * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link NodeLock} as locks).  Once support for
-    * legacy node locking schemes are dropped, this method will be more strongly typed to accept <tt>List<Fqn></tt>.
-    *
-    * @param locks locks to add
-    */
-   @SuppressWarnings("unchecked")
-   public void addAllLocks(List locks)
-   {
-      // first check transactional scope
-      if (transactionContext != null)
-      {
-         transactionContext.addAllLocks(locks);
-      }
-      else
-      {
-         // no need to worry about concurrency here - a context is only valid for a single thread.
-         if (invocationLocks == null) invocationLocks = new LinkedHashSet(5);
-         invocationLocks.addAll(locks);
-      }
-   }
-
-   /**
-    * Adds a lock to the currently maintained collection of locks acquired.
-    * <p/>
-    * Note that if a transaction is in scope, this lock is recorded on the {@link org.jboss.cache.transaction.TransactionContext} rather than
-    * this {@link org.jboss.cache.InvocationContext}.  Adding a lock here will ensure it is promoted to the appropriate
-    * scope.
-    * <p/>
-    * Note that currently (as of 3.0.0) this lock is weakly typed.  This is to allow support for both MVCC (which uses {@link Fqn}s as locks)
-    * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link NodeLock} as locks).  Once support for
-    * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link Fqn}.
-    *
-    * @param lock lock to add
-    */
-   @SuppressWarnings("unchecked")
-   public void addLock(Object lock)
-   {
-      // first check transactional scope
-      if (transactionContext != null)
-      {
-         transactionContext.addLock(lock);
-      }
-      else
-      {
-         // no need to worry about concurrency here - a context is only valid for a single thread.
-         if (invocationLocks == null) invocationLocks = new LinkedHashSet(5);
-         invocationLocks.add(lock);
-      }
-   }
-
-   /**
-    * Removes a lock from the currently maintained collection of locks acquired.
-    * <p/>
-    * Note that if a transaction is in scope, this lock is removed from the {@link org.jboss.cache.transaction.TransactionContext} rather than
-    * this {@link org.jboss.cache.InvocationContext}.  Removing a lock here will ensure it is removed in the appropriate
-    * scope.
-    * <p/>
-    * Note that currently (as of 3.0.0) this lock is weakly typed.  This is to allow support for both MVCC (which uses {@link Fqn}s as locks)
-    * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link NodeLock} as locks).  Once support for
-    * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link Fqn}.
-    *
-    * @param lock lock to remove
-    */
-   @SuppressWarnings("unchecked")
-   public void removeLock(Object lock)
-   {
-      // first check transactional scope
-      if (transactionContext != null)
-      {
-         transactionContext.removeLock(lock);
-      }
-      else
-      {
-         // no need to worry about concurrency here - a context is only valid for a single thread.
-         if (invocationLocks != null) invocationLocks.remove(lock);
-      }
-   }
-
-   /**
-    * Clears all locks from the currently maintained collection of locks acquired.
-    * <p/>
-    * Note that if a transaction is in scope, locks are cleared from the {@link org.jboss.cache.transaction.TransactionContext} rather than
-    * this {@link org.jboss.cache.InvocationContext}.  Clearing locks here will ensure they are cleared in the appropriate
-    * scope.
-    * <p/>
-    * Note that currently (as of 3.0.0) this lock is weakly typed.  This is to allow support for both MVCC (which uses {@link Fqn}s as locks)
-    * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link NodeLock} as locks).  Once support for
-    * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link Fqn}.
-    */
-   public void clearLocks()
-   {
-      // first check transactional scope
-      if (transactionContext != null)
-      {
-         transactionContext.clearLocks();
-      }
-      else
-      {
-         // no need to worry about concurrency here - a context is only valid for a single thread.
-         if (invocationLocks != null) invocationLocks.clear();
-      }
-   }
-
-   /**
-    * @return true if options exist to suppress locking - false otherwise.  Note that this is only used by the {@link org.jboss.cache.interceptors.PessimisticLockInterceptor}.
-    */
-   public boolean isLockingSuppressed()
-   {
-      return getOptionOverrides() != null && getOptionOverrides().isSuppressLocking();
-   }
-
-   /**
-    * If set to true, the invocation is assumed to have originated locally.  If set to false,
-    * assumed to have originated from a remote cache.
-    *
-    * @param originLocal
-    */
-   public void setOriginLocal(boolean originLocal)
-   {
-      this.originLocal = originLocal;
-   }
-
-   @Override
-   public String toString()
-   {
-      return "InvocationContext{" +
-            "transaction=" + transaction +
-            ", globalTransaction=" + globalTransaction +
-            ", optionOverrides=" + optionOverrides +
-            ", originLocal=" + originLocal +
-            ", txHasMods=" + txHasMods +
-            '}';
-   }
-
-   public boolean isTxHasMods()
-   {
-      return txHasMods;
-   }
-
-   public void setTxHasMods(boolean b)
-   {
-      txHasMods = b;
-   }
-
-   public boolean isLocalRollbackOnly()
-   {
-      return localRollbackOnly;
-   }
-
-   /**
-    * Resets this to the defaults used when constructing an invocation context object
-    */
-   public void reset()
-   {
-      transaction = null;
-      globalTransaction = null;
-      optionOverrides = null;
-      originLocal = true;
-      txHasMods = false;
-      invocationLocks = null;
-      methodCall = null;
-      command = null;
-   }
-
-   /**
-    * This is a "copy-factory-method" that should be used whenever a clone of this class is needed.  The resulting instance
-    * is equal() to, but not ==, to the InvocationContext invoked on.  Note that this is a shallow copy with the exception
-    * of the Option object, which is deep, as well as any collections held on the context such as locks.  Note that the reference
-    * to a TransactionEntry, if any, is maintained.
-    *
-    * @return a new InvocationContext
-    */
-   @SuppressWarnings("unchecked")
-   public InvocationContext copy()
-   {
-      InvocationContext copy = new InvocationContext();
-      copy.command = command;
-      copy.globalTransaction = globalTransaction;
-      copy.invocationLocks = invocationLocks == null ? null : new LinkedHashSet(invocationLocks);
-      copy.localRollbackOnly = localRollbackOnly;
-      copy.lookedUpNodes.putAll(lookedUpNodes);
-      copy.optionOverrides = optionOverrides == null ? null : optionOverrides.copy();
-      copy.originLocal = originLocal;
-      copy.transaction = transaction;
-      copy.transactionContext = transactionContext;
-      copy.txHasMods = txHasMods;
-      return null;
-   }
-
-   /**
-    * Sets the state of the InvocationContext based on the template context passed in
-    *
-    * @param template
-    */
-   public void setState(InvocationContext template)
-   {
-      if (template == null)
-      {
-         throw new NullPointerException("Template InvocationContext passed in to InvocationContext.setState() passed in is null");
-      }
-
-      this.setGlobalTransaction(template.getGlobalTransaction());
-      this.setLocalRollbackOnly(template.isLocalRollbackOnly());
-      this.setOptionOverrides(template.getOptionOverrides());
-      this.setOriginLocal(template.isOriginLocal());
-      this.setTransaction(template.getTransaction());
-      this.setTxHasMods(template.isTxHasMods());
-   }
-
-   @Override
-   public boolean equals(Object o)
-   {
-      if (this == o) return true;
-      if (o == null || getClass() != o.getClass()) return false;
-
-      final InvocationContext that = (InvocationContext) o;
-
-      if (localRollbackOnly != that.localRollbackOnly) return false;
-      if (originLocal != that.originLocal) return false;
-      if (txHasMods != that.txHasMods) return false;
-      if (globalTransaction != null ? !globalTransaction.equals(that.globalTransaction) : that.globalTransaction != null)
-      {
-         return false;
-      }
-      if (optionOverrides != null ? !optionOverrides.equals(that.optionOverrides) : that.optionOverrides != null)
-      {
-         return false;
-      }
-      if (transaction != null ? !transaction.equals(that.transaction) : that.transaction != null) return false;
-
-      return true;
-   }
-
-   @Override
-   public int hashCode()
-   {
-      int result;
-      result = (transaction != null ? transaction.hashCode() : 0);
-      result = 29 * result + (globalTransaction != null ? globalTransaction.hashCode() : 0);
-      result = 29 * result + (optionOverrides != null ? optionOverrides.hashCode() : 0);
-      result = 29 * result + (originLocal ? 1 : 0);
-      result = 29 * result + (txHasMods ? 1 : 0);
-      result = 29 * result + (localRollbackOnly ? 1 : 0);
-      return result;
-   }
-
-   /**
-    * @return the method call associated with this invocation
-    */
-   @Deprecated
-   @SuppressWarnings("deprecation")
-   public MethodCall getMethodCall()
-   {
-      if (methodCall == null)
-      {
-         methodCall = createMethodCall();
-      }
-      return methodCall;
-   }
-
-   @SuppressWarnings("deprecation")
-   private MethodCall createMethodCall()
-   {
-      if (command == null) return null;
-      MethodCall call = new MethodCall();
-      call.setMethodId(command.getCommandId());
-      call.setArgs(command.getParameters());
-      return call;
-   }
-
-
-   /**
-    * Sets the method call associated with this invocation.
-    *
-    * @param methodCall methodcall to set
-    * @deprecated not used anymore.  Interceptors will get a {@link org.jboss.cache.commands.ReplicableCommand} instance passed in along with an InvocationContext.
-    */
-   @Deprecated
-   public void setMethodCall(MethodCall methodCall)
-   {
-      this.methodCall = methodCall;
-   }
-
-   /**
-    * Factory method that creates a context with a given method call.
-    *
-    * @param methodCall methodcall to use
-    * @return invocation context
-    */
-   public static InvocationContext fromMethodCall(MethodCall methodCall)
-   {
-      InvocationContext ctx = new InvocationContext();
-      ctx.methodCall = methodCall;
-      return ctx;
-   }
-
-   /**
-    * If the acq timeout if overwritten for current call, then return that one.
-    * If not overwritten return default value.
-    */
-   public long getContextLockAcquisitionTimeout(long timeout)
-   {
-      if (getOptionOverrides() != null
-            && getOptionOverrides().getLockAcquisitionTimeout() >= 0)
-      {
-         timeout = getOptionOverrides().getLockAcquisitionTimeout();
-      }
-      return timeout;
-   }
-
-   /**
-    * This is only used for backward compatibility with old interceptors implementation and should <b>NOT</b> be
-    * use by any new custom interceptors. The commands is now passed in as the second param in each implementing
-    * handlers (handler = method in ChainedInterceptor class)
-    */
-   @Deprecated
-   @SuppressWarnings("deprecation")
-   public void setCommand(VisitableCommand cacheCommand)
-   {
-      this.command = cacheCommand;
-   }
-
-   /**
-    * @see #setCommand(org.jboss.cache.commands.VisitableCommand)
-    */
-   @Deprecated
-   @SuppressWarnings("deprecation")
-   public VisitableCommand getCommand()
-   {
-      return command;
-   }
-
-   public boolean isValidTransaction()
-   {
-      return transaction != null && TransactionTable.isValid(transaction);
-   }
-
-   public void throwIfNeeded(Throwable e) throws Throwable
-   {
-      Option optionOverride = getOptionOverrides();
-      boolean shouldRethtrow = optionOverride == null || !optionOverride.isFailSilently();
-      if (!shouldRethtrow)
-      {
-         if (trace)
-            log.trace("There was a problem handling this request, but failSilently was set, so suppressing exception", e);
-         return;
-      }
-      throw e;
-   }
-}




More information about the jbosscache-commits mailing list