org.apache.lucene.index

## Class ReaderManager

- java.lang.Object
- - org.apache.lucene.search.ReferenceManager<DirectoryReader>
  - - org.apache.lucene.index.ReaderManager

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public final class ReaderManager
      extends ReferenceManager<DirectoryReader>

  Utility class to safely share `DirectoryReader` instances across multiple threads, while periodically reopening. This class ensures each reader is closed only once all threads have finished using it.
  See Also:
    `SearcherManager`
  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.lucene.search.ReferenceManager

      `ReferenceManager.RefreshListener`

  - ### Field Summary

    - ### Fields inherited from class org.apache.lucene.search.ReferenceManager

      `current`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReaderManager(Directory dir)` Creates and returns a new ReaderManager from the given `Directory`.
    `ReaderManager(DirectoryReader reader)` Creates and returns a new ReaderManager from the given already-opened `DirectoryReader`, stealing the incoming reference.
    `ReaderManager(IndexWriter writer)` Creates and returns a new ReaderManager from the given `IndexWriter`.
    `ReaderManager(IndexWriter writer, boolean applyAllDeletes, boolean writeAllDeletes)` Expert: creates and returns a new ReaderManager from the given `IndexWriter`, controlling whether past deletions should be applied.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `decRef(DirectoryReader reference)` Decrement reference counting on the given reference.
    `protected int` | `getRefCount(DirectoryReader reference)` Returns the current reference count of the given reference.
    `protected DirectoryReader` | `refreshIfNeeded(DirectoryReader referenceToRefresh)` Refresh the given reference if needed.
    `protected boolean` | `tryIncRef(DirectoryReader reference)` Try to increment reference counting on the given reference.

    - ### Methods inherited from class org.apache.lucene.search.ReferenceManager

      `acquire, addListener, afterClose, afterMaybeRefresh, close, maybeRefresh, maybeRefreshBlocking, release, removeListener`

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

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

- - ### Constructor Detail

    - #### ReaderManager

          public ReaderManager(IndexWriter writer)
                        throws IOException

      Creates and returns a new ReaderManager from the given `IndexWriter`.
      Parameters:
        `writer` - the IndexWriter to open the IndexReader from.
      Throws:
        `IOException` - If there is a low-level I/O error

    - #### ReaderManager

          public ReaderManager(IndexWriter writer,
                               boolean applyAllDeletes,
                               boolean writeAllDeletes)
                        throws IOException

      Expert: creates and returns a new ReaderManager from the given `IndexWriter`, controlling whether past deletions should be applied.
      Parameters:
        `writer` - the IndexWriter to open the IndexReader from.
        `applyAllDeletes` - If `true`, all buffered deletes will be applied (made visible) in the `IndexSearcher` / `DirectoryReader`. If `false`, the deletes may or may not be applied, but remain buffered (in IndexWriter) so that they will be applied in the future. Applying deletes can be costly, so if your app can tolerate deleted documents being returned you might gain some performance by passing `false`. See `DirectoryReader.openIfChanged(DirectoryReader, IndexWriter, boolean)`.
        `writeAllDeletes` - If `true`, new deletes will be forcefully written to index files.
      Throws:
        `IOException` - If there is a low-level I/O error

    - #### ReaderManager

          public ReaderManager(Directory dir)
                        throws IOException

      Creates and returns a new ReaderManager from the given `Directory`.
      Parameters:
        `dir` - the directory to open the DirectoryReader on.
      Throws:
        `IOException` - If there is a low-level I/O error

    - #### ReaderManager

          public ReaderManager(DirectoryReader reader)
                        throws IOException

      Creates and returns a new ReaderManager from the given already-opened `DirectoryReader`, stealing the incoming reference.
      Parameters:
        `reader` - the directoryReader to use for future reopens
      Throws:
        `IOException` - If there is a low-level I/O error

  - ### Method Detail

    - #### decRef

          protected void decRef(DirectoryReader reference)
                         throws IOException

      Description copied from class: `ReferenceManager`
      Decrement reference counting on the given reference.
      Specified by:
        `decRef` in class `ReferenceManager<DirectoryReader>`
      Throws:
        `IOException` - if reference decrement on the given resource failed.

    - #### refreshIfNeeded

          protected DirectoryReader refreshIfNeeded(DirectoryReader referenceToRefresh)
                                             throws IOException

      Description copied from class: `ReferenceManager`
      Refresh the given reference if needed. Returns `null` if no refresh was needed, otherwise a new refreshed reference.
      Specified by:
        `refreshIfNeeded` in class `ReferenceManager<DirectoryReader>`
      Throws:
        `IOException` - if the refresh operation failed

    - #### tryIncRef

          protected boolean tryIncRef(DirectoryReader reference)

      Description copied from class: `ReferenceManager`
      Try to increment reference counting on the given reference. Return true if the operation was successful.
      Specified by:
        `tryIncRef` in class `ReferenceManager<DirectoryReader>`

    - #### getRefCount

          protected int getRefCount(DirectoryReader reference)

      Description copied from class: `ReferenceManager`
      Returns the current reference count of the given reference.
      Specified by:
        `getRefCount` in class `ReferenceManager<DirectoryReader>`

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