1 7 package org.jboss.cache.lock; 8 9 import EDU.oswego.cs.dl.util.concurrent.Sync; 10 import EDU.oswego.cs.dl.util.concurrent.ReentrantWriterPreferenceReadWriteLock; 11 12 16 public class BelasLockStrategy implements LockStrategy { 17 ReentrantWriterPreferenceReadWriteLock lock=new ReentrantWriterPreferenceReadWriteLock(); 18 19 public BelasLockStrategy() { 20 } 21 22 public Sync readLock() { 23 return lock.readLock(); 24 } 25 26 public Sync writeLock() { 27 return lock.writeLock(); 28 } 29 30 public Sync upgradeLockAttempt(long msecs) throws UpgradeException { 31 boolean acquired; 32 Sync writeLock=lock.writeLock(); 33 34 try { 35 acquired=writeLock.attempt(msecs); 36 if(acquired) { 37 lock.readLock().release(); 38 return writeLock; 39 } 40 else { 41 return null; 42 } 43 } 44 catch(InterruptedException iex) { 45 throw new UpgradeException("failed upgrading lock", iex); 46 } 47 } 48 } 49 | Popular Tags |