Package org.apache.lucene.store
Class Lock
- java.lang.Object
 - 
- org.apache.lucene.store.Lock
 
 
- 
- All Implemented Interfaces:
 java.io.Closeable,java.lang.AutoCloseable
public abstract class Lock extends java.lang.Object implements java.io.CloseableAn interprocess mutex lock.Typical use might look like:
new Lock.With(directory.makeLock("my.lock")) { public Object doBody() { ... code to execute while locked ... } }.run();- See Also:
 Directory.makeLock(String)
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLock.WithUtility class for executing code with exclusive access. 
- 
Field Summary
Fields Modifier and Type Field Description static longLOCK_OBTAIN_WAIT_FOREVERPass this value toobtain(long)to try forever to obtain the lock.static longLOCK_POLL_INTERVALHow longobtain(long)waits, in milliseconds, in between attempts to acquire the lock. 
- 
Constructor Summary
Constructors Constructor Description Lock() 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidclose()Releases exclusive access.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. 
 - 
 
- 
- 
Field Detail
- 
LOCK_POLL_INTERVAL
public static long LOCK_POLL_INTERVAL
How longobtain(long)waits, in milliseconds, in between attempts to acquire the lock. 
- 
LOCK_OBTAIN_WAIT_FOREVER
public static final long LOCK_OBTAIN_WAIT_FOREVER
Pass this value toobtain(long)to try forever to obtain the lock.- See Also:
 - Constant Field Values
 
 
 - 
 
- 
Method Detail
- 
obtain
public abstract boolean obtain() throws java.io.IOExceptionAttempts to obtain exclusive access and immediately return upon success or failure. Useclose()to release the lock.- Returns:
 - true iff exclusive access is obtained
 - Throws:
 java.io.IOException
 
- 
obtain
public boolean obtain(long lockWaitTimeout) throws java.io.IOExceptionAttempts to obtain an exclusive lock within amount of time given. Polls once perLOCK_POLL_INTERVAL(currently 1000) milliseconds until lockWaitTimeout is passed.- Parameters:
 lockWaitTimeout- length of time to wait in milliseconds orLOCK_OBTAIN_WAIT_FOREVERto retry forever- Returns:
 - true if lock was obtained
 - Throws:
 LockObtainFailedException- if lock wait times outjava.lang.IllegalArgumentException- if lockWaitTimeout is out of boundsjava.io.IOException- if obtain() throws IOException
 
- 
close
public abstract void close() throws java.io.IOExceptionReleases exclusive access.- Specified by:
 closein interfacejava.lang.AutoCloseable- Specified by:
 closein interfacejava.io.Closeable- Throws:
 java.io.IOException
 
- 
isLocked
public abstract boolean isLocked() throws java.io.IOExceptionReturns true if the resource is currently locked. Note that one must still callobtain()before using the resource.- Throws:
 java.io.IOException
 
 - 
 
 -