_logger.info("(Starting harvest thread for " + _sSourceType + ")");
}
while (!_sources.isEmpty()) {
LinkedList<SourcePojo> sourceBatch = SourceUtils.getDistributedSourceList(_sources, _sSourceType, false);
while (!sourceBatch.isEmpty()) {
SourcePojo source = sourceBatch.pop();
SourceHarvesterRunnable sourceRunner = new SourceHarvesterRunnable(source);
boolean bSubmittedTask = false;
for (int i = 0; (i < 5) && !bSubmittedTask; ++i) {
try {
bex.submitTask(sourceRunner, true);
bSubmittedTask = true;
}
catch (Exception e) {
try {
_logger.info("(Thread failure for " + _sSourceType + ", can probably recover)");
Thread.sleep(1000); // wait a second
} catch (InterruptedException e1) { }
}
}
if (_bStopHarvest) { // Just need to update the status of all remaining source
_logger.info("(Shutdown, cleaning up " + sourceBatch.size() + " queued sources for " + _sSourceType + ")");
for (SourcePojo sourceToDelete: sourceBatch) {
if ((null != source.getHarvestStatus()) &&
(null != source.getHarvestStatus().getHarvest_status()) &&
(HarvestEnum.in_progress != source.getHarvestStatus().getHarvest_status()))
{
// (If I can revert to old status)
SourceUtils.updateHarvestStatus(sourceToDelete, source.getHarvestStatus().getHarvest_status(), null, 0, null);
}
else {
SourceUtils.updateHarvestStatus(sourceToDelete, HarvestEnum.success, null, 0, null);
}
}