[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at jboss.com
Tue Oct 31 12:11:42 EST 2006
User: msurtani
Date: 06/10/31 12:11:42
Modified: src/org/jboss/cache/interceptors
PessimisticLockInterceptor.java
Log:
JBCACHE-794
Revision Changes Path
1.33 +16 -14 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.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- PessimisticLockInterceptor.java 16 Sep 2006 00:23:34 -0000 1.32
+++ PessimisticLockInterceptor.java 31 Oct 2006 17:11:42 -0000 1.33
@@ -36,7 +36,7 @@
* current method and unlock when the method returns.
*
* @author Bela Ban
- * @version $Id: PessimisticLockInterceptor.java,v 1.32 2006/09/16 00:23:34 msurtani Exp $
+ * @version $Id: PessimisticLockInterceptor.java,v 1.33 2006/10/31 17:11:42 msurtani Exp $
*/
public class PessimisticLockInterceptor extends Interceptor
{
@@ -91,6 +91,7 @@
boolean recursive = false;
boolean createIfNotExists = false;
+ boolean zeroLockTimeout = false; // only used if the call is an evict() call. See JBCACHE-794
// 1. Determine the type of lock (read, write, or none) depending on the method. If no lock is required, invoke
// the method, then return immediately
@@ -120,6 +121,7 @@
lock_type = DataNode.LockType.WRITE;
break;
case MethodDeclarations.evictNodeMethodLocal_id:
+ zeroLockTimeout = true;
fqn = (Fqn) args[0];
lock_type = DataNode.LockType.WRITE;
break;
@@ -145,7 +147,7 @@
// rollback propagated up from the tx interceptor
rollback(ctx.getGlobalTransaction());
break;
- default :
+ default:
if (isOnePhaseCommitPrepareMehod(m))
{
// commit propagated up from the tx interceptor
@@ -162,7 +164,7 @@
{
do
{
- lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, createIfNotExists);
+ lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, createIfNotExists, zeroLockTimeout ? 0 : lock_acquisition_timeout);
}
while (createIfNotExists && !cache.hasChild(fqn)); // keep trying until we have the lock (fixes concurrent remove())
}
@@ -187,11 +189,11 @@
// this call will ensure the node gets a WL and it's current parent gets RL.
if (log.isTraceEnabled()) log.trace("Attempting to get WL on node to be moved [" + node + "]");
- lock(node, cache.getInvocationContext().getGlobalTransaction(), DataNode.LockType.WRITE, true, false);
+ lock(node, cache.getInvocationContext().getGlobalTransaction(), DataNode.LockType.WRITE, true, false, lock_acquisition_timeout);
//now for an RL for the new parent.
if (log.isTraceEnabled()) log.trace("Attempting to get RL on new parent [" + parent + "]");
- lock(parent, cache.getInvocationContext().getGlobalTransaction(), DataNode.LockType.READ, true, false);
+ lock(parent, cache.getInvocationContext().getGlobalTransaction(), DataNode.LockType.READ, true, false, lock_acquisition_timeout);
}
@@ -203,14 +205,14 @@
* @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, DataNode.LockType lock_type, boolean recursive, boolean createIfNotExists)
+ private void lock(Fqn fqn, GlobalTransaction gtx, DataNode.LockType lock_type, boolean recursive, boolean createIfNotExists, long timeout)
throws TimeoutException, LockingException, InterruptedException
{
Node n;
Node child_node;
Object child_name;
Thread currentThread = Thread.currentThread();
- Object owner = (gtx != null) ? (Object) gtx : currentThread;
+ Object owner = (gtx != null) ? gtx : currentThread;
int treeNodeSize;
boolean acquired;
@@ -266,12 +268,12 @@
if (lock_type == DataNode.LockType.WRITE && i == (treeNodeSize - 1))
{
//acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_WRITE);
- acquired = lockManager.acquire(child_node, owner, DataNode.LockType.WRITE);
+ acquired = lockManager.acquire(child_node, owner, DataNode.LockType.WRITE, timeout);
}
else
{
//acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_READ);
- acquired = lockManager.acquire(child_node, owner, DataNode.LockType.READ);
+ acquired = lockManager.acquire(child_node, owner, DataNode.LockType.READ, timeout);
}
}
@@ -298,7 +300,7 @@
if (recursive && i == (treeNodeSize - 1))
{
//Set acquired_locks=child_node.acquireAll(owner, lock_timeout, lock_type);
- Set acquired_locks = lockManager.acquireAll(child_node, owner, lock_type);
+ Set acquired_locks = lockManager.acquireAll(child_node, owner, lock_type, timeout);
if (acquired_locks.size() > 0)
{
if (gtx != null)
@@ -453,10 +455,10 @@
private class LockManager
{
- boolean acquire(Node node, Object owner, DataNode.LockType lockType) throws InterruptedException
+ boolean acquire(Node node, Object owner, DataNode.LockType lockType, long timeout) 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);
+ return ((TreeCacheProxyImpl) node).acquire(owner, timeout, lockType);
}
IdentityLock getLock(Node node)
@@ -464,9 +466,9 @@
return ((TreeCacheProxyImpl) node).getLock();
}
- public Set acquireAll(Node node, Object owner, DataNode.LockType lockType) throws InterruptedException
+ public Set acquireAll(Node node, Object owner, DataNode.LockType lockType, long timeout) throws InterruptedException
{
- return ((TreeCacheProxyImpl) node).acquireAll(owner, lock_acquisition_timeout, lockType);
+ return ((TreeCacheProxyImpl) node).acquireAll(owner, timeout, lockType);
}
}
More information about the jboss-cvs-commits
mailing list