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 472959 2006-11-09 16:21:50Z yonik $
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
protected Throwable
failureReason
If a lock obtain called, this failureReason may be set with the "root cause" Exception as to why the lock was not obtained.

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.

Field Details

LOCK_POLL_INTERVAL

public static long LOCK_POLL_INTERVAL

failureReason

protected Throwable failureReason
If a lock obtain called, this failureReason may be set with the "root cause" Exception as to why the lock was not obtained.

Method Details

isLocked

public abstract boolean isLocked()

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

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

release

public abstract void release()
Releases exclusive access.

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.