org.openstreetmap.osmosis.core.util
Class FileBasedLock

java.lang.Object
  extended by org.openstreetmap.osmosis.core.util.FileBasedLock
All Implemented Interfaces:
Releasable

public class FileBasedLock
extends java.lang.Object
implements Releasable

This class provides a mechanism to use simple files as locks to prevent multiple threads or processes from updating common files.

Author:
Brett Henderson

Constructor Summary
FileBasedLock(java.io.File lockFile)
          Creates a new instance.
 
Method Summary
 void lock()
          Obtain an exclusive lock.
 void release()
          Performs resource cleanup tasks such as closing files, or database connections.
 void unlock()
          Release the lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileBasedLock

public FileBasedLock(java.io.File lockFile)
Creates a new instance.

Parameters:
lockFile - The file to use for locking.
Method Detail

lock

public void lock()
Obtain an exclusive lock. This will fail if another thread or process already has a lock.


unlock

public void unlock()
Release the lock.


release

public void release()
Performs resource cleanup tasks such as closing files, or database connections. This must be called after all processing is complete and may be called multiple times. Implementations must call release on any nested Releasable objects. It should be called within a finally block to ensure it is called in exception scenarios.

Specified by:
release in interface Releasable