public class ControlledRealTimeReopenThread<T>
extends java.lang.Thread
implements java.io.Closeable
ReferenceManager
, with methods to wait for a specific
index changes to become visible. When a given search request needs to see a specific
index change, call the {#waitForGeneration} to wait for
that change to be visible. Note that this will only
scale well if most searches do not need to wait for a
specific index generation.Modifier and Type | Class and Description |
---|---|
private class |
ControlledRealTimeReopenThread.HandleRefresh |
Modifier and Type | Field and Description |
---|---|
private boolean |
finish |
private ReferenceManager<T> |
manager |
private long |
refreshStartGen |
private java.util.concurrent.locks.Condition |
reopenCond |
private java.util.concurrent.locks.ReentrantLock |
reopenLock |
private long |
searchingGen |
private long |
targetMaxStaleNS |
private long |
targetMinStaleNS |
private long |
waitingGen |
private IndexWriter |
writer |
Constructor and Description |
---|
ControlledRealTimeReopenThread(IndexWriter writer,
ReferenceManager<T> manager,
double targetMaxStaleSec,
double targetMinStaleSec)
Create ControlledRealTimeReopenThread, to periodically
reopen the
ReferenceManager . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
long |
getSearchingGen()
Returns which
generation the current searcher is guaranteed to include. |
private void |
refreshDone() |
void |
run() |
void |
waitForGeneration(long targetGen)
Waits for the target generation to become visible in
the searcher.
|
boolean |
waitForGeneration(long targetGen,
int maxMS)
Waits for the target generation to become visible in
the searcher, up to a maximum specified milli-seconds.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
private final ReferenceManager<T> manager
private final long targetMaxStaleNS
private final long targetMinStaleNS
private final IndexWriter writer
private volatile boolean finish
private volatile long waitingGen
private volatile long searchingGen
private long refreshStartGen
private final java.util.concurrent.locks.ReentrantLock reopenLock
private final java.util.concurrent.locks.Condition reopenCond
public ControlledRealTimeReopenThread(IndexWriter writer, ReferenceManager<T> manager, double targetMaxStaleSec, double targetMinStaleSec)
ReferenceManager
.targetMaxStaleSec
- Maximum time until a new
reader must be opened; this sets the upper bound
on how slowly reopens may occur, when no
caller is waiting for a specific generation to
become visible.targetMinStaleSec
- Mininum time until a new
reader can be opened; this sets the lower bound
on how quickly reopens may occur, when a caller
is waiting for a specific generation to
become visible.private void refreshDone()
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public void waitForGeneration(long targetGen) throws java.lang.InterruptedException
ReferenceManager.maybeRefresh()
or until the ReferenceManager
is closed.targetGen
- the generation to wait forjava.lang.InterruptedException
public boolean waitForGeneration(long targetGen, int maxMS) throws java.lang.InterruptedException
ReferenceManager.maybeRefresh()
, the given waiting time has elapsed, or until
the ReferenceManager
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 formaxMS
- maximum milliseconds to wait, or -1 to wait indefinitelyjava.lang.InterruptedException
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public long getSearchingGen()
generation
the current searcher is guaranteed to include.