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.
Creates and returns a new ReaderManager from the given IndexWriter.
| name | type | description |
|---|---|---|
| writer | org.apache.lucene.index.IndexWriter | the IndexWriter to open the IndexReader from. |
| IOException | If there is a low-level I/O error | |
<init>(org.apache.lucene.index.IndexWriter writer, boolean applyAllDeletes, boolean writeAllDeletes)Expert: creates and returns a new ReaderManager from the given IndexWriter, controlling
whether past deletions should be applied.
| name | type | description |
|---|---|---|
| writer | org.apache.lucene.index.IndexWriter | the IndexWriter to open the IndexReader from. |
| apply_all_deletes | boolean | 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). |
| write_all_deletes | boolean | If true, new deletes will be forcefully written to index
files. |
| IOException | If there is a low-level I/O error | |
Creates and returns a new ReaderManager from the given Directory.
| name | type | description |
|---|---|---|
| dir | org.apache.lucene.store.Directory | the directory to open the DirectoryReader on. |
| IOException | If there is a low-level I/O error | |
Creates and returns a new ReaderManager from the given already-opened DirectoryReader,
stealing the incoming reference.
| name | type | description |
|---|---|---|
| reader | org.apache.lucene.index.DirectoryReader | the directoryReader to use for future reopens |
| IOException | If there is a low-level I/O error | |
acquire()Obtain the current reference. You must match every call to acquire with one call to #release; it's best to do so in a finally clause, and set the reference to null to
prevent accidental usage after it has been released.
| AlreadyClosedException | if the reference manager has been closed. |
|
addListener(org.apache.lucene.search.ReferenceManager.RefreshListener listener)Adds a listener, to be notified when a reference is refreshed/swapped.
close()Closes this ReferenceManager to prevent future acquiring. A reference
manager should be closed if the reference to the managed resource should be disposed or the
application using the ReferenceManager is shutting down. The managed resource might not
be released immediately, if the ReferenceManager user is holding on to a previously
acquired reference. The resource will be released once when the last
reference is released. Those references can still be used as if the
manager was still active.
Applications should not acquire new references from this manager once
this method has been called. Acquiring a resource on a closed ReferenceManager will throw an AlreadyClosedException.
| IOException | if the underlying reader of the current reference could not be closed | |
maybeRefresh()You must call this (or #maybeRefreshBlocking()), periodically, if you want that #acquire() will return refreshed instances.
Threads: it's fine for more than one thread to call this at once. Only the first thread will attempt the refresh; subsequent threads will see that another thread is already handling refresh and will return immediately. Note that this means if another thread is already refreshing then subsequent threads will return right away without waiting for the refresh to complete.
If this method returns true it means the calling thread either refreshed or that there were no changes to refresh. If it returns false it means another thread is currently refreshing.
| IOException | if refreshing the resource causes an IOException |
|
| AlreadyClosedException | if the reference manager has been closed. |
|
maybeRefreshBlocking()You must call this (or #maybeRefresh()), periodically, if you want that #acquire() will return refreshed instances.
Threads: unlike #maybeRefresh(), if another thread is currently refreshing,
this method blocks until that thread completes. It is useful if you want to guarantee that the
next call to #acquire() will return a refreshed instance. Otherwise, consider using the
non-blocking #maybeRefresh().
| IOException | if refreshing the resource causes an IOException |
|
| AlreadyClosedException | if the reference manager has been closed. |
|
release(G reference)Release the reference previously obtained via #acquire().
NOTE: it's safe to call this after #close().
| IOException | if the release operation on the given resource throws an IOException |
|
removeListener(org.apache.lucene.search.ReferenceManager.RefreshListener listener)Remove a listener added with #addListener(RefreshListener).