From jbosscache-commits at lists.jboss.org Thu Jun 26 12:32:57 2008 Content-Type: multipart/mixed; boundary="===============7067986116345013670==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r6059 - core/trunk/src/main/java/org/jboss/cache. Date: Thu, 26 Jun 2008 12:32:57 -0400 Message-ID: --===============7067986116345013670== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 Manik Surtani (manik(a)jbo= ss.org) - */ -(a)SuppressWarnings("deprecation") -public class InvocationContext -{ - private static final Log log =3D LogFactory.getLog(InvocationContext.cl= ass); - private static final boolean trace =3D log.isTraceEnabled(); - - private Transaction transaction; - private GlobalTransaction globalTransaction; - private TransactionContext transactionContext; - private Option optionOverrides; - // defaults to true. - private boolean originLocal =3D 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 LinkedHa= shSet because we need efficient Set semantics - * but also need guaranteed ordering for use by lock release code (see = JBCCACHE-874). - *

- * This needs to be unchecked since we support both MVCC (Fqns held her= e) or legacy Opt/Pess locking (NodeLocks held here). - * once we drop support for opt/pess locks we can genericise this to co= ntain Fqns. - Manik Surtani, June 2008 - */ - private LinkedHashSet invocationLocks; - - private final Map lookedUpNodes =3D new HashMap(); - - /** - * Retrieves a node from the registry of looked up nodes in the current= scope. - *

- * If a transaction is in progress, this method will delegate to {@link= org.jboss.cache.transaction.TransactionContext#lookUpNode(Fqn)} - *

- * - * @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 !=3D null) return transactionContext.lookUpNo= de(fqn); - return lookedUpNodes.get(fqn); - } - - /** - * Puts an entry in the registry of looked up nodes in the current scop= e. - *

- * If a transaction is in progress, this method will delegate to {@link= org.jboss.cache.transaction.TransactionContext#putLookedUpNode(Fqn, NodeSP= I)} - *

- * - * @param f fqn to add - * @param n node to add - * @since 3.0. - */ - public void putLookedUpNode(Fqn f, NodeSPI n) - { - if (transactionContext !=3D null) - transactionContext.putLookedUpNode(f, n); - else - lookedUpNodes.put(f, n); - } - - /** - * Clears the registry of looked up nodes. - *

- * If a transaction is in progress, this method will delegate to {@link= org.jboss.cache.transaction.TransactionContext#clearLookedUpNodes()}. - *

- * - * @since 3.0. - */ - public void clearLookedUpNodes() - { - if (transactionContext !=3D null) - transactionContext.clearLookedUpNodes(); - else - lookedUpNodes.clear(); - } - - /** - * Retrieves a map of nodes looked up within the current invocation's s= cope. - *

- * If a transaction is in progress, this method will delegate to {@link= org.jboss.cache.transaction.TransactionContext#getLookedUpNodes()}. - *

- * - * @return a map of looked up nodes. - * @since 3.0 - */ - public Map getLookedUpNodes() - { - if (transactionContext !=3D null) return transactionContext.getLooke= dUpNodes(); - return lookedUpNodes; - } - - public void setLocalRollbackOnly(boolean localRollbackOnly) - { - this.localRollbackOnly =3D 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 =3D transaction; - } - - /** - * @return the transaction entry associated with the current transactio= n, 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 =3D 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 =3D globalTransaction; - } - - /** - * Retrieves the option overrides associated with this invocation - * - * @return the option overrides associated with this invocation - */ - public Option getOptionOverrides() - { - if (optionOverrides =3D=3D null) - { - optionOverrides =3D new Option(); - } - return optionOverrides; - } - - public boolean isOptionsUninitialised() - { - return optionOverrides =3D=3D null; - } - - /** - * Sets the option overrides associated with this invocation - * - * @param optionOverrides - */ - public void setOptionOverrides(Option optionOverrides) - { - this.optionOverrides =3D 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. - *

- * Note that if a transaction is in scope, these locks are retrieved fr= om the {@link org.jboss.cache.transaction.TransactionContext} rather than - * this {@link org.jboss.cache.InvocationContext}. Retrieving locks fr= om here will ensure they are retrieved from the appropriate - * scope. - *

- * Note that currently (as of 3.0.0) this list is unchecked. This is t= o 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 st= rongly typed to return List. - * - * @return locks held in current scope. - */ - @SuppressWarnings("unchecked") - public List getLocks() - { - // first check transactional scope - if (transactionContext !=3D null) return transactionContext.getLocks= (); - return invocationLocks =3D=3D null ? Collections.emptyList() : Colle= ctions.unmodifiableList(new ArrayList(invocationLocks)); - } - - /** - * Adds a List of locks to the currently maintained collection of locks= acquired. - *

- * 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 w= ill ensure they are promoted to the appropriate - * scope. - *

- * Note that currently (as of 3.0.0) this list is unchecked. This is t= o 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 st= rongly typed to accept List. - * - * @param locks locks to add - */ - @SuppressWarnings("unchecked") - public void addAllLocks(List locks) - { - // first check transactional scope - if (transactionContext !=3D null) - { - transactionContext.addAllLocks(locks); - } - else - { - // no need to worry about concurrency here - a context is only va= lid for a single thread. - if (invocationLocks =3D=3D null) invocationLocks =3D new LinkedHa= shSet(5); - invocationLocks.addAll(locks); - } - } - - /** - * Adds a lock to the currently maintained collection of locks acquired. - *

- * 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. - *

- * Note that currently (as of 3.0.0) this lock is weakly typed. This i= s 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 st= rongly typed to accept {@link Fqn}. - * - * @param lock lock to add - */ - @SuppressWarnings("unchecked") - public void addLock(Object lock) - { - // first check transactional scope - if (transactionContext !=3D null) - { - transactionContext.addLock(lock); - } - else - { - // no need to worry about concurrency here - a context is only va= lid for a single thread. - if (invocationLocks =3D=3D null) invocationLocks =3D new LinkedHa= shSet(5); - invocationLocks.add(lock); - } - } - - /** - * Removes a lock from the currently maintained collection of locks acq= uired. - *

- * Note that if a transaction is in scope, this lock is removed from th= e {@link org.jboss.cache.transaction.TransactionContext} rather than - * this {@link org.jboss.cache.InvocationContext}. Removing a lock her= e will ensure it is removed in the appropriate - * scope. - *

- * Note that currently (as of 3.0.0) this lock is weakly typed. This i= s 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 st= rongly typed to accept {@link Fqn}. - * - * @param lock lock to remove - */ - @SuppressWarnings("unchecked") - public void removeLock(Object lock) - { - // first check transactional scope - if (transactionContext !=3D null) - { - transactionContext.removeLock(lock); - } - else - { - // no need to worry about concurrency here - a context is only va= lid for a single thread. - if (invocationLocks !=3D null) invocationLocks.remove(lock); - } - } - - /** - * Clears all locks from the currently maintained collection of locks a= cquired. - *

- * 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. - *

- * Note that currently (as of 3.0.0) this lock is weakly typed. This i= s 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 st= rongly typed to accept {@link Fqn}. - */ - public void clearLocks() - { - // first check transactional scope - if (transactionContext !=3D null) - { - transactionContext.clearLocks(); - } - else - { - // no need to worry about concurrency here - a context is only va= lid for a single thread. - if (invocationLocks !=3D 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.Pe= ssimisticLockInterceptor}. - */ - public boolean isLockingSuppressed() - { - return getOptionOverrides() !=3D null && getOptionOverrides().isSupp= ressLocking(); - } - - /** - * 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 =3D originLocal; - } - - @Override - public String toString() - { - return "InvocationContext{" + - "transaction=3D" + transaction + - ", globalTransaction=3D" + globalTransaction + - ", optionOverrides=3D" + optionOverrides + - ", originLocal=3D" + originLocal + - ", txHasMods=3D" + txHasMods + - '}'; - } - - public boolean isTxHasMods() - { - return txHasMods; - } - - public void setTxHasMods(boolean b) - { - txHasMods =3D b; - } - - public boolean isLocalRollbackOnly() - { - return localRollbackOnly; - } - - /** - * Resets this to the defaults used when constructing an invocation con= text object - */ - public void reset() - { - transaction =3D null; - globalTransaction =3D null; - optionOverrides =3D null; - originLocal =3D true; - txHasMods =3D false; - invocationLocks =3D null; - methodCall =3D null; - command =3D 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 =3D=3D, 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 =3D new InvocationContext(); - copy.command =3D command; - copy.globalTransaction =3D globalTransaction; - copy.invocationLocks =3D invocationLocks =3D=3D null ? null : new Li= nkedHashSet(invocationLocks); - copy.localRollbackOnly =3D localRollbackOnly; - copy.lookedUpNodes.putAll(lookedUpNodes); - copy.optionOverrides =3D optionOverrides =3D=3D null ? null : option= Overrides.copy(); - copy.originLocal =3D originLocal; - copy.transaction =3D transaction; - copy.transactionContext =3D transactionContext; - copy.txHasMods =3D txHasMods; - return null; - } - - /** - * Sets the state of the InvocationContext based on the template contex= t passed in - * - * @param template - */ - public void setState(InvocationContext template) - { - if (template =3D=3D 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 =3D=3D o) return true; - if (o =3D=3D null || getClass() !=3D o.getClass()) return false; - - final InvocationContext that =3D (InvocationContext) o; - - if (localRollbackOnly !=3D that.localRollbackOnly) return false; - if (originLocal !=3D that.originLocal) return false; - if (txHasMods !=3D that.txHasMods) return false; - if (globalTransaction !=3D null ? !globalTransaction.equals(that.glo= balTransaction) : that.globalTransaction !=3D null) - { - return false; - } - if (optionOverrides !=3D null ? !optionOverrides.equals(that.optionO= verrides) : that.optionOverrides !=3D null) - { - return false; - } - if (transaction !=3D null ? !transaction.equals(that.transaction) : = that.transaction !=3D null) return false; - - return true; - } - - @Override - public int hashCode() - { - int result; - result =3D (transaction !=3D null ? transaction.hashCode() : 0); - result =3D 29 * result + (globalTransaction !=3D null ? globalTransa= ction.hashCode() : 0); - result =3D 29 * result + (optionOverrides !=3D null ? optionOverride= s.hashCode() : 0); - result =3D 29 * result + (originLocal ? 1 : 0); - result =3D 29 * result + (txHasMods ? 1 : 0); - result =3D 29 * result + (localRollbackOnly ? 1 : 0); - return result; - } - - /** - * @return the method call associated with this invocation - */ - @Deprecated - @SuppressWarnings("deprecation") - public MethodCall getMethodCall() - { - if (methodCall =3D=3D null) - { - methodCall =3D createMethodCall(); - } - return methodCall; - } - - @SuppressWarnings("deprecation") - private MethodCall createMethodCall() - { - if (command =3D=3D null) return null; - MethodCall call =3D 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.jb= oss.cache.commands.ReplicableCommand} instance passed in along with an Invo= cationContext. - */ - @Deprecated - public void setMethodCall(MethodCall methodCall) - { - this.methodCall =3D 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 =3D new InvocationContext(); - ctx.methodCall =3D 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() !=3D null - && getOptionOverrides().getLockAcquisitionTimeout() >=3D 0) - { - timeout =3D getOptionOverrides().getLockAcquisitionTimeout(); - } - return timeout; - } - - /** - * This is only used for backward compatibility with old interceptors i= mplementation and should NOT be - * use by any new custom interceptors. The commands is now passed in as= the second param in each implementing - * handlers (handler =3D method in ChainedInterceptor class) - */ - @Deprecated - @SuppressWarnings("deprecation") - public void setCommand(VisitableCommand cacheCommand) - { - this.command =3D cacheCommand; - } - - /** - * @see #setCommand(org.jboss.cache.commands.VisitableCommand) - */ - @Deprecated - @SuppressWarnings("deprecation") - public VisitableCommand getCommand() - { - return command; - } - - public boolean isValidTransaction() - { - return transaction !=3D null && TransactionTable.isValid(transaction= ); - } - - public void throwIfNeeded(Throwable e) throws Throwable - { - Option optionOverride =3D getOptionOverrides(); - boolean shouldRethtrow =3D optionOverride =3D=3D null || !optionOver= ride.isFailSilently(); - if (!shouldRethtrow) - { - if (trace) - log.trace("There was a problem handling this request, but fail= Silently was set, so suppressing exception", e); - return; - } - throw e; - } -} --===============7067986116345013670==--