}
@Override
public int doLogic() throws Exception {
final PerfRunData runData = getRunData();
// Get initial reader
IndexWriter w = runData.getIndexWriter();
if (w == null) {
throw new RuntimeException("please open the writer before invoking NearRealtimeReader");
}
if (runData.getIndexReader() != null) {
throw new RuntimeException("please close the existing reader before invoking NearRealtimeReader");
}
long t = System.currentTimeMillis();
IndexReader r = w.getReader();
runData.setIndexReader(r);
// Transfer our reference to runData
r.decRef();
// TODO: gather basic metrics for reporting -- eg mean,
// stddev, min/max reopen latencies
// Parent sequence sets stopNow
int reopenCount = 0;
while(!stopNow) {
long waitForMsec = (long) (pauseMSec - (System.currentTimeMillis() - t));
if (waitForMsec > 0) {
Thread.sleep(waitForMsec);
}
t = System.currentTimeMillis();
final IndexReader newReader = r.reopen();
if (r != newReader) {
// TODO: somehow we need to enable warming, here
runData.setIndexReader(newReader);
// Transfer our reference to runData
newReader.decRef();
r = newReader;
reopenCount++;
}