Search in sources :

Example 1 with HasTransactionAttribute

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;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) IbisTransaction(nl.nn.adapterframework.core.IbisTransaction) HasTransactionAttribute(nl.nn.adapterframework.core.HasTransactionAttribute) PipeRunException(nl.nn.adapterframework.core.PipeRunException) TransactionStatus(org.springframework.transaction.TransactionStatus) TimeoutGuard(nl.nn.adapterframework.task.TimeoutGuard)

Aggregations

HasTransactionAttribute (nl.nn.adapterframework.core.HasTransactionAttribute)1 IbisTransaction (nl.nn.adapterframework.core.IbisTransaction)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 TimeoutGuard (nl.nn.adapterframework.task.TimeoutGuard)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1