|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.search.ReferenceManager<IndexSearcher> org.apache.lucene.search.NRTManager
public class NRTManager
Utility class to manage sharing near-real-time searchers across multiple searching thread. The difference vs SearcherManager is that this class enables individual requests to wait until specific indexing changes are visible.
You must create an IndexWriter, then create a NRTManager.TrackingIndexWriter
from it, and pass that to the
NRTManager. You may want to create two NRTManagers, once
that always applies deletes on refresh and one that does
not. In this case you should use a single NRTManager.TrackingIndexWriter
instance for both.
Then, use ReferenceManager.acquire()
to obtain the
IndexSearcher
, and ReferenceManager.release(G)
(ideally,
from within a finally
clause) to release it.
NOTE: to use this class, you must call ReferenceManager.maybeRefresh()
periodically. The NRTManagerReopenThread
is a
simple class to do this on a periodic basis, and reopens
more quickly if a request is waiting. If you implement
your own reopener, be sure to call addWaitingListener(org.apache.lucene.search.NRTManager.WaitingListener)
so your reopener is notified when a
caller is waiting for a specific generation
searcher.
SearcherFactory
Nested Class Summary | |
---|---|
static class |
NRTManager.TrackingIndexWriter
Class that tracks changes to a delegated IndexWriter. |
static interface |
NRTManager.WaitingListener
NRTManager invokes this interface to notify it when a caller is waiting for a specific generation searcher to be visible. |
Field Summary |
---|
Fields inherited from class org.apache.lucene.search.ReferenceManager |
---|
current |
Constructor Summary | |
---|---|
NRTManager(NRTManager.TrackingIndexWriter writer,
SearcherFactory searcherFactory)
Create new NRTManager. |
|
NRTManager(NRTManager.TrackingIndexWriter writer,
SearcherFactory searcherFactory,
boolean applyAllDeletes)
Expert: just like NRTManager(TrackingIndexWriter,SearcherFactory) ,
but you can also specify whether each reopened searcher must
apply deletes. |
Method Summary | |
---|---|
void |
addWaitingListener(NRTManager.WaitingListener l)
Adds a listener, to be notified when a caller is waiting for a specific generation searcher to be visible. |
protected void |
afterClose()
Called after close(), so subclass can free any resources. |
protected void |
afterRefresh()
Called after swapReference has installed a new instance. |
protected void |
decRef(IndexSearcher reference)
Decrement reference counting on the given reference. |
long |
getCurrentSearchingGen()
Returns generation of current searcher. |
boolean |
isSearcherCurrent()
Returns true if no changes have occured since this searcher
ie. |
protected IndexSearcher |
refreshIfNeeded(IndexSearcher referenceToRefresh)
Refresh the given reference if needed. |
void |
removeWaitingListener(NRTManager.WaitingListener l)
Remove a listener added with addWaitingListener(org.apache.lucene.search.NRTManager.WaitingListener) . |
protected boolean |
tryIncRef(IndexSearcher reference)
Try to increment reference counting on the given reference. |
void |
waitForGeneration(long targetGen)
Waits for the target generation to become visible in the searcher. |
void |
waitForGeneration(long targetGen,
long time,
TimeUnit unit)
Waits for the target generation to become visible in the searcher. |
Methods inherited from class org.apache.lucene.search.ReferenceManager |
---|
acquire, close, maybeRefresh, release |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NRTManager(NRTManager.TrackingIndexWriter writer, SearcherFactory searcherFactory) throws IOException
writer
- TrackingIndexWriter to open near-real-time
readerssearcherFactory
- An optional SearcherFactory
. Pass
null
if you don't require the searcher to be warmed
before going live or other custom behavior.
IOException
public NRTManager(NRTManager.TrackingIndexWriter writer, SearcherFactory searcherFactory, boolean applyAllDeletes) throws IOException
NRTManager(TrackingIndexWriter,SearcherFactory)
,
but you can also specify whether each reopened searcher must
apply deletes. This is useful for cases where certain
uses can tolerate seeing some deleted docs, since
reopen time is faster if deletes need not be applied.
IOException
Method Detail |
---|
protected void decRef(IndexSearcher reference) throws IOException
ReferenceManager
decRef
in class ReferenceManager<IndexSearcher>
IOException
protected boolean tryIncRef(IndexSearcher reference)
ReferenceManager
tryIncRef
in class ReferenceManager<IndexSearcher>
public void addWaitingListener(NRTManager.WaitingListener l)
public void removeWaitingListener(NRTManager.WaitingListener l)
addWaitingListener(org.apache.lucene.search.NRTManager.WaitingListener)
.
public void waitForGeneration(long targetGen)
ReferenceManager.maybeRefresh()
or until the NRTManager
is closed.
targetGen
- the generation to wait forpublic void waitForGeneration(long targetGen, long time, TimeUnit unit)
ReferenceManager.maybeRefresh()
, the given waiting time has elapsed, or until
the NRTManager is closed.
NOTE: if the waiting time elapses before the requested target generation is
available the current SearcherManager
is returned instead.
targetGen
- the generation to wait fortime
- the time to wait for the target generationunit
- the waiting time's time unitpublic long getCurrentSearchingGen()
protected IndexSearcher refreshIfNeeded(IndexSearcher referenceToRefresh) throws IOException
ReferenceManager
null
if no refresh
was needed, otherwise a new refreshed reference.
refreshIfNeeded
in class ReferenceManager<IndexSearcher>
IOException
protected void afterRefresh()
ReferenceManager
afterRefresh
in class ReferenceManager<IndexSearcher>
protected void afterClose() throws IOException
ReferenceManager
afterClose
in class ReferenceManager<IndexSearcher>
IOException
public boolean isSearcherCurrent() throws IOException
true
if no changes have occured since this searcher
ie. reader was opened, otherwise false
.
IOException
IndexReader.isCurrent()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |