1 23 24 package org.apache.commons.transaction.locking; 25 26 import org.apache.commons.transaction.util.LoggerFacade; 27 28 34 public class ReadWriteLockManager extends GenericLockManager { 35 36 42 public ReadWriteLockManager(LoggerFacade logger, long timeoutMSecs) { 43 super(ReadWriteLock.WRITE_LOCK, logger, timeoutMSecs); 44 } 45 46 protected ReadWriteLockManager(int maxLockLevel, LoggerFacade logger, long timeoutMSecs) 47 throws IllegalArgumentException { 48 super(maxLockLevel, logger, timeoutMSecs); 49 } 50 51 64 public boolean tryReadLock(Object ownerId, Object resourceId) { 65 return tryLock(ownerId, resourceId, ReadWriteLock.READ_LOCK, true); 66 } 67 68 81 public boolean tryWriteLock(Object ownerId, Object resourceId) { 82 return tryLock(ownerId, resourceId, ReadWriteLock.WRITE_LOCK, true); 83 } 84 85 99 public boolean checkReadLock(Object ownerId, Object resourceId) { 100 return checkLock(ownerId, resourceId, ReadWriteLock.READ_LOCK, true); 101 } 102 103 114 public boolean hasWriteLock(Object ownerId, Object resourceId) { 115 return hasLock(ownerId, resourceId, ReadWriteLock.WRITE_LOCK); 116 } 117 118 129 public boolean hasReadLock(Object ownerId, Object resourceId) { 130 return hasLock(ownerId, resourceId, ReadWriteLock.READ_LOCK); 131 } 132 133 147 public boolean checkWriteLock(Object ownerId, Object resourceId) { 148 return checkLock(ownerId, resourceId, ReadWriteLock.WRITE_LOCK, true); 149 } 150 151 166 public void readLock(Object ownerId, Object resourceId) throws LockException { 167 lock(ownerId, resourceId, ReadWriteLock.READ_LOCK, GenericLock.COMPATIBILITY_REENTRANT, 168 false, globalTimeoutMSecs); 169 } 170 171 186 public void writeLock(Object ownerId, Object resourceId) throws LockException { 187 lock(ownerId, resourceId, ReadWriteLock.WRITE_LOCK, GenericLock.COMPATIBILITY_REENTRANT, 188 true, globalTimeoutMSecs); 189 } 190 191 protected GenericLock createLock(Object resourceId) { 192 synchronized (globalLocks) { 193 GenericLock lock = new ReadWriteLock(resourceId, logger); 194 globalLocks.put(resourceId, lock); 195 return lock; 196 } 197 } 198 199 } | Popular Tags |