net.sourceforge.cobertura.util
Class FileLocker

java.lang.Object
  extended by net.sourceforge.cobertura.util.FileLocker

public class FileLocker
extends java.lang.Object

This class controls access to any file so that multiple JVMs will not be able to write to the file at the same time. A file called "filename.lock" is created and Java's FileLock class is used to lock the file. The java.nio classes were introduced in Java 1.4, so this class does a no-op when used with Java 1.3. The class maintains compatability with Java 1.3 by accessing the java.nio classes using reflection.

Author:
John Lewis, Mark Doliner

Field Summary
private  java.lang.Object lock
          An object of type FileLock, created using reflection.
private  java.lang.Object lockChannel
          An object of type FileChannel, created using reflection.
private  java.io.File lockFile
          A file called "filename.lock" that resides in the same directory as "filename"
 
Constructor Summary
FileLocker(java.io.File file)
           
 
Method Summary
private static java.lang.Object closeChannel(java.lang.Object channel)
           
 boolean lock()
          Obtains a lock on the file.
 void release()
          Releases the lock on the file.
private static java.lang.Object releaseFileLock(java.lang.Object lock)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lock

private java.lang.Object lock
An object of type FileLock, created using reflection.


lockChannel

private java.lang.Object lockChannel
An object of type FileChannel, created using reflection.


lockFile

private java.io.File lockFile
A file called "filename.lock" that resides in the same directory as "filename"

Constructor Detail

FileLocker

public FileLocker(java.io.File file)
Method Detail

lock

public boolean lock()
Obtains a lock on the file. This blocks until the lock is obtained.


release

public void release()
Releases the lock on the file.


releaseFileLock

private static java.lang.Object releaseFileLock(java.lang.Object lock)

closeChannel

private static java.lang.Object closeChannel(java.lang.Object channel)