[jbosscache-commits] JBoss Cache SVN: r6098 - core/trunk/src/main/java/org/jboss/cache/lock.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Fri Jun 27 11:16:41 EDT 2008
Author: manik.surtani at jboss.com
Date: 2008-06-27 11:16:41 -0400 (Fri, 27 Jun 2008)
New Revision: 6098
Modified:
core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java
Log:
Vague support for some APIs.
Modified: core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java 2008-06-27 14:23:54 UTC (rev 6097)
+++ core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java 2008-06-27 15:16:41 UTC (rev 6098)
@@ -12,11 +12,13 @@
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.invocation.InvocationContextContainer;
+import static org.jboss.cache.lock.LockType.READ;
import org.jboss.cache.util.concurrent.locks.OwnableReentrantLock;
import javax.transaction.TransactionManager;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -75,16 +77,10 @@
internalFqns = cache.getInternalFqns();
}
-
- protected void assertIsWriteLock(LockType lockType)
+ public boolean lock(Fqn fqn, LockType lockType, Object owner) throws InterruptedException
{
- if (lockType != LockType.WRITE)
- throw new UnsupportedOperationException(getClass().getName() + " only supports write locks.");
- }
+ if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion
- public boolean lock(Fqn fqn, LockType lockType, Object owner) throws InterruptedException
- {
- assertIsWriteLock(lockType);
if (trace) log.trace("Attempting to lock " + fqn);
Lock lock = lockContainer.getLock(fqn);
return lock.tryLock(lockAcquisitionTimeout, MILLISECONDS);
@@ -92,7 +88,8 @@
public boolean lock(Fqn fqn, LockType lockType, Object owner, long timeoutMillis) throws InterruptedException
{
- assertIsWriteLock(lockType);
+ if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion
+
if (trace) log.trace("Attempting to lock " + fqn);
Lock lock = lockContainer.getLock(fqn);
return lock.tryLock(timeoutMillis, MILLISECONDS);
@@ -100,7 +97,8 @@
public boolean lockAndRecord(Fqn fqn, LockType lockType, InvocationContext ctx) throws InterruptedException
{
- assertIsWriteLock(lockType);
+ if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion
+
if (trace) log.trace("Attempting to lock " + fqn);
Lock lock = lockContainer.getLock(fqn);
if (lock.tryLock(ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), MILLISECONDS))
@@ -186,25 +184,25 @@
public boolean lockAll(NodeSPI node, LockType lockType, Object owner) throws InterruptedException
{
- assertIsWriteLock(lockType);
+ if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion
return lockRecursively(node, lockAcquisitionTimeout, false, null);
}
public boolean lockAll(NodeSPI node, LockType lockType, Object owner, long timeout) throws InterruptedException
{
- assertIsWriteLock(lockType);
+ if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion
return lockRecursively(node, timeout, false, null);
}
public boolean lockAll(NodeSPI node, LockType lockType, Object owner, long timeout, boolean excludeInternalFqns) throws InterruptedException
{
- assertIsWriteLock(lockType);
+ if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion
return lockRecursively(node, timeout, excludeInternalFqns, null);
}
public boolean lockAllAndRecord(NodeSPI node, LockType lockType, InvocationContext ctx) throws InterruptedException
{
- assertIsWriteLock(lockType);
+ if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion
return lockRecursively(node, ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), false, ctx);
}
@@ -232,7 +230,7 @@
public boolean ownsLock(Fqn fqn, LockType lockType, Object owner)
{
- assertIsWriteLock(lockType);
+ if (lockType == READ) return false; // we don't support read locks. TODO: enforce this with an assertion
return lockContainer.ownsLock(fqn, owner);
}
@@ -248,18 +246,32 @@
public boolean isLocked(NodeSPI n, LockType lockType)
{
- assertIsWriteLock(lockType);
+ if (lockType == READ) return false; // we don't support read locks. TODO: enforce this with an assertion
return lockContainer.isLocked(n.getFqn());
}
public Object getWriteOwner(Fqn f)
{
- throw new UnsupportedOperationException("Not supported in this impl.");
+ if (lockContainer.isLocked(f))
+ {
+ Lock l = lockContainer.getLock(f);
+
+ if (l instanceof OwnableReentrantLock)
+ {
+ return ((OwnableReentrantLock) l).getOwner();
+ }
+ else
+ {
+ // cannot determine owner.
+ return null;
+ }
+ }
+ else return null;
}
public Collection<Object> getReadOwners(Fqn f)
{
- throw new UnsupportedOperationException("Not supported in this impl.");
+ return Collections.emptySet();
}
public String printLockInfo(NodeSPI node)
More information about the jbosscache-commits
mailing list