final BlockingQueue<?> queue = endpoint.getQueue();
while (queue != null && isRunAllowed()) {
final Exchange exchange = this.getEndpoint().createExchange();
Transaction transaction = null;
if (endpoint.getConfiguration().isTransacted()) {
// Get and begin transaction if exist
transaction = endpoint.getHazelcastInstance().getTransaction();
if (transaction != null && transaction.getStatus() == Transaction.TXN_STATUS_NO_TXN) {
log.trace("Begin transaction: {}", transaction);
transaction.begin();
}
}
try {
final Object body = queue.poll(endpoint.getConfiguration().getPollInterval(), TimeUnit.MILLISECONDS);
if (body != null) {
if (body instanceof DefaultExchangeHolder) {
DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) body);
} else {
exchange.getIn().setBody(body);
}
try {
// process using the asynchronous routing engine
processor.process(exchange, new AsyncCallback() {
public void done(boolean asyncDone) {
// noop
}
});
if (exchange.getException() != null) {
// Rollback
if (transaction != null) {
transaction.rollback();
}
getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
}
} catch (Exception e) {
LOG.error("Hzlq Exception caught: " + e, e);
// Rollback
if (transaction != null) {
log.trace("Rollback transaction: {}", transaction);
transaction.rollback();
}
}
}
// It's OK, I commit
if (exchange.getException() == null && transaction != null && transaction.getStatus() == Transaction.TXN_STATUS_ACTIVE) {
log.trace("Commit transaction: {}", transaction);
transaction.commit();
}
} catch (InterruptedException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Hzlq Consumer Interrupted: " + e, e);
}
continue;
} catch (Throwable e) {
// Rollback
if (transaction != null) {
log.trace("Rollback transaction: {}", transaction);
transaction.rollback();
}
getExceptionHandler().handleException("Error processing exchange", exchange, e);
}
}
}