public void run() {
// repeatedly try to process documents while some still
// remain
while (docIter.hasNext()) {
TemporalDocument doc = docIter.next();
int docNumber = count.incrementAndGet();
long docTime = doc.timeStamp();
// special case for first document
if (docNumber == 1) {
curSSpaceStartTime.set(docTime);
startBarrier.set(true);
}
// Spin until the Thread with the first document
// sets the initial starting document time. Note
// that we spin here instead of block, because this
// is expected that another thread will immediately
// set this and so it will be a quick no-op
while (startBarrier.get() == false)
;
// Check whether the time for this document would
// exceed the maximum time span for any TRI
// partition. Loop to ensure that if this thread
// does loop and another thread has an earlier time
// that would cause this thread's time span to
// exceeds the other thread's time period, then this
// thread will block and loop again.
while (!timeSpan.insideRange(
curSSpaceStartTime.get(), docTime)) {
try {
// notify the barrier that this Thread is
// now processing a document in the next
// time span and so the serialization thread
// should write the .sspace to disk. In
// addition, enqueue the time for this
// document so the serialization thread can
// reset the correct s-sspace start time
futureStartTimes.offer(docTime);
exceededTimeSpanBarrier.await();
} catch (InterruptedException ex) {
return;
} catch (BrokenBarrierException ex) {
return;
}
}
try {
fdTri.processDocument(doc.reader());
} catch (IOException ioe) {
// rethrow
throw new IOError(ioe);
}
LOGGER.fine("parsed document #" + docNumber);