Author: bstansberry(a)jboss.com
Date: 2007-09-17 23:26:11 -0400 (Mon, 17 Sep 2007)
New Revision: 4481
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
Log:
[JBCACHE-1178] Option to set lock timeout
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java 2007-09-18
03:25:32 UTC (rev 4480)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java 2007-09-18
03:26:11 UTC (rev 4481)
@@ -47,9 +47,15 @@
case MethodDeclarations.optimisticPrepareMethod_id:
//try and acquire the locks - before passing on
GlobalTransaction gtx = getGlobalTransaction(ctx);
+ long timeout = lockAcquisitionTimeout;
+ if (ctx.getOptionOverrides() != null
+ && ctx.getOptionOverrides().getLockAcquisitionTimeout() >=
0)
+ {
+ timeout = ctx.getOptionOverrides().getLockAcquisitionTimeout();
+ }
try
{
- lockNodes(gtx);
+ lockNodes(gtx, timeout);
}
catch (Throwable e)
{
@@ -108,7 +114,7 @@
*
* @param gtx global transaction which contains a workspace
*/
- private void lockNodes(GlobalTransaction gtx) throws InterruptedException
+ private void lockNodes(GlobalTransaction gtx, long timeout) throws
InterruptedException
{
TransactionWorkspace<?, ?> workspace = getTransactionWorkspace(gtx);
if (log.isDebugEnabled()) log.debug("Locking nodes in transaction workspace
for GlobalTransaction " + gtx);
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-09-18
03:25:32 UTC (rev 4480)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-09-18
03:26:11 UTC (rev 4481)
@@ -179,9 +179,10 @@
{
if (!locksAlreadyObtained)
{
+ long timeout = zeroLockTimeout ? 0 : getLockAcquisitionTimeout(ctx);
do
{
- lock(ctx, fqn, lock_type, recursive, createIfNotExists, zeroLockTimeout ?
0 : lock_acquisition_timeout, isDeleteOperation, isEvictOperation,
isRemoveDataOperation);
+ lock(ctx, fqn, lock_type, recursive, createIfNotExists, timeout,
isDeleteOperation, isEvictOperation, isRemoveDataOperation);
}
while (createIfNotExists && cache.peek(fqn, false) == null);// keep
trying until we have the lock (fixes concurrent remove())
}
@@ -221,18 +222,32 @@
return o;
}
+ private long getLockAcquisitionTimeout(InvocationContext ctx)
+ {
+ long timeout = lock_acquisition_timeout;
+ if (ctx.getOptionOverrides() != null
+ && ctx.getOptionOverrides().getLockAcquisitionTimeout() >= 0)
+ {
+ timeout = ctx.getOptionOverrides().getLockAcquisitionTimeout();
+ }
+ return timeout;
+ }
+
+
private void obtainLocksForMove(InvocationContext ctx, Fqn node, Fqn parent) throws
InterruptedException
{
// parent node (new parent) and current node's existing parent should both get
RLs.
// node should have a WL.
+ long timeout = getLockAcquisitionTimeout(ctx);
+
// 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(ctx, node, NodeLock.LockType.WRITE, true, false, lock_acquisition_timeout,
true, false, false);
+ lock(ctx, node, NodeLock.LockType.WRITE, true, false, timeout, true, false,
false);
//now for an RL for the new parent.
if (log.isTraceEnabled()) log.trace("Attempting to get RL on new parent
[" + parent + "]");
- lock(ctx, parent, NodeLock.LockType.READ, true, false, lock_acquisition_timeout,
false, false, false);
+ lock(ctx, parent, NodeLock.LockType.READ, true, false, timeout, false, false,
false);
}