gate.creole.annic.apache.lucene.store
Class Lock

java.lang.Object
  extended by gate.creole.annic.apache.lucene.store.Lock

public abstract class Lock
extends Object

An interprocess mutex lock.

Typical use might look like:

 new Lock.With(directory.makeLock("my.lock")) {
     public Object doBody() {
       ... code to execute while locked ...
     }
   }.run();
 

Version:
$Id: Lock.java 529 2004-10-05 11:55:26Z niraj $
Author:
Doug Cutting
See Also:
Directory.makeLock(String)

Nested Class Summary
static class Lock.With
          Utility class for executing code with exclusive access.
 
Field Summary
static long LOCK_POLL_INTERVAL
           
 
Constructor Summary
Lock()
           
 
Method Summary
abstract  boolean isLocked()
          Returns true if the resource is currently locked.
abstract  boolean obtain()
          Attempts to obtain exclusive access and immediately return upon success or failure.
 boolean obtain(long lockWaitTimeout)
          Attempts to obtain an exclusive lock within amount of time given.
abstract  void release()
          Releases exclusive access.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCK_POLL_INTERVAL

public static final long LOCK_POLL_INTERVAL
See Also:
Constant Field Values
Constructor Detail

Lock

public Lock()
Method Detail

obtain

public abstract boolean obtain()
                        throws IOException
Attempts to obtain exclusive access and immediately return upon success or failure.

Returns:
true iff exclusive access is obtained
Throws:
IOException

obtain

public boolean obtain(long lockWaitTimeout)
               throws IOException
Attempts to obtain an exclusive lock within amount of time given. Currently polls once per second until lockWaitTimeout is passed.

Parameters:
lockWaitTimeout - length of time to wait in ms
Returns:
true if lock was obtained
Throws:
IOException - if lock wait times out or obtain() throws an IOException

release

public abstract void release()
Releases exclusive access.


isLocked

public abstract boolean isLocked()
Returns true if the resource is currently locked. Note that one must still call obtain() before using the resource.