Author: manik.surtani(a)jboss.com
Date: 2008-06-25 09:17:18 -0400 (Wed, 25 Jun 2008)
New Revision: 6021
Modified:
core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java
Log:
UPdated to use new methods on InvocationContext
Modified: core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java 2008-06-25
13:16:45 UTC (rev 6020)
+++ core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java 2008-06-25
13:17:18 UTC (rev 6021)
@@ -6,7 +6,6 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
@@ -19,27 +18,23 @@
* @since 2.2
*/
@SuppressWarnings("deprecation")
-public class NodeBasedLockManager implements LockManager
+public class NodeBasedLockManager extends AbstractLockManager
{
private static final Log log = LogFactory.getLog(NodeBasedLockManager.class);
private static final boolean trace = log.isTraceEnabled();
- protected Configuration configuration;
- protected long lockAcquisitionTimeout;
protected DataContainer dataContainer;
protected NodeSPI rootNode;
@Inject
- public void inject(Configuration configuration, DataContainer dataContainer)
+ public void inject(DataContainer dataContainer)
{
- this.configuration = configuration;
this.dataContainer = dataContainer;
}
@Start
public void setRootNode()
{
- this.lockAcquisitionTimeout = configuration.getLockAcquisitionTimeout();
rootNode = dataContainer.getRoot();
}
@@ -78,11 +73,6 @@
return null;
}
- public Object getLockOwner(InvocationContext ctx)
- {
- return ctx.getGlobalTransaction() != null ? ctx.getGlobalTransaction() :
Thread.currentThread();
- }
-
public boolean lock(Fqn fqn, LockType lockType, Object owner)
{
return acquireLock(fqn, lockType, owner, lockAcquisitionTimeout) != null;
@@ -120,7 +110,7 @@
}
else
{
- ctx.addInvocationLockAcquired(lock);
+ ctx.addLock(lock);
}
return true;
}
@@ -132,8 +122,8 @@
public void unlock(InvocationContext ctx)
{
- List<NodeLock> locks = ctx.getTransactionEntry() != null ?
ctx.getTransactionEntry().getLocks() : ctx.getInvocationLocksAcquired();
- if (locks == null || locks.isEmpty()) return;
+ List<NodeLock> locks = ctx.getLocks();
+ if (locks.isEmpty()) return;
Object owner = getLockOwner(ctx);
// Copying out to an array is faster than creating an ArrayList and iterating,
@@ -145,7 +135,8 @@
log.trace("releasing lock for " + lockArray[i].getFqn() + "
(" + lockArray[i] + "), owner " + owner);
lockArray[i].release(owner);
}
- locks.clear();
+
+ ctx.clearLocks();
}
private void unlock(NodeLock lock, Object owner)
@@ -219,11 +210,11 @@
{
if (ctx.getGlobalTransaction() != null)
{
- ctx.getTransactionEntry().addLocks(locks);
+ ctx.getTransactionEntry().addAllLocks(locks);
}
else
{
- ctx.addInvocationLocksAcquired(locks);
+ ctx.addAllLocks(locks);
}
}
Show replies by date