Search in sources :

Example 1 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple in project narayana by jbosstm.

the class XATerminatorImple method doRecover.

/**
 * <p>
 * Recovering /JCA section of object store.
 * The filtering functionality on xid or parentNodeName is not permitted and throws {@link NotSupportedException}.<br>
 * Expected to be called only with null parameters <code>doRecover(null, null)</code>
 *
 * @param xid has to be null
 * @param parentNodeName  has to be null
 * @return array of subordinate recovered xids
 * @throws XAException  if recovery operation fails for the XA protocol reason
 * @throws NotSupportedException  if not null params are passes as method parameters
 */
@Override
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException, NotSupportedException {
    if (xid != null || parentNodeName != null)
        throw new NotSupportedException("doRecover method works only with null arguments");
    Xid[] indoubt = null;
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        InputObjectState states = new InputObjectState();
        // only look in the JCA section of the object store
        if (recoveryStore.allObjUids(ServerTransaction.getType(), states) && (states.notempty())) {
            Stack<Transaction> values = new Stack<Transaction>();
            boolean finished = false;
            do {
                Uid uid = null;
                try {
                    uid = UidHelper.unpackFrom(states);
                } catch (IOException ex) {
                    jtsLogger.i18NLogger.info_fail_to_read_subordinate_uid(recoveryStore, states, ex);
                    finished = true;
                }
                if (uid.notEquals(Uid.nullUid())) {
                    Transaction tx = SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                    if (tx != null)
                        values.push(tx);
                } else
                    finished = true;
            } while (!finished);
            if (values.size() > 0) {
                int index = 0;
                indoubt = new Xid[values.size()];
                while (!values.empty()) {
                    TransactionImple id = (TransactionImple) values.pop();
                    indoubt[index] = id.baseXid();
                    index++;
                }
            }
        }
    } catch (Exception ex) {
        jtsLogger.i18NLogger.info_fail_to_dorecover(xid, parentNodeName, ex);
    }
    return indoubt;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple) IOException(java.io.IOException) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) IOException(java.io.IOException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException) Stack(java.util.Stack) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) ServerTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.coordinator.ServerTransaction) Transaction(javax.transaction.Transaction) SubordinateAtomicTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction) NotSupportedException(javax.transaction.NotSupportedException)

Example 2 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple in project narayana by jbosstm.

the class TransactionImporterImple method removeImportedTransaction.

/**
 * Remove the subordinate (imported) transaction.
 *
 * @param xid the global transaction.
 *
 * @throws XAException thrown if there are any errors.
 */
public void removeImportedTransaction(Xid xid) throws XAException {
    if (xid == null)
        throw new IllegalArgumentException();
    AtomicReference<SubordinateTransaction> remove = _transactions.remove(new SubordinateXidImple(xid));
    if (remove != null) {
        synchronized (remove) {
            com.arjuna.ats.internal.jta.transaction.jts.TransactionImple transactionImple = (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) remove.get();
            while (transactionImple == null) {
                try {
                    remove.wait();
                    transactionImple = (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) remove.get();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new XAException(XAException.XAER_RMFAIL);
                }
            }
            TransactionImple.removeTransaction(transactionImple);
        }
    }
}
Also used : SubordinateXidImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateXidImple) XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)

Example 3 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple in project narayana by jbosstm.

the class SubordinateTxUnitTest method testTransactionImple.

@Test
public void testTransactionImple() throws Exception {
    TransactionImple tx = new TransactionImple(new Uid());
    TransactionImple dummy = new TransactionImple(new Uid());
    tx.recordTransaction();
    assertFalse(tx.equals(dummy));
    assertTrue(tx.toString() != null);
    tx.recover();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple) Test(org.junit.Test)

Example 4 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple in project narayana by jbosstm.

the class TransactionImpleUnitTest method test.

@Test
public void test() throws Exception {
    TransactionImple tx = new TransactionImple(0);
    tx.recordTransaction();
    assertFalse(tx.equals(null));
    assertTrue(tx.equals(tx));
    assertFalse(tx.equals(new TransactionImple(0)));
    assertTrue(tx.toString() != null);
    assertTrue(tx.baseXid() != null);
    tx.recover();
    assertTrue(tx.activated());
}
Also used : TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple) Test(org.junit.Test)

Example 5 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple 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

TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple)5 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)3 Uid (com.arjuna.ats.arjuna.common.Uid)2 SubordinateXidImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateXidImple)2 XAException (javax.transaction.xa.XAException)2 Test (org.junit.Test)2 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 SubordinateAtomicTransaction (com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction)1 ServerTransaction (com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.coordinator.ServerTransaction)1 UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)1 IOException (java.io.IOException)1 Stack (java.util.Stack)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 HeuristicCommitException (javax.transaction.HeuristicCommitException)1 HeuristicMixedException (javax.transaction.HeuristicMixedException)1 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 NotSupportedException (javax.transaction.NotSupportedException)1 RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1