for (int index = 0; index < total && isBatchAllowed(); index++) {
// only loop if we are started (allowed to run)
DataHolder holder = ObjectHelper.cast(DataHolder.class, exchanges.poll());
EntityManager entityManager = holder.manager;
Exchange exchange = holder.exchange;
Object result = holder.result;
// add current index and total as properties
exchange.setProperty(Exchange.BATCH_INDEX, index);
exchange.setProperty(Exchange.BATCH_SIZE, total);
exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1);
// update pending number of exchanges
pendingExchanges = total - index - 1;
if (lockEntity(result, entityManager)) {
// Run the @PreConsumed callback
createPreDeleteHandler().deleteObject(entityManager, result, exchange);
// process the current exchange
LOG.debug("Processing exchange: {}", exchange);
getProcessor().process(exchange);
if (exchange.getException() != null) {
// if we failed then throw exception
throw exchange.getException();
}
// Run the @Consumed callback
getDeleteHandler().deleteObject(entityManager, result, exchange);
}