final BlockingQueue<?> queue = endpoint.getQueue();
while (queue != null && isRunAllowed()) {
final Exchange exchange = this.getEndpoint().createExchange();
TransactionContext transactionCtx = null;
if (endpoint.getConfiguration().isTransacted()) {
// Get and begin transaction if exist
transactionCtx = endpoint.getHazelcastInstance().newTransactionContext();
if (transactionCtx != null) {
log.trace("Begin transaction: {}", transactionCtx.getTxnId());
transactionCtx.beginTransaction();
}
}
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 (transactionCtx != null) {
transactionCtx.rollbackTransaction();
}
getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
}
} catch (Exception e) {
LOG.error("Hzlq Exception caught: " + e, e);
// Rollback
if (transactionCtx != null) {
log.trace("Rollback transaction: {}", transactionCtx.getTxnId());
transactionCtx.rollbackTransaction();
}
}
}
// It's OK, I commit
if (exchange.getException() == null && transactionCtx != null) {
log.trace("Commit transaction: {}", transactionCtx.getTxnId());
transactionCtx.commitTransaction();
}
} catch (InterruptedException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Hzlq Consumer Interrupted: " + e, e);
}
continue;
} catch (Throwable e) {
// Rollback
if (transactionCtx != null) {
log.trace("Rollback transaction: {}", transactionCtx.getTxnId());
transactionCtx.rollbackTransaction();
}
getExceptionHandler().handleException("Error processing exchange", exchange, e);
}
}
}