Sometimes it is necessary to lock a file at the disk level. Since there is no native Java way of locking a file, we have to implement our own. Unfortunately, it appears as though we can only assume that rename is atomic. We base the locking on this then: rename the lock file and update it with the lock owners. How it works: for every file we want to lock we create an _lock file. This file contains information about who is locking the file, and in what mode. (Single writer, multiple readers.) To guarantee atomicity of update, we move (rename) the actual file each time we want to lock it and update the lock file. When this is done, we move (rename) it back. Almost like a two-phase commit protocol! Currently we don't support re-entrant locking.
@author Mark Little (mark@arjuna.com)
@version $Id: FileLock.java 2342 2006-03-30 13:06:17Z $
@since JTS 1.0.
@message com.arjuna.ats.arjuna.utils.FileLock_1 [com.arjuna.ats.arjuna.utils.FileLock_1] - FileLock.lock called for {0}
@message com.arjuna.ats.arjuna.utils.FileLock_2 [com.arjuna.ats.arjuna.utils.FileLock_2] - FileLock.unlock called for {0}
@message com.arjuna.ats.arjuna.utils.FileLock_3 [com.arjuna.ats.arjuna.utils.FileLock_3] - FileLock.createFile called for {0}
@message com.arjuna.ats.arjuna.utils.FileLock_4 [com.arjuna.ats.arjuna.utils.FileLock_4] - An error occurred while creating file {0}
@message com.arjuna.ats.arjuna.utils.FileLock_5 [com.arjuna.ats.arjuna.utils.FileLock_5] - FileLock.lockFile called for {0}
@message com.arjuna.ats.arjuna.utils.FileLock_6 [com.arjuna.ats.arjuna.utils.FileLock_6] - FileLock.unlockFile called for {0}
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.