use of nl.nn.adapterframework.core.HasTransactionAttribute in project iaf by ibissource.
the class TransactionAttributePipeProcessor method processPipe.
public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
PipeRunResult pipeRunResult;
int txOption;
int txTimeout = 0;
if (pipe instanceof HasTransactionAttribute) {
HasTransactionAttribute taPipe = (HasTransactionAttribute) pipe;
txOption = taPipe.getTransactionAttributeNum();
txTimeout = taPipe.getTransactionTimeout();
} else {
txOption = TransactionDefinition.PROPAGATION_SUPPORTS;
}
// TransactionStatus txStatus = txManager.getTransaction(SpringTxManagerProxy.getTransactionDefinition(txOption,txTimeout));
IbisTransaction itx = new IbisTransaction(txManager, SpringTxManagerProxy.getTransactionDefinition(txOption, txTimeout), "pipe [" + pipe.getName() + "]");
TransactionStatus txStatus = itx.getStatus();
try {
TimeoutGuard tg = new TimeoutGuard("pipeline of adapter [" + pipeLine.getOwner().getName() + "] running pipe [" + pipe.getName() + "]");
Throwable tCaught = null;
try {
tg.activateGuard(txTimeout);
pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
} catch (Throwable t) {
tCaught = t;
throw tCaught;
} finally {
if (tg.cancel()) {
if (tCaught == null) {
throw new PipeRunException(pipe, tg.getDescription() + " was interrupted");
} else {
log.warn("Thread interrupted, but propagating other caught exception of type [" + ClassUtils.nameOf(tCaught) + "]");
}
}
}
} catch (Throwable t) {
log.debug("setting RollBackOnly for pipe [" + pipe.getName() + "] after catching exception");
txStatus.setRollbackOnly();
if (t instanceof Error) {
throw (Error) t;
} else if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else if (t instanceof PipeRunException) {
throw (PipeRunException) t;
} else {
throw new PipeRunException(pipe, "Caught unknown checked exception", t);
}
} finally {
// txManager.commit(txStatus);
itx.commit();
}
return pipeRunResult;
}
Aggregations