this.objectsLimit = objectsLimit;
}
@Override
public void run() {
ErrorHandler errorHandler = searchFactory.getErrorHandler();
try {
final BatchTransactionalContext btctx = new BatchTransactionalContext( sessionFactory, errorHandler );
//first start the consumers, then the producers (reverse order):
for ( int i = 0; i < luceneWorkerBuildingThreadNum; i++ ) {
//from entity to LuceneWork:
final EntityConsumerLuceneWorkProducer producer = new EntityConsumerLuceneWorkProducer(
fromEntityToAddwork, monitor,
sessionFactory, producerEndSignal, searchFactory,
cacheMode, backend, errorHandler
);
execDocBuilding.execute( new OptionallyWrapInJTATransaction( btctx, producer ) );
}
for ( int i = 0; i < objectLoadingThreadNum; i++ ) {
//from primary key to loaded entity:
final IdentifierConsumerEntityProducer producer = new IdentifierConsumerEntityProducer(
fromIdentifierListToEntities, fromEntityToAddwork, monitor,
sessionFactory, cacheMode, indexedType, idNameOfIndexedType, errorHandler
);
execFirstLoader.execute( new OptionallyWrapInJTATransaction( btctx, producer ) );
}
//from class definition to all primary keys:
final IdentifierProducer producer = new IdentifierProducer(
fromIdentifierListToEntities, sessionFactory,
objectLoadingBatchSize, indexedType, monitor,
objectsLimit, errorHandler, idFetchSize
);
execIdentifiersLoader.execute( new OptionallyWrapInJTATransaction( btctx, producer ) );
//shutdown all executors:
execIdentifiersLoader.shutdown();
execFirstLoader.shutdown();
execDocBuilding.shutdown();
try {
producerEndSignal.await(); //await for all work being sent to the backend
log.debugf( "All work for type %s has been produced", indexedType.getName() );
}
catch (InterruptedException e) {
//restore interruption signal:
Thread.currentThread().interrupt();
throw new SearchException( "Interrupted on batch Indexing; index will be left in unknown state!", e );
}
}
catch (RuntimeException re) {
//being this an async thread we want to make sure everything is somehow reported
errorHandler.handleException( log.massIndexerUnexpectedErrorMessage() , re );
}
finally {
endAllSignal.countDown();
}
}