[jboss-cvs] JBossCache/src/org/jboss/cache/lock ...
Elias Ross
genman at noderunner.net
Fri Dec 8 13:50:49 EST 2006
User: genman
Date: 06/12/08 13:50:49
Modified: src/org/jboss/cache/lock
LockStrategyReadUncommitted.java
ReadWriteLockWithUpgrade.java
LockStrategyRepeatableRead.java
SimpleReadWriteLock.java IsolationLevel.java
LockStrategyReadCommitted.java LockMap.java
LockStrategyNone.java SimpleLock.java LockUtil.java
IdentityLock.java LockStrategy.java
LockStrategyFactory.java
LockStrategySerializable.java
Added: src/org/jboss/cache/lock NullLock.java
SemaphoreLock.java
Log:
JBCACHE-891 Use JDK 1.5 lock classes
Revision Changes Path
1.2 +12 -13 JBossCache/src/org/jboss/cache/lock/LockStrategyReadUncommitted.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LockStrategyReadUncommitted.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockStrategyReadUncommitted.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- LockStrategyReadUncommitted.java 31 Mar 2005 10:15:06 -0000 1.1
+++ LockStrategyReadUncommitted.java 8 Dec 2006 18:50:49 -0000 1.2
@@ -6,32 +6,31 @@
*/
package org.jboss.cache.lock;
-import EDU.oswego.cs.dl.util.concurrent.FIFOSemaphore;
-import EDU.oswego.cs.dl.util.concurrent.NullSync;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
/**
* Transaction isolation level of READ-UNCOMMITTED. Reads always succeed (NullLock), whereas writes are exclusive.
* It prevents none of the dirty read, non-repeatable read, or phantom read.
*
* @author Ben Wang
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class LockStrategyReadUncommitted implements LockStrategy
{
- private FIFOSemaphore wLock_;
- private NullSync rLock_; // Null lock will always return true
+ private SemaphoreLock wLock_;
+ private Lock rLock_; // Null lock will always return true
public LockStrategyReadUncommitted()
{
- wLock_ = new FIFOSemaphore(1);
- rLock_ = new NullSync();
+ wLock_ = new SemaphoreLock(1);
+ rLock_ = new NullLock();
}
/**
* @see org.jboss.cache.lock.LockStrategy#readLock()
*/
- public Sync readLock()
+ public Lock readLock()
{
return rLock_;
}
@@ -39,12 +38,12 @@
/**
* @see org.jboss.cache.lock.LockStrategy#upgradeLockAttempt(long)
*/
- public Sync upgradeLockAttempt(long msecs) throws UpgradeException
+ public Lock upgradeLockAttempt(long msecs) throws UpgradeException
{
// Since write is exclusive, we need to obtain the write lock first
// before we can return the upgrade
try {
- wLock_.attempt(msecs);
+ wLock_.tryLock(msecs, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new UpgradeException("Upgrade failed in " + msecs + " msecs", e);
}
@@ -54,7 +53,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#writeLock()
*/
- public Sync writeLock()
+ public Lock writeLock()
{
return wLock_;
}
1.4 +54 -23 JBossCache/src/org/jboss/cache/lock/ReadWriteLockWithUpgrade.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ReadWriteLockWithUpgrade.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/ReadWriteLockWithUpgrade.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ReadWriteLockWithUpgrade.java 22 Jun 2005 14:33:06 -0000 1.3
+++ ReadWriteLockWithUpgrade.java 8 Dec 2006 18:50:49 -0000 1.4
@@ -12,8 +12,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.Lock;
/*
* <p> This class is similar to PreferredWriterReadWriteLock except that
@@ -77,12 +79,12 @@
}
- public Sync writeLock()
+ public Lock writeLock()
{
return writerLock_;
}
- public Sync readLock()
+ public Lock readLock()
{
return readerLock_;
}
@@ -94,7 +96,7 @@
* @param msecs Time to wait in millisecons.
* @return Sync object. Null if not successful or timeout.
*/
- public Sync upgradeLockAttempt(long msecs) throws UpgradeException
+ public Lock upgradeLockAttempt(long msecs) throws UpgradeException
{
if (activeReaders_ == 0)
throw new RuntimeException("No reader lock available for upgrade");
@@ -118,13 +120,13 @@
resetWaitingUpgrader();
return changeLock();
} else {
- readerLock_.release();
+ readerLock_.unlock();
try {
- if (!writerLock_.attempt(msecs)) {
+ if (!writerLock_.tryLock(msecs, TimeUnit.MILLISECONDS)) {
log_.error("upgradeLock(): failed");
resetWaitingUpgrader();
- if(!readerLock_.attempt(msecs)) {
+ if(!readerLock_.tryLock(msecs, TimeUnit.MILLISECONDS)) {
String errStr="ReadWriteLockWithUpgrade.upgradeLockAttempt():" +
" failed to upgrade to write lock and also failed to re-obtain the read lock";
log_.error(errStr);
@@ -149,7 +151,7 @@
}
}
- protected synchronized Sync changeLock()
+ protected synchronized Lock changeLock()
{
--activeReaders_;
@@ -277,15 +279,47 @@
void signalWaiters();
}
- protected class ReaderLock implements Signaller, Sync
+ static abstract class LockBase implements Lock
{
- public void acquire() throws InterruptedException
+ public void lock()
{
- throw new RuntimeException("acquire(): Operation currently not supported.");
+ throw new UnsupportedOperationException();
}
- public void release()
+ public void lockInterruptibly() throws InterruptedException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Condition newCondition()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean tryLock()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void unlock()
+ {
+ throw new UnsupportedOperationException();
+ }
+ */
+
+ }
+
+ protected class ReaderLock extends LockBase implements Signaller, Lock
+ {
+
+ public void unlock()
{
Signaller s = endRead();
if (s != null) {
@@ -298,9 +332,10 @@
ReaderLock.this.notifyAll();
}
- public boolean attempt(long msecs) throws InterruptedException
+ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
{
if (Thread.interrupted()) throw new InterruptedException();
+ long msecs = unit.toMillis(time);
InterruptedException ie = null;
synchronized (this) {
if (msecs <= 0)
@@ -341,15 +376,10 @@
}
- protected class WriterLock implements Signaller, Sync
+ protected class WriterLock extends LockBase implements Signaller, Lock
{
- public void acquire() throws InterruptedException
- {
- throw new RuntimeException("acquire(): Operation currently not supported.");
- }
-
- public void release()
+ public void unlock()
{
Signaller s = endWrite();
if (s != null) s.signalWaiters();
@@ -362,10 +392,11 @@
WriterLock.this.notifyAll();
}
- public boolean attempt(long msecs) throws InterruptedException
+ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
{
if (Thread.interrupted()) throw new InterruptedException();
InterruptedException ie = null;
+ long msecs = unit.toMillis(time);
synchronized (WriterLock.this) {
if (msecs <= 0) {
1.2 +5 -5 JBossCache/src/org/jboss/cache/lock/LockStrategyRepeatableRead.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LockStrategyRepeatableRead.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockStrategyRepeatableRead.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- LockStrategyRepeatableRead.java 31 Mar 2005 10:15:06 -0000 1.1
+++ LockStrategyRepeatableRead.java 8 Dec 2006 18:50:49 -0000 1.2
@@ -6,7 +6,7 @@
*/
package org.jboss.cache.lock;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
+import java.util.concurrent.locks.Lock;
/**
* Transaction isolation level of Repeatable_Read. It prevents dirty read and non-repeatable read.
@@ -16,7 +16,7 @@
* transaction commit. </p>
*
* @author Ben Wang
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class LockStrategyRepeatableRead implements LockStrategy
{
@@ -30,7 +30,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#readLock()
*/
- public Sync readLock()
+ public Lock readLock()
{
return lock_.readLock();
}
@@ -38,7 +38,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#upgradeLockAttempt(long)
*/
- public Sync upgradeLockAttempt(long msecs) throws UpgradeException
+ public Lock upgradeLockAttempt(long msecs) throws UpgradeException
{
return lock_.upgradeLockAttempt(msecs);
}
@@ -46,7 +46,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#writeLock()
*/
- public Sync writeLock()
+ public Lock writeLock()
{
return lock_.writeLock();
}
1.2 +11 -30 JBossCache/src/org/jboss/cache/lock/SimpleReadWriteLock.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SimpleReadWriteLock.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/SimpleReadWriteLock.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- SimpleReadWriteLock.java 31 Mar 2005 10:15:06 -0000 1.1
+++ SimpleReadWriteLock.java 8 Dec 2006 18:50:49 -0000 1.2
@@ -1,30 +1,11 @@
package org.jboss.cache.lock;
-import EDU.oswego.cs.dl.util.concurrent.ReentrantWriterPreferenceReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* @author Bela Ban
- * @version $Id: SimpleReadWriteLock.java,v 1.1 2005/03/31 10:15:06 belaban Exp $
+ * @version $Id: SimpleReadWriteLock.java,v 1.2 2006/12/08 18:50:49 genman Exp $
*/
-public class SimpleReadWriteLock extends ReentrantWriterPreferenceReadWriteLock {
-
- protected synchronized Signaller endRead() {
- Signaller result=super.endRead();
-// if(result != null)
-// return result;
-//
-// if(activeReaders_ == 1 && waitingWriters_ > 0) {
-// if(readers_.size() == 1 && readers_.containsKey(Thread.currentThread())) {
-// --activeReaders_;
-// return writerLock_;
-// }
-// }
-// return null;
-
-
- return result;
- }
-
-
+public class SimpleReadWriteLock extends ReentrantReadWriteLock {
}
1.7 +35 -4 JBossCache/src/org/jboss/cache/lock/IsolationLevel.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IsolationLevel.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/IsolationLevel.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- IsolationLevel.java 14 Aug 2006 17:52:34 -0000 1.6
+++ IsolationLevel.java 8 Dec 2006 18:50:49 -0000 1.7
@@ -1,14 +1,45 @@
/**
*
* @author Bela Ban Nov 25, 2003
- * @version $Id: IsolationLevel.java,v 1.6 2006/08/14 17:52:34 msurtani Exp $
+ * @version $Id: IsolationLevel.java,v 1.7 2006/12/08 18:50:49 genman Exp $
*/
package org.jboss.cache.lock;
/**
* Various transaction isolation levels as an enumerated class.
*/
-public enum IsolationLevel
-{
- NONE, SERIALIZABLE, REPEATABLE_READ, READ_COMMITTED, READ_UNCOMMITTED
+public enum IsolationLevel {
+
+ NONE {
+ public LockStrategy getLockStrategy()
+ {
+ return new LockStrategyNone();
+ }
+ },
+ SERIALIZABLE {
+ public LockStrategy getLockStrategy()
+ {
+ return new LockStrategySerializable();
+ }
+ },
+ REPEATABLE_READ {
+ public LockStrategy getLockStrategy()
+ {
+ return new LockStrategyRepeatableRead();
+ }
+ },
+ READ_COMMITTED {
+ public LockStrategy getLockStrategy()
+ {
+ return new LockStrategyReadCommitted();
+ }
+ },
+ READ_UNCOMMITTED {
+ public LockStrategy getLockStrategy()
+ {
+ return new LockStrategyReadUncommitted();
+ }
+ };
+
+ public abstract LockStrategy getLockStrategy();
}
\ No newline at end of file
1.2 +5 -5 JBossCache/src/org/jboss/cache/lock/LockStrategyReadCommitted.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LockStrategyReadCommitted.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockStrategyReadCommitted.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- LockStrategyReadCommitted.java 31 Mar 2005 10:15:06 -0000 1.1
+++ LockStrategyReadCommitted.java 8 Dec 2006 18:50:49 -0000 1.2
@@ -6,7 +6,7 @@
*/
package org.jboss.cache.lock;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
+import java.util.concurrent.locks.Lock;
/**
* Transaction isolation level of READ_COMMITTED. Similar to read/write lock, but writers are not blocked on readers
@@ -15,7 +15,7 @@
* transaction commit. </p>
*
* @author Ben Wang
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class LockStrategyReadCommitted implements LockStrategy
{
@@ -29,7 +29,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#readLock()
*/
- public Sync readLock()
+ public Lock readLock()
{
return lock_.readLock();
}
@@ -37,7 +37,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#upgradeLockAttempt(long)
*/
- public Sync upgradeLockAttempt(long msecs) throws UpgradeException
+ public Lock upgradeLockAttempt(long msecs) throws UpgradeException
{
return lock_.upgradeLockAttempt(msecs);
}
@@ -45,7 +45,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#writeLock()
*/
- public Sync writeLock()
+ public Lock writeLock()
{
return lock_.writeLock();
}
1.11 +2 -2 JBossCache/src/org/jboss/cache/lock/LockMap.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LockMap.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockMap.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- LockMap.java 23 Nov 2006 19:43:05 -0000 1.10
+++ LockMap.java 8 Dec 2006 18:50:49 -0000 1.11
@@ -14,7 +14,7 @@
* Provide lock ownership mapping.
*
* @author Ben Wang
- * @version $Id: LockMap.java,v 1.10 2006/11/23 19:43:05 genman Exp $
+ * @version $Id: LockMap.java,v 1.11 2006/12/08 18:50:49 genman Exp $
*/
public class LockMap
{
@@ -126,7 +126,7 @@
{
int size = readOwnerList_.size();
for (int i = 0; i < size; i++)
- lock.readLock().release();
+ lock.readLock().unlock();
}
/**
1.2 +9 -9 JBossCache/src/org/jboss/cache/lock/LockStrategyNone.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LockStrategyNone.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockStrategyNone.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- LockStrategyNone.java 31 Mar 2005 10:15:06 -0000 1.1
+++ LockStrategyNone.java 8 Dec 2006 18:50:49 -0000 1.2
@@ -6,28 +6,27 @@
*/
package org.jboss.cache.lock;
-import EDU.oswego.cs.dl.util.concurrent.NullSync;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
+import java.util.concurrent.locks.Lock;
/**
* Transaction isolation level of None.
*
* @author Lari Hotari
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class LockStrategyNone implements LockStrategy
{
- private NullSync nullLock_;
+ private Lock nullLock_;
public LockStrategyNone()
{
- nullLock_ = new NullSync();
+ nullLock_ = new NullLock();
}
/**
* @see org.jboss.cache.lock.LockStrategy#readLock()
*/
- public Sync readLock()
+ public Lock readLock()
{
return nullLock_;
}
@@ -35,7 +34,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#upgradeLockAttempt(long)
*/
- public Sync upgradeLockAttempt(long msecs) throws UpgradeException
+ public Lock upgradeLockAttempt(long msecs) throws UpgradeException
{
return nullLock_;
}
@@ -43,9 +42,10 @@
/**
* @see org.jboss.cache.lock.LockStrategy#writeLock()
*/
- public Sync writeLock()
+ public Lock writeLock()
{
return nullLock_;
}
-}
+
+ }
1.4 +8 -11 JBossCache/src/org/jboss/cache/lock/SimpleLock.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SimpleLock.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/SimpleLock.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- SimpleLock.java 6 Nov 2006 23:34:09 -0000 1.3
+++ SimpleLock.java 8 Dec 2006 18:50:49 -0000 1.4
@@ -6,33 +6,30 @@
*/
package org.jboss.cache.lock;
-import EDU.oswego.cs.dl.util.concurrent.FIFOSemaphore;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
-
-//import org.jboss.logging.Logger;
+import java.util.concurrent.locks.Lock;
/**
* Simple lock that does not differentiate read and write lock. All locks are obtained FIFO.
- * Just implements from Doug Lea's concurrent package. This class is used as a delegate for LockStrategy
+ * This class is used as a delegate for LockStrategy
* is transaction isolation level.
*
* @author <a href="mailto:bwang00 at sourceforge.net">Ben Wang</a> July 15, 2003
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class SimpleLock
{
// Log log=LogFactory.getLog(getClass());
- private FIFOSemaphore sem_;
+ private SemaphoreLock sem_;
public SimpleLock()
{
- sem_ = new FIFOSemaphore(1);
+ sem_ = new SemaphoreLock(1);
}
/**
* @see org.jboss.cache.lock.LockStrategy#readLock()
*/
- public Sync readLock()
+ public Lock readLock()
{
return sem_;
}
@@ -40,7 +37,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#upgradeLockAttempt(long)
*/
- public Sync upgradeLockAttempt(long msecs)
+ public Lock upgradeLockAttempt(long msecs)
{
return sem_;
}
@@ -48,7 +45,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#writeLock()
*/
- public Sync writeLock()
+ public Lock writeLock()
{
return sem_;
}
1.5 +0 -1 JBossCache/src/org/jboss/cache/lock/LockUtil.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LockUtil.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockUtil.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- LockUtil.java 20 Nov 2006 03:53:55 -0000 1.4
+++ LockUtil.java 8 Dec 2006 18:50:49 -0000 1.5
@@ -11,7 +11,6 @@
import javax.transaction.Status;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import java.util.Collection;
import java.util.Iterator;
public abstract class LockUtil
1.17 +9 -12 JBossCache/src/org/jboss/cache/lock/IdentityLock.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IdentityLock.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/IdentityLock.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- IdentityLock.java 23 Nov 2006 19:43:05 -0000 1.16
+++ IdentityLock.java 8 Dec 2006 18:50:49 -0000 1.17
@@ -6,20 +6,17 @@
*/
package org.jboss.cache.lock;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.DataNode;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.cache.NodeImpl;
-import org.jboss.cache.NodeSPI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.Map;
import java.util.Set;
/**
@@ -61,7 +58,7 @@
*
* @author <a href="mailto:bela at jboss.org">Bela Ban</a> Apr 11, 2003
* @author Ben Wang July 2003
- * @version $Revision: 1.16 $
+ * @version $Revision: 1.17 $
*/
public class IdentityLock implements NodeLock
{
@@ -189,7 +186,7 @@
if (map_.isOwner(caller, LockMap.OWNER_READ))
{
// Currently is a reader owner. Obtain the writer ownership then.
- Sync wLock;
+ Lock wLock;
try
{
if (trace)
@@ -225,7 +222,7 @@
else
{
// Not a current reader owner. Obtain the writer ownership then.
- boolean rc = lock_.writeLock().attempt(timeout);
+ boolean rc = lock_.writeLock().tryLock(timeout, TimeUnit.MILLISECONDS);
// we don't need to synchronize from here on because we own the semaphore
if (!rc)
@@ -299,7 +296,7 @@
return false; // owner already has the lock
}
- rc = lock_.readLock().attempt(timeout);
+ rc = lock_.readLock().tryLock(timeout, TimeUnit.MILLISECONDS);
// we don't need to synchronize from here on because we own the semaphore
if (!rc)
@@ -334,12 +331,12 @@
if (map_.isOwner(caller, LockMap.OWNER_READ))
{
map_.removeReader(caller);
- lock_.readLock().release();
+ lock_.readLock().unlock();
}
else if (map_.isOwner(caller, LockMap.OWNER_WRITE))
{
map_.removeWriter();
- lock_.writeLock().release();
+ lock_.writeLock().unlock();
}
}
@@ -353,7 +350,7 @@
if ((map_.writerOwner()) != null)
{
// lock_.readLock().release();
- lock_.writeLock().release();
+ lock_.writeLock().unlock();
}
map_.releaseReaderOwners(lock_);
1.2 +37 -41 JBossCache/src/org/jboss/cache/lock/LockStrategy.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LockStrategy.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockStrategy.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- LockStrategy.java 31 Mar 2005 10:15:06 -0000 1.1
+++ LockStrategy.java 8 Dec 2006 18:50:49 -0000 1.2
@@ -6,7 +6,7 @@
*/
package org.jboss.cache.lock;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
+import java.util.concurrent.locks.Lock;
/**
* Interface to specify lock strategy, e.g., for different isolation levels.
@@ -17,25 +17,21 @@
{
/**
* Return a read lock object.
- *
- * @return Sync (@see EDU.oswego.cs.dl.util.concurrent.Sync)
*/
- Sync readLock();
+ Lock readLock();
/**
* Return a write lock object.
- *
- * @return Sync (@see EDU.oswego.cs.dl.util.concurrent.Sync)
*/
- Sync writeLock();
+ Lock writeLock();
/**
* Attempt to upgrade the current read lock to write lock with
* <code>msecs</code> timeout.
*
* @param msecs Timeout in milliseconds.
- * @return Sync object. Will return null if timeout or failed.
+ * @return Lock object. Will return null if timeout or failed.
*/
- Sync upgradeLockAttempt(long msecs) throws UpgradeException;
+ Lock upgradeLockAttempt(long msecs) throws UpgradeException;
}
1.5 +2 -11 JBossCache/src/org/jboss/cache/lock/LockStrategyFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LockStrategyFactory.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockStrategyFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- LockStrategyFactory.java 31 May 2006 14:20:42 -0000 1.4
+++ LockStrategyFactory.java 8 Dec 2006 18:50:49 -0000 1.5
@@ -36,18 +36,9 @@
//if(log_.isTraceEnabled()) {
// log_.trace("LockStrategy is: " + lockingLevel);
//}
- if (lockingLevel == null || lockingLevel == IsolationLevel.NONE)
+ if (lockingLevel == null)
return new LockStrategyNone();
- if (lockingLevel == IsolationLevel.REPEATABLE_READ)
- return new LockStrategyRepeatableRead();
- if (lockingLevel == IsolationLevel.SERIALIZABLE)
- return new LockStrategySerializable();
- if (lockingLevel == IsolationLevel.READ_COMMITTED)
- return new LockStrategyReadCommitted();
- if (lockingLevel == IsolationLevel.READ_UNCOMMITTED)
- return new LockStrategyReadUncommitted();
- throw new RuntimeException("getLockStrategy: LockStrategy selection not recognized." +
- " selection: " + lockingLevel);
+ return lockingLevel.getLockStrategy();
}
public static void setIsolationLevel(IsolationLevel level)
1.4 +7 -8 JBossCache/src/org/jboss/cache/lock/LockStrategySerializable.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LockStrategySerializable.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockStrategySerializable.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- LockStrategySerializable.java 6 Nov 2006 23:34:09 -0000 1.3
+++ LockStrategySerializable.java 8 Dec 2006 18:50:49 -0000 1.4
@@ -6,8 +6,7 @@
*/
package org.jboss.cache.lock;
-import EDU.oswego.cs.dl.util.concurrent.FIFOSemaphore;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
+import java.util.concurrent.locks.Lock;
//import org.jboss.logging.Logger;
@@ -21,23 +20,23 @@
* <p> Phantom read allows (t1) read n rows, (t2) insert k rows, and (t1) read n+k rows.</p>
*
* @author <a href="mailto:bwang00 at sourceforge.net">Ben Wang</a> July 15, 2003
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class LockStrategySerializable implements LockStrategy
{
// Log log=LogFactory.getLog(getClass());
- private FIFOSemaphore sem_;
+ private SemaphoreLock sem_;
public LockStrategySerializable()
{
- sem_ = new FIFOSemaphore(1);
+ sem_ = new SemaphoreLock(1);
}
/**
* @see org.jboss.cache.lock.LockStrategy#readLock()
*/
- public Sync readLock()
+ public Lock readLock()
{
return sem_;
}
@@ -45,7 +44,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#upgradeLockAttempt(long)
*/
- public Sync upgradeLockAttempt(long msecs) throws UpgradeException
+ public Lock upgradeLockAttempt(long msecs) throws UpgradeException
{
// If we come to this far, that means the thread owns a rl already
// so we just return the same lock
@@ -55,7 +54,7 @@
/**
* @see org.jboss.cache.lock.LockStrategy#writeLock()
*/
- public Sync writeLock()
+ public Lock writeLock()
{
return sem_;
}
1.1 date: 2006/12/08 18:50:49; author: genman; state: Exp;JBossCache/src/org/jboss/cache/lock/NullLock.java
Index: NullLock.java
===================================================================
package org.jboss.cache.lock;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
class NullLock implements Lock, Condition {
public void lock()
{
}
public void lockInterruptibly() throws InterruptedException
{
}
public Condition newCondition()
{
return this;
}
public boolean tryLock()
{
return true;
}
public boolean tryLock(long arg0, TimeUnit arg1) throws InterruptedException
{
return true;
}
public void unlock()
{
}
public void await() throws InterruptedException
{
}
public boolean await(long arg0, TimeUnit arg1) throws InterruptedException
{
return true;
}
public long awaitNanos(long arg0) throws InterruptedException
{
return arg0;
}
public void awaitUninterruptibly()
{
}
public boolean awaitUntil(Date arg0) throws InterruptedException
{
return true;
}
public void signal()
{
}
public void signalAll()
{
}
}
1.1 date: 2006/12/08 18:50:49; author: genman; state: Exp;JBossCache/src/org/jboss/cache/lock/SemaphoreLock.java
Index: SemaphoreLock.java
===================================================================
package org.jboss.cache.lock;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
/**
* Implements most of the methods of Lock using the {@link Semaphore} implementation.
*/
public class SemaphoreLock extends Semaphore implements Lock
{
public SemaphoreLock(int permits)
{
super(permits);
}
public void lock()
{
try
{
acquire();
}
catch (InterruptedException e)
{
lock(); // recursive, I know ..
}
}
public void lockInterruptibly() throws InterruptedException
{
acquire();
}
public Condition newCondition()
{
throw new UnsupportedOperationException();
}
public boolean tryLock()
{
return tryAcquire();
}
public boolean tryLock(long arg0, TimeUnit arg1) throws InterruptedException
{
return tryAcquire(arg0, arg1);
}
public void unlock()
{
release();
}
}
More information about the jboss-cvs-commits
mailing list