Search in sources :

Example 1 with TransactionImportResult

use of org.jboss.tm.TransactionImportResult in project narayana by jbosstm.

the class TransactionImporterImple method addImportedTransaction.

/**
 * This can be used for newly imported transactions or recovered ones.
 *
 * @param recoveredTransaction If this is recovery
 * @param mapKey
 * @param xid if this is import
 * @param timeout
 * @return
 */
private TransactionImportResult addImportedTransaction(TransactionImple recoveredTransaction, Xid mapKey, Xid xid, int timeout) {
    boolean isNew = false;
    SubordinateXidImple importedXid = new SubordinateXidImple(mapKey);
    // We need to store the imported transaction in a volatile field holder so that it can be shared between threads
    AtomicReference<TransactionImple> holder = new AtomicReference<>();
    AtomicReference<TransactionImple> existing;
    if ((existing = _transactions.putIfAbsent(importedXid, holder)) != null) {
        holder = existing;
    }
    TransactionImple txn = holder.get();
    // Should only be called by the recovery system - this will replace the Transaction with one from disk
    if (recoveredTransaction != null) {
        synchronized (holder) {
            // now it's safe to add the imported transaction to the holder
            recoveredTransaction.recordTransaction();
            txn = recoveredTransaction;
            holder.set(txn);
            holder.notifyAll();
        }
    }
    if (txn == null) {
        // a volatile so can be concurrently accessed by multiple threads
        synchronized (holder) {
            txn = holder.get();
            if (txn == null) {
                txn = new TransactionImple(timeout, xid);
                holder.set(txn);
                holder.notifyAll();
                isNew = true;
            }
        }
    }
    return new TransactionImportResult(txn, isNew);
}
Also used : TransactionImportResult(org.jboss.tm.TransactionImportResult) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 2 with TransactionImportResult

use of org.jboss.tm.TransactionImportResult in project narayana by jbosstm.

the class ServerImpl method locateOrImportTransactionThenResumeIt.

@Override
public Xid locateOrImportTransactionThenResumeIt(int remainingTimeout, Xid toResume) throws XAException, IllegalStateException, SystemException, IOException {
    JBossXATerminator xaTerminator = transactionManagerService.getJbossXATerminator();
    if (!ExtendedJBossXATerminator.class.isInstance(xaTerminator)) {
        System.out.printf("ExtendedJBossXATerminator: FAIL not an instance");
        return null;
    }
    ExtendedJBossXATerminator extendedJBossXATerminator = (ExtendedJBossXATerminator) xaTerminator;
    boolean subordinateCreated = false;
    Transaction transaction = extendedJBossXATerminator.getTransaction(toResume);
    if (transaction == null) {
        TransactionImportResult transactionImportResult = extendedJBossXATerminator.importTransaction(toResume, remainingTimeout);
        subordinateCreated = transactionImportResult.isNewImportedTransaction();
        transaction = transactionImportResult.getTransaction();
    }
    transactionManagerService.getTransactionManager().resume(transaction);
    return subordinateCreated ? ((com.arjuna.ats.jta.transaction.Transaction) transaction).getTxId() : null;
}
Also used : ExtendedJBossXATerminator(org.jboss.tm.ExtendedJBossXATerminator) JBossXATerminator(org.jboss.tm.JBossXATerminator) TransactionImportResult(org.jboss.tm.TransactionImportResult) Transaction(javax.transaction.Transaction) ExtendedJBossXATerminator(org.jboss.tm.ExtendedJBossXATerminator)

Example 3 with TransactionImportResult

use of org.jboss.tm.TransactionImportResult in project narayana by jbosstm.

the class TransactionImporterImple method addImportedTransaction.

/**
 * This can be used for newly imported transactions or recovered ones.
 *
 * @param recoveredTransaction If this is recovery
 * @param xid if this is import
 * @param timeout
 * @return
 */
private TransactionImportResult addImportedTransaction(TransactionImple recoveredTransaction, Xid mapKey, Xid xid, int timeout) {
    boolean isNew = false;
    SubordinateXidImple importedXid = new SubordinateXidImple(mapKey);
    // We need to store the imported transaction in a volatile field holder so that it can be shared between threads
    AtomicReference<SubordinateTransaction> holder = new AtomicReference<>();
    AtomicReference<SubordinateTransaction> existing;
    if ((existing = _transactions.putIfAbsent(importedXid, holder)) != null) {
        holder = existing;
    }
    SubordinateTransaction txn = holder.get();
    // Should only be called by the recovery system - this will replace the Transaction with one from disk
    if (recoveredTransaction != null) {
        synchronized (holder) {
            // now it's safe to add the imported transaction to the holder
            recoveredTransaction.recordTransaction();
            txn = recoveredTransaction;
            holder.set(txn);
            holder.notifyAll();
        }
    }
    if (txn == null) {
        // a volatile so can be concurrently accessed by multiple threads
        synchronized (holder) {
            txn = holder.get();
            if (txn == null) {
                txn = new TransactionImple(timeout, xid);
                holder.set(txn);
                holder.notifyAll();
                isNew = true;
            }
        }
    }
    return new TransactionImportResult(txn, isNew);
}
Also used : SubordinateXidImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateXidImple) TransactionImportResult(org.jboss.tm.TransactionImportResult) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple) AtomicReference(java.util.concurrent.atomic.AtomicReference) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)

Aggregations

TransactionImportResult (org.jboss.tm.TransactionImportResult)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)1 SubordinateXidImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateXidImple)1 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple)1 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple)1 Transaction (javax.transaction.Transaction)1 ExtendedJBossXATerminator (org.jboss.tm.ExtendedJBossXATerminator)1 JBossXATerminator (org.jboss.tm.JBossXATerminator)1