[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at jboss.com
Mon Aug 14 13:20:34 EDT 2006
User: msurtani
Date: 06/08/14 13:20:34
Modified: src/org/jboss/cache/interceptors CallInterceptor.java
Interceptor.java PessimisticLockInterceptor.java
Log:
Restored some basic cache functionality (at last!)
Revision Changes Path
1.11 +3 -3 JBossCache/src/org/jboss/cache/interceptors/CallInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CallInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/CallInterceptor.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- CallInterceptor.java 19 Jul 2006 21:34:43 -0000 1.10
+++ CallInterceptor.java 14 Aug 2006 17:20:34 -0000 1.11
@@ -21,7 +21,7 @@
* this interceptor unless it is a call the OptimisticNodeInterceptor knows nothing about.
*
* @author Bela Ban
- * @version $Id: CallInterceptor.java,v 1.10 2006/07/19 21:34:43 msurtani Exp $
+ * @version $Id: CallInterceptor.java,v 1.11 2006/08/14 17:20:34 msurtani Exp $
*/
public class CallInterceptor extends Interceptor
{
@@ -47,10 +47,10 @@
if (!transactionLifecycleMethods.contains(m.getMethod()))
{
- if (log.isTraceEnabled()) log.trace("Invoking method " + m + " on cache.");
+ if (log.isTraceEnabled()) log.trace("Passing up method " + m + " so it gets invoked on cache.");
try
{
- retval = m.invoke(cache);
+ retval = super.invoke(m);
}
catch (Throwable t)
{
1.17 +22 -5 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.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- Interceptor.java 19 Jul 2006 21:34:43 -0000 1.16
+++ Interceptor.java 14 Aug 2006 17:20:34 -0000 1.17
@@ -24,6 +24,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
+import org.jboss.cache.TreeCache;
+import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.marshall.JBCMethodCall;
import org.jboss.cache.marshall.MethodDeclarations;
@@ -39,11 +41,13 @@
* 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.16 2006/07/19 21:34:43 msurtani Exp $
+ * @version $Id: Interceptor.java,v 1.17 2006/08/14 17:20:34 msurtani Exp $
*/
public abstract class Interceptor implements InterceptorMBean {
protected Interceptor next=null;
protected CacheSPI cache;
+ // TODO: MANIK: internalise/hide this reference from other interceptors!!
+ private static TreeCache treecache;
protected Log log=null;
protected Configuration configuration;
private boolean statsEnabled = false;
@@ -52,7 +56,6 @@
log=LogFactory.getLog(getClass());
}
-
public void setNext(Interceptor i) {
next=i;
}
@@ -67,8 +70,22 @@
this.configuration = cache.getConfiguration();
}
- public Object invoke(MethodCall m) throws Throwable {
+ public static void setTreeCacheInstance(TreeCache cache)
+ {
+ treecache = cache;
+ }
+
+ public Object invoke(MethodCall m) throws Throwable
+ {
+ if (next != null && !InvocationContext.getOptionOverrides().isBypassInterceptorChain())
return next.invoke(m);
+ else
+ return invokeOnTreeCache(m);
+ }
+
+ private Object invokeOnTreeCache(MethodCall m) throws Throwable
+ {
+ return m.invoke(treecache);
}
public boolean getStatisticsEnabled()
1.23 +53 -17 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.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- PessimisticLockInterceptor.java 20 Jul 2006 21:43:36 -0000 1.22
+++ PessimisticLockInterceptor.java 14 Aug 2006 17:20:34 -0000 1.23
@@ -6,15 +6,16 @@
*/
package org.jboss.cache.interceptors;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DataNode;
import org.jboss.cache.Fqn;
import org.jboss.cache.GlobalTransaction;
import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
import org.jboss.cache.TransactionEntry;
import org.jboss.cache.TransactionTable;
-import org.jboss.cache.TreeCache;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Node;
+import org.jboss.cache.TreeCacheProxyImpl;
+import org.jboss.cache.config.Option;
import org.jboss.cache.lock.IdentityLock;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockingException;
@@ -37,7 +38,7 @@
* current method and unlock when the method returns.
*
* @author Bela Ban
- * @version $Id: PessimisticLockInterceptor.java,v 1.22 2006/07/20 21:43:36 bstansberry Exp $
+ * @version $Id: PessimisticLockInterceptor.java,v 1.23 2006/08/14 17:20:34 msurtani Exp $
*/
public class PessimisticLockInterceptor extends Interceptor {
TransactionTable tx_table=null;
@@ -45,6 +46,7 @@
/** Map<Object, java.util.List>. Keys = threads, values = lists of locks held by that thread */
Map lock_table;
private long lock_acquisition_timeout;
+ LockManager lockManager = new LockManager();
public void setCache(CacheSPI cache) {
@@ -160,14 +162,14 @@
if(createIfNotExists) {
do {
// TODO: WHat do we do about createIfNotExists flag?
- lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, lock_timeout);//, createIfNotExists);
+ lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, createIfNotExists);
}
while(!cache.hasChild(fqn)); // keep trying until we have the lock (fixes concurrent remove())
// terminates successfully, or with (Timeout)Exception
}
else
// TODO: WHat do we do about createIfNotExists flag?
- lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, lock_timeout);//, createIfNotExists);
+ lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, createIfNotExists);
}
else {
if(log.isTraceEnabled())
@@ -187,8 +189,7 @@
* @param lock_type DataNode.LOCK_TYPE_READ, DataNode.LOCK_TYPE_WRITE or DataNode.LOCK_TYPE_NONE
* @param recursive Lock children recursively
*/
- private void lock(Fqn fqn, GlobalTransaction gtx, int lock_type, boolean recursive,
- long lock_timeout)
+ private void lock(Fqn fqn, GlobalTransaction gtx, int lock_type, boolean recursive, boolean createIfNotExists)
throws TimeoutException, LockingException, InterruptedException {
Node n;
Node child_node;
@@ -215,7 +216,20 @@
n=cache;
for(int i=0; i < treeNodeSize; i++) {
child_name=fqn.get(i);
+
+ Option o = InvocationContext.getOptionOverrides();
+ o.setBypassInterceptorChain(true);
+ InvocationContext.setOptionOverrides(o);
+
+ child_node = n.getChild(new Fqn(child_name));
+ if (child_node == null && createIfNotExists)
+ {
+ o = InvocationContext.getOptionOverrides();
+ o.setBypassInterceptorChain(true);
+ InvocationContext.setOptionOverrides(o);
child_node= n.addChild(new Fqn(child_name));
+ }
+
if(child_node == null) {
if(log.isTraceEnabled())
log.trace("failed to find or create child " + child_name + " of node " + n.getFqn());
@@ -229,10 +243,12 @@
}
else {
if(lock_type == DataNode.LOCK_TYPE_WRITE && i == (treeNodeSize - 1)) {
- acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_WRITE);
+ //acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_WRITE);
+ acquired = lockManager.acquire(child_node, owner, DataNode.LOCK_TYPE_WRITE);
}
else {
- acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_READ);
+ //acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_READ);
+ acquired = lockManager.acquire(child_node, owner, DataNode.LOCK_TYPE_READ);
}
}
@@ -241,10 +257,10 @@
if(gtx != null) {
// add the lock to the list of locks maintained for this transaction
// (needed for release of locks on commit or rollback)
- cache.getTransactionTable().addLock(gtx, child_node.getLock());
+ cache.getTransactionTable().addLock(gtx, lockManager.getLock(child_node));
}
else {
- IdentityLock l=child_node.getLock();
+ IdentityLock l=lockManager.getLock(child_node);
List locks = getLocks(currentThread);
if(!locks.contains(l))
locks.add(l);
@@ -252,7 +268,8 @@
}
if(recursive && i == (treeNodeSize - 1)) {
- Set acquired_locks=child_node.acquireAll(owner, lock_timeout, lock_type);
+ //Set acquired_locks=child_node.acquireAll(owner, lock_timeout, lock_type);
+ Set acquired_locks = lockManager.acquireAll(child_node, owner, lock_type);
if(acquired_locks.size() > 0) {
if(gtx != null) {
cache.getTransactionTable().addLocks(gtx, acquired_locks);
@@ -378,4 +395,23 @@
tx_table.remove(tx);
}
+ private class LockManager
+ {
+ boolean acquire(Node node, Object owner, int lockType) throws InterruptedException
+ {
+ // TODO: MANIK: The lock map should not be accessed by methods on the Node. This is temporary until it can properly be refactored out.
+ return ((TreeCacheProxyImpl) node).acquire(owner, lock_acquisition_timeout, lockType);
+ }
+
+ IdentityLock getLock(Node node)
+ {
+ return ((TreeCacheProxyImpl) node).getLock();
+ }
+
+ public Set acquireAll(Node node, Object owner, int lockType) throws InterruptedException
+ {
+ return ((TreeCacheProxyImpl) node).acquireAll(owner, lock_acquisition_timeout, lockType);
+ }
+ }
+
}
More information about the jboss-cvs-commits
mailing list