|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--uk.org.ogsadai.common.FileLock
This class implements a Multiple Reader, Single Writer (MRSW) mutual exclusion locking facility.
Threads wishing to obtain a lock on a file should call
getReadLock or getWriteLock, and should call
returnReadLock or returnWriteLock to relinquish
the lock.
The MRSW lock permits either one thread to hold a write lock, or
any number of threads to hold read locks. For example, if two threads
have read locks and another thread calls getWriteLock to
obtain a write lock, this thread waits until both reading threads
have relinquished their read locks via returnReadLock.
| Constructor Summary | |
FileLock()
|
|
| Method Summary | |
int |
countReaders(java.lang.String fileName)
Return the number of threads with a read lock on a file. |
int |
countWriters(java.lang.String fileName)
Return the number of threads with a write lock on a file. |
void |
doLocking(java.lang.String fileName,
boolean lock,
boolean read)
Perform a locking or unlocking operation on a file. |
void |
getReadLock(java.lang.String fileName)
Block until a read lock is available on a file, and obtain it. |
void |
getWriteLock(java.lang.String fileName)
Block until a write lock is available on a file, and obtain it. |
void |
returnReadLock(java.lang.String fileName)
Relinquish a read lock on a file. |
void |
returnWriteLock(java.lang.String fileName)
Relinquish a write lock on a file. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public FileLock()
| Method Detail |
public void doLocking(java.lang.String fileName,
boolean lock,
boolean read)
throws CommonSystemException
fileName - the file to lock or unlocklock - true to lock the file, false to unlock the fileread - true if the lock is a read lock, false if the lock is a write lock
CommonSystemException - if an error occurs while waiting for a lock
public void getReadLock(java.lang.String fileName)
throws CommonSystemException
fileName - the file to lock
CommonSystemException - if an error occurs while waiting for the lock
public void returnReadLock(java.lang.String fileName)
throws CommonSystemException
fileName - the file to unlock
CommonSystemException - if there is no existing read lock
public void getWriteLock(java.lang.String fileName)
throws CommonSystemException
fileName - the file to lock
CommonSystemException - if an error occurs while waiting for the lock
public void returnWriteLock(java.lang.String fileName)
throws CommonSystemException
fileName - the file to unlock
CommonSystemException - if there is no existing write lockpublic int countReaders(java.lang.String fileName)
fileName - the file
public int countWriters(java.lang.String fileName)
fileName - the file
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||