|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exist.storage.lock.FileLock
public class FileLock
Cooperative inter-process file locking, used to synchronize access to database files across
processes, i.e. across different Java VMs or separate database instances within one
VM. This is similar to the native file locks provided by Java NIO. However, the NIO
implementation has various problems. Among other things, we observed that locks
were not properly released on WinXP.
FileLock implements a cooperative approach. The class attempts to write a lock file
at the specified location. Every lock file stores 1) a magic word to make sure that the
file was really written by eXist, 2) a heartbeat timestamp. The procedure for acquiring the
lock in tryLock()
is as follows:
If a lock file does already exist in the specified location, we check its heartbeat timestamp.
If the timestamp is more than HEARTBEAT
milliseconds in the past, we assume
that the lock is stale and its owner process has died. The lock file is removed and we create
a new one.
If the heartbeat indicates that the owner process is still alive, the lock
attempt is aborted and tryLock()
returns false.
Otherwise, we create a new lock file and start a daemon thread to periodically update
the lock file's heartbeat value.
Constructor Summary | |
---|---|
FileLock(BrokerPool pool,
File parent,
String lockName)
|
|
FileLock(BrokerPool pool,
String path)
|
Method Summary | |
---|---|
File |
getFile()
Returns the lock file that represents the active lock held by the FileLock. |
Date |
getLastHeartbeat()
Returns the last heartbeat written to the lock file. |
void |
release()
Release the lock. |
boolean |
tryLock()
Attempt to create the lock file and thus acquire a lock. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileLock(BrokerPool pool, String path)
public FileLock(BrokerPool pool, File parent, String lockName)
Method Detail |
---|
public boolean tryLock() throws ReadOnlyException
ReadOnlyException
- if the lock file could not be created or saved
due to IO errors. The caller may want to switch to read-only mode.public void release()
public Date getLastHeartbeat()
public File getFile()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |