[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at jboss.com
Tue Sep 5 07:03:26 EDT 2006
User: msurtani
Date: 06/09/05 07:03:26
Modified: src/org/jboss/cache/interceptors Interceptor.java
PessimisticLockInterceptor.java
Added: src/org/jboss/cache/interceptors
InvocationContextInterceptor.java
Log:
Fixed suppress locking bugs, improved interceptor chain construction, added new interceptor to construct invocation ctx
Revision Changes Path
1.23 +76 -61 JBossCache/src/org/jboss/cache/interceptors/Interceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Interceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/Interceptor.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- Interceptor.java 25 Aug 2006 14:10:07 -0000 1.22
+++ Interceptor.java 5 Sep 2006 11:03:26 -0000 1.23
@@ -25,8 +25,8 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.marshall.MethodCall;
+import org.jboss.cache.marshall.MethodDeclarations;
import javax.transaction.Status;
import javax.transaction.SystemException;
@@ -37,40 +37,42 @@
/**
* Class representing an interceptor.
* <em>Note that this will be replaced by {@link org.jboss.aop.advice.Interceptor} in one of the next releases</em>
+ *
* @author Bela Ban
- * @version $Id: Interceptor.java,v 1.22 2006/08/25 14:10:07 msurtani Exp $
+ * @version $Id: Interceptor.java,v 1.23 2006/09/05 11:03:26 msurtani Exp $
*/
-public abstract class Interceptor implements InterceptorMBean {
- protected Interceptor next=null, last = null;
+public abstract class Interceptor implements InterceptorMBean
+{
+ protected Interceptor next = null, last = null;
protected CacheSPI cache;
- protected Log log=null;
+ protected Log log = null;
protected Configuration configuration;
private boolean statsEnabled = false;
- public Interceptor() {
- log=LogFactory.getLog(getClass());
+ public Interceptor()
+ {
+ log = LogFactory.getLog(getClass());
}
- public void setNext(Interceptor i) {
- next=i;
+ public void setNext(Interceptor i)
+ {
+ next = i;
}
- public Interceptor getNext() {
+ public Interceptor getNext()
+ {
return next;
}
public void setCache(CacheSPI cache)
{
- this.cache=cache;
+ this.cache = cache;
this.configuration = cache.getConfiguration();
}
public Object invoke(MethodCall m) throws Throwable
{
- if (next != null && !cache.getInvocationContext().getOptionOverrides().isBypassInterceptorChain())
return next.invoke(m);
- else
- return last.invoke(m);
}
public boolean getStatisticsEnabled()
@@ -104,29 +106,39 @@
// should be implemented by individual interceptors
}
- /** Returns true if transaction is ACTIVE, false otherwise */
- protected boolean isActive(Transaction tx) {
- if(tx == null) return false;
- int status=-1;
- try {
- status=tx.getStatus();
+ /**
+ * Returns true if transaction is ACTIVE, false otherwise
+ */
+ protected boolean isActive(Transaction tx)
+ {
+ if (tx == null) return false;
+ int status = -1;
+ try
+ {
+ status = tx.getStatus();
return status == Status.STATUS_ACTIVE;
}
- catch(SystemException e) {
+ catch (SystemException e)
+ {
log.error("failed getting transaction status", e);
return false;
}
}
- /** Returns true if transaction is PREPARING, false otherwise */
- protected boolean isPreparing(Transaction tx) {
- if(tx == null) return false;
- int status=-1;
- try {
- status=tx.getStatus();
+ /**
+ * Returns true if transaction is PREPARING, false otherwise
+ */
+ protected boolean isPreparing(Transaction tx)
+ {
+ if (tx == null) return false;
+ int status = -1;
+ try
+ {
+ status = tx.getStatus();
return status == Status.STATUS_PREPARING;
}
- catch(SystemException e) {
+ catch (SystemException e)
+ {
log.error("failed getting transaction status", e);
return false;
}
@@ -134,15 +146,18 @@
/**
* Return s true of tx's status is ACTIVE or PREPARING
+ *
* @param tx
* @return true if the tx is active or preparing
*/
- protected boolean isValid(Transaction tx) {
+ protected boolean isValid(Transaction tx)
+ {
return isActive(tx) || isPreparing(tx);
}
/**
* This only works for prepare() and optimisticPrepare() method calls.
+ *
* @param m
*/
protected boolean isOnePhaseCommitPrepareMehod(MethodCall m)
1.31 +8 -2 JBossCache/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PessimisticLockInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- PessimisticLockInterceptor.java 30 Aug 2006 17:08:18 -0000 1.30
+++ PessimisticLockInterceptor.java 5 Sep 2006 11:03:26 -0000 1.31
@@ -36,7 +36,7 @@
* current method and unlock when the method returns.
*
* @author Bela Ban
- * @version $Id: PessimisticLockInterceptor.java,v 1.30 2006/08/30 17:08:18 msurtani Exp $
+ * @version $Id: PessimisticLockInterceptor.java,v 1.31 2006/09/05 11:03:26 msurtani Exp $
*/
public class PessimisticLockInterceptor extends Interceptor
{
@@ -329,8 +329,14 @@
for (int i = 0; i < treeNodeSize; i++)
{
Object child_name = fqn.get(i);
+ Fqn childFqn = new Fqn(child_name);
cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
- Node child_node = n.addChild(new Fqn(child_name)); //, gtx, true);
+ Node child_node = n.getChild(childFqn);
+ if (child_node == null)
+ {
+ cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
+ child_node = n.addChild(childFqn); //, gtx, true);
+ }
if (child_node == null)
{
if (log.isTraceEnabled())
1.1 date: 2006/09/05 11:03:26; author: msurtani; state: Exp;JBossCache/src/org/jboss/cache/interceptors/InvocationContextInterceptor.java
Index: InvocationContextInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.interceptors;
import org.jboss.cache.marshall.MethodCall;
/**
* Always place this interceptor at the start of the interceptor chain to ensure invocation contexts and set up and cleaned up correctly.
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
*/
public class InvocationContextInterceptor extends Interceptor
{
public Object invoke(MethodCall call) throws Throwable
{
try
{
if (cache.getInvocationContext().getOptionOverrides().isBypassInterceptorChain())
{
return getLast().invoke(call);
}
else
{
return super.invoke(call);
}
}
finally
{
// clean up any invocation-scope options set up
cache.getInvocationContext().getOptionOverrides().reset();
}
}
}
More information about the jboss-cvs-commits
mailing list