ecologylab.io
Class LockFile

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.io.LockFile

public class LockFile
extends Debug

Simple utility to write and detect lock files.

Author:
blake

Constructor Summary
LockFile(java.lang.String uniqueProgramName)
          Takes a program name to check/generate lockfile state.
 
Method Summary
 void close()
          Gets rid of the file handler (for garbage collection)
 java.io.File getFileLock()
          Gets a File reference to the actual file lock.
 boolean isLocked()
          Determine weather or not the program is locked right now.
 boolean isOld()
          Return true if the lock file exists, and is older than 90 seconds ago.
 boolean lock()
          Lock the program (create a lockfile).
 boolean unlock()
          Unlock the program (delete the lockfile).
 
Methods inherited from class ecologylab.generic.Debug
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LockFile

public LockFile(java.lang.String uniqueProgramName)
Takes a program name to check/generate lockfile state.

Parameters:
uniqueProgramName - The unique name of the program concerned with locking.
Method Detail

lock

public boolean lock()
Lock the program (create a lockfile). Return a status.

Returns:
whether or not the lockfile could be sucessfully written.

unlock

public boolean unlock()
Unlock the program (delete the lockfile). Return a status.

Returns:
whether or not the lockfile could be sucessfully deleted.

isLocked

public boolean isLocked()
Determine weather or not the program is locked right now. This is NEVER cached.

Returns:
whether or not this program is locked.

isOld

public boolean isOld()
Return true if the lock file exists, and is older than 90 seconds ago.

Returns:

close

public void close()
Gets rid of the file handler (for garbage collection)


getFileLock

public java.io.File getFileLock()
Gets a File reference to the actual file lock.

Returns:
The file lock.