if (maxMessagesPerPoll > 0 && total > maxMessagesPerPoll) {
LOG.debug("Limiting to maximum messages to poll " + maxMessagesPerPoll + " as there was " + total + " messages in this poll.");
total = maxMessagesPerPoll;
}
for (int index = 0; index < total && isRunAllowed(); index++) {
<BUG>MailExchange exchange = (MailExchange) exchanges.poll();
exchange.setProperty(Exchange.BATCH_INDEX, index);</BUG>
exchange.setProperty(Exchange.BATCH_SIZE, total);
exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1);
processExchange(exchange);

if (maxMessagesPerPoll > 0 && total > maxMessagesPerPoll) {
LOG.debug("Limiting to maximum messages to poll " + maxMessagesPerPoll + " as there was " + total + " messages in this poll.");
total = maxMessagesPerPoll;
}
for (int index = 0; index < total && isRunAllowed(); index++) {
Exchange exchange = (Exchange)exchanges.poll();
exchange.setProperty(Exchange.BATCH_INDEX, index);
exchange.setProperty(Exchange.BATCH_SIZE, total);
exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1);
processExchange(exchange);
