org.apache.lucene.store

Class 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 179414 2005-06-01 20:10:58Z dnaber $

Author: Doug Cutting

See Also: makeLock

Nested Class Summary
abstract static classLock.With
Utility class for executing code with exclusive access.
Field Summary
static longLOCK_POLL_INTERVAL
Method Summary
abstract booleanisLocked()
Returns true if the resource is currently locked.
abstract booleanobtain()
Attempts to obtain exclusive access and immediately return upon success or failure.
booleanobtain(long lockWaitTimeout)
Attempts to obtain an exclusive lock within amount of time given.
abstract voidrelease()
Releases exclusive access.

Field Detail

LOCK_POLL_INTERVAL

public static long LOCK_POLL_INTERVAL

Method Detail

isLocked

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

obtain

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

Returns: true iff exclusive access is obtained

obtain

public boolean obtain(long lockWaitTimeout)
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.
Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.