com.revusky.niggle.util
Class FileLock

java.lang.Object
  |
  +--com.revusky.niggle.util.FileLock

public class FileLock
extends java.lang.Object

A file lock. Since proper file locking is problematic (PhD thesis goes here), we use this class throughout the MediMOM systems to manage access to shared flat files. This mechanism is used by convention.

This class will attempt to acquire a lock for at most MAX_LOCK_LIFE seconds. If that fails, an error is written to the log file, and the lock is stolen. This implies that we never expect any of our processes to spend more than MAX_LOCK_LIFE writing to a file. If a lock gets to be that old, we assume the process or thread that created it died unexpectedly.

MAX_LOCK_LIFE should be set to a value that we would consider to be beyond the maximum acceptable time for any of our write operations.

NB: This locking system is a perfect semaphore mechanism within a single process. It is pretty good between processes, but not perfect. The only way it will be perfect is if the locking is managed by a single process.

Author:
Paul Murphy murphy@niggle.com

Constructor Summary
FileLock(java.lang.String filename)
          Designated constructor.
 
Method Summary
 void dispose()
          Deletes the file associated with the current lock object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileLock

public FileLock(java.lang.String filename)
         throws FileLockException
Designated constructor.
Throws:
FileLockException - thrown when a lock cannot be acquired.
Method Detail

dispose

public void dispose()
Deletes the file associated with the current lock object. If the file does not exist, or contains an invalid timestamp, logs an error.