* will return as soon as the batch indexing is finished, it is only in case something goes
* wrong that this timeout will prevent endless hanging. An exception is thrown in case
* the batch indexing did not finish within this timeout.
*/
public void batchBuildIndex(String indexName, String[] batchCliArgs, long timeOut) throws Exception {
WriteableIndexerModel model = getIndexerModel();
try {
String lock = model.lockIndexer(indexName);
try {
IndexerDefinition index = model.getIndexer(indexName);
IndexerDefinitionBuilder builder = new IndexerDefinitionBuilder()
.startFrom(index)
.batchIndexingState(IndexerDefinition.BatchIndexingState.BUILD_REQUESTED)
.batchIndexCliArguments(batchCliArgs);
model.updateIndexer(builder.build(), lock);
} finally {
model.unlockIndexer(lock);
}
} catch (Exception e) {
throw new Exception("Error launching batch index build.", e);
}
try {
// Now wait until its finished
long tryUntil = System.currentTimeMillis() + timeOut;
while (System.currentTimeMillis() < tryUntil) {
Thread.sleep(100);
IndexerDefinition definition = model.getIndexer(indexName);
if (definition.getBatchIndexingState() == IndexerDefinition.BatchIndexingState.INACTIVE) {
Long amountFailed = null;
//Long amountFailed = definition.getLastBatchBuildInfo().getCounters().get(COUNTER_NUM_FAILED_RECORDS);
boolean successFlag = definition.getLastBatchBuildInfo().isFinishedSuccessful();