org.apache.lucene.store

## Class LockFactory

- java.lang.Object
- - org.apache.lucene.store.LockFactory

- Direct Known Subclasses:
    FSLockFactory, NoLockFactory, SingleInstanceLockFactory, VerifyingLockFactory

      public abstract class LockFactory
      extends Object

  Base class for Locking implementation. `Directory` uses instances of this class to implement locking.

  Lucene uses `NativeFSLockFactory` by default for `FSDirectory`-based index directories.

  Special care needs to be taken if you change the locking implementation: First be certain that no writer is in fact writing to the index otherwise you can easily corrupt your index. Be sure to do the LockFactory change on all Lucene instances and clean up all leftover lock files before starting the new configuration for the first time. Different implementations can not work together!

  If you suspect that some LockFactory implementation is not working properly in your environment, you can easily test it by using `VerifyingLockFactory`, `LockVerifyServer` and `LockStressTest`.

  See Also:
    `LockVerifyServer`, `LockStressTest`, `VerifyingLockFactory`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LockFactory()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract Lock` | `obtainLock(Directory dir, String lockName)` Return a new obtained Lock instance identified by lockName.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LockFactory

          public LockFactory()

  - ### Method Detail

    - #### obtainLock

          public abstract Lock obtainLock(Directory dir,
                                          String lockName)
                                   throws IOException

      Return a new obtained Lock instance identified by lockName.
      Parameters:
        `lockName` - name of the lock to be created.
      Throws:
        `LockObtainFailedException` - (optional specific exception) if the lock could not be obtained because it is currently held elsewhere.
        `IOException` - if any i/o error occurs attempting to gain the lock

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