Skip to content

Commit

Permalink
HSEARCH-643 add a satefy net to BatchCoordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Sep 27, 2011
1 parent 620b49d commit 2bcde2e
Showing 1 changed file with 20 additions and 11 deletions.
Expand Up @@ -29,6 +29,7 @@

import org.hibernate.search.engine.spi.SearchFactoryImplementor;
import org.hibernate.search.exception.ErrorHandler;
import org.hibernate.search.exception.impl.SingleErrorContext;
import org.hibernate.search.util.logging.impl.Log;

import org.hibernate.CacheMode;
Expand Down Expand Up @@ -90,18 +91,26 @@ public BatchCoordinator(Set<Class<?>> rootEntities,
}

public void run() {
final BatchBackend backend = searchFactoryImplementor.makeBatchBackend( monitor );
try {
beforeBatch( backend ); // purgeAll and pre-optimize activities
doBatchWork( backend );
afterBatch( backend );
}
catch ( InterruptedException e ) {
log.interruptedBatchIndexing();
Thread.currentThread().interrupt();
}
finally {
monitor.indexingCompleted();
final BatchBackend backend = searchFactoryImplementor.makeBatchBackend( monitor );
try {
beforeBatch( backend ); // purgeAll and pre-optimize activities
doBatchWork( backend );
afterBatch( backend );
}
catch ( InterruptedException e ) {
log.interruptedBatchIndexing();
Thread.currentThread().interrupt();
}
finally {
monitor.indexingCompleted();
}
} catch (RuntimeException re) {
// each batch processing stage is already supposed to properly handle any kind
// of exception, still since this is possibly an async operation we need a safety
// for the unexpected exceptions
SingleErrorContext singleErrorContext = new SingleErrorContext( re );
errorHandler.handle( singleErrorContext );
}
}

Expand Down

0 comments on commit 2bcde2e

Please sign in to comment.