org.apache.lucene.store
Class NativeFSLockFactory

java.lang.Object
  extended byorg.apache.lucene.store.LockFactory
      extended byorg.apache.lucene.store.NativeFSLockFactory

public class NativeFSLockFactory
extends LockFactory

Implements LockFactory using native OS file locks (available through java.nio.*). Note that for certain filesystems native locks are possible but must be explicity configured and enabled (and may be disabled by default). For example, for NFS servers there sometimes must be a separate lockd process running, and other configuration may be required such as running the server in kernel mode. Other filesystems may not even support native OS locks in which case you must use a different LockFactory implementation.

The advantage of this lock factory over SimpleFSLockFactory is that the locks should be "correct", whereas SimpleFSLockFactory uses java.io.File.createNewFile which has warnings about not using it for locking. Furthermore, if the JVM crashes, the OS will free any held locks, whereas SimpleFSLockFactory will keep the locks held, requiring manual removal before re-running Lucene.

Note that, unlike SimpleFSLockFactory, the existence of leftover lock files in the filesystem on exiting the JVM is fine because the OS will free the locks held against these files even though the files still remain.

Native locks file names have the substring "-n-", which you can use to differentiate them from lock files created by SimpleFSLockFactory.

See Also:
LockFactory

Field Summary
 
Fields inherited from class org.apache.lucene.store.LockFactory
lockPrefix
 
Constructor Summary
NativeFSLockFactory(File lockDir)
          Create a NativeFSLockFactory instance, storing lock files into the specified lockDir:
NativeFSLockFactory(String lockDirName)
          Create a NativeFSLockFactory instance, storing lock files into the specified lockDirName:
 
Method Summary
 void clearLock(String lockName)
          Attempt to clear (forcefully unlock and remove) the specified lock.
 Lock makeLock(String lockName)
          Return a new Lock instance identified by lockName.
 
Methods inherited from class org.apache.lucene.store.LockFactory
getLockPrefix, setLockPrefix
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NativeFSLockFactory

public NativeFSLockFactory(String lockDirName)
                    throws IOException
Create a NativeFSLockFactory instance, storing lock files into the specified lockDirName:

Parameters:
lockDirName - where lock files are created.

NativeFSLockFactory

public NativeFSLockFactory(File lockDir)
                    throws IOException
Create a NativeFSLockFactory instance, storing lock files into the specified lockDir:

Parameters:
lockDir - where lock files are created.
Method Detail

makeLock

public Lock makeLock(String lockName)
Description copied from class: LockFactory
Return a new Lock instance identified by lockName.

Specified by:
makeLock in class LockFactory
Parameters:
lockName - name of the lock to be created.

clearLock

public void clearLock(String lockName)
               throws IOException
Description copied from class: LockFactory
Attempt to clear (forcefully unlock and remove) the specified lock. Only call this at a time when you are certain this lock is no longer in use.

Specified by:
clearLock in class LockFactory
Parameters:
lockName - name of the lock to be cleared.
Throws:
IOException


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