Search in sources :

Example 1 with ROLLING_BACK

use of org.osgi.service.transaction.control.TransactionStatus.ROLLING_BACK in project aries by apache.

the class TransactionContextImpl method finish.

@Override
public void finish() {
    beforeCompletion(() -> setRollbackOnly());
    TransactionStatus status;
    if (getRollbackOnly()) {
        vanillaRollback();
        status = ROLLED_BACK;
    } else {
        tranStatus.set(COMMITTING);
        List<LocalResource> committed = new ArrayList<>(resources.size());
        List<LocalResource> rolledback = new ArrayList<>(0);
        resources.stream().forEach(lr -> {
            try {
                if (getRollbackOnly()) {
                    lr.rollback();
                    rolledback.add(lr);
                } else {
                    lr.commit();
                    committed.add(lr);
                }
            } catch (Exception e) {
                firstUnexpectedException.compareAndSet(null, e);
                if (committed.isEmpty()) {
                    tranStatus.set(ROLLING_BACK);
                }
                rolledback.add(lr);
            }
        });
        status = tranStatus.updateAndGet(ts -> ts == ROLLING_BACK ? ROLLED_BACK : COMMITTED);
    }
    afterCompletion(status);
}
Also used : ACTIVE(org.osgi.service.transaction.control.TransactionStatus.ACTIVE) COMMITTING(org.osgi.service.transaction.control.TransactionStatus.COMMITTING) ROLLED_BACK(org.osgi.service.transaction.control.TransactionStatus.ROLLED_BACK) AbstractTransactionContextImpl(org.apache.aries.tx.control.service.common.impl.AbstractTransactionContextImpl) MARKED_ROLLBACK(org.osgi.service.transaction.control.TransactionStatus.MARKED_ROLLBACK) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ROLLING_BACK(org.osgi.service.transaction.control.TransactionStatus.ROLLING_BACK) Consumer(java.util.function.Consumer) XAResource(javax.transaction.xa.XAResource) COMMITTED(org.osgi.service.transaction.control.TransactionStatus.COMMITTED) List(java.util.List) LocalResource(org.osgi.service.transaction.control.LocalResource) TransactionContext(org.osgi.service.transaction.control.TransactionContext) TransactionStatus(org.osgi.service.transaction.control.TransactionStatus) ArrayList(java.util.ArrayList) TransactionStatus(org.osgi.service.transaction.control.TransactionStatus) LocalResource(org.osgi.service.transaction.control.LocalResource)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 XAResource (javax.transaction.xa.XAResource)1 AbstractTransactionContextImpl (org.apache.aries.tx.control.service.common.impl.AbstractTransactionContextImpl)1 LocalResource (org.osgi.service.transaction.control.LocalResource)1 TransactionContext (org.osgi.service.transaction.control.TransactionContext)1 TransactionStatus (org.osgi.service.transaction.control.TransactionStatus)1 ACTIVE (org.osgi.service.transaction.control.TransactionStatus.ACTIVE)1 COMMITTED (org.osgi.service.transaction.control.TransactionStatus.COMMITTED)1 COMMITTING (org.osgi.service.transaction.control.TransactionStatus.COMMITTING)1 MARKED_ROLLBACK (org.osgi.service.transaction.control.TransactionStatus.MARKED_ROLLBACK)1 ROLLED_BACK (org.osgi.service.transaction.control.TransactionStatus.ROLLED_BACK)1 ROLLING_BACK (org.osgi.service.transaction.control.TransactionStatus.ROLLING_BACK)1