Class Locker

java.lang.Object
  extended byLocker

public class Locker
extends java.lang.Object

File locking.

Version:
$Id: $
Author:
Jim Wiggins, iWiggins.com

Nested Class Summary
static interface Locker.LockerCB
           
 
Constructor Summary
Locker(java.io.File lockfile)
          Constructor.
 
Method Summary
 java.lang.String getError()
          Return latest error code.
static void main(java.lang.String[] args)
          Test method.
 void release()
          Release the lockfile.
 boolean take()
          Take the lockfile, blocking version.
 boolean take(int retries, int secondsToWait, Locker.LockerCB cb)
          Take the lockfile, non-blocking version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Locker

public Locker(java.io.File lockfile)
Constructor.

Method Detail

getError

public java.lang.String getError()
Return latest error code.


take

public boolean take()
Take the lockfile, blocking version.

Returns:
true if got lock, false if exception (fetch it with getError())

take

public boolean take(int retries,
                    int secondsToWait,
                    Locker.LockerCB cb)
Take the lockfile, non-blocking version.

Parameters:
retries - - number of times to retry
secondsToWait - - number of seconds to sleep between retries
cb - - callback to user after each non-exceptional failure
Returns:
true if got lock, false puts reason into getError()

release

public void release()
Release the lockfile.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test method.

Throws:
java.lang.Exception