com.faunos.util.cc
Class XprocLock

java.lang.Object
  extended by com.faunos.util.cc.XprocLock

public class XprocLock
extends Object

A cross-process, file-based locking protocol. The implementation uses an exclusive lock on a local file.

This implementation does not work on every OS/file system combination. For example, if the local file is NTFS mounted through aufs on Linux, then this implementation does not work. Must experiment to find a more robust cross-process lock implementation for this class. Consider this class for the time being a marker for a better implementation.

Author:
Babak Farhang

Constructor Summary
XprocLock(File lockFile)
          Creates an instance with the specified lock file.
 
Method Summary
 void lock()
          Locks the instance by acquiring an exclusive lock on the underlying file passed in at construction.
 void release()
          Releases the lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XprocLock

public XprocLock(File lockFile)
Creates an instance with the specified lock file. On return, the instance is not locked.

Note the given lockFile must not be locked from within this process any other way. Also, the specified lock file must be a local file.

See Also:
lock
Method Detail

lock

public void lock()
Locks the instance by acquiring an exclusive lock on the underlying file passed in at construction. Repeated invocations are OK; the lock is still released on a single invocation of release().

Throws:
IllegalStateException - if the underlying file lock could not be acquired
See Also:
release()

release

public void release()
Releases the lock. The lock may be re-acquired.

See Also:
lock()


SourceForge.net Logo