Search in sources :

Example 6 with TransactionImple

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

the class XATerminatorImple method doRecover.

/**
 * Return a list of indoubt transactions. This may include those
 * transactions that are currently in-flight and running 2PC and do not need
 * recovery invoked on them.
 *
 * @param nodeName
 * 				Only recover transactions for this node (unless set to NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES)
 * @throws XAException
 *             thrown if any error occurs.
 * @return a list of potentially indoubt transactions or <code>null</code>.
 */
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException {
    /*
         * Requires going through the objectstore for the states of imported
         * transactions. Our own crash recovery takes care of transactions
         * imported via CORBA, Web Services etc.
         */
    Xid[] indoubt = null;
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        InputObjectState states = new InputObjectState();
        if (recoveryStore.allObjUids(SubordinateAtomicAction.getType(), states) && (states.notempty())) {
            Stack<Xid> values = new Stack<Xid>();
            boolean finished = false;
            do {
                Uid uid = null;
                try {
                    uid = UidHelper.unpackFrom(states);
                } catch (IOException ex) {
                    ex.printStackTrace();
                    finished = true;
                }
                if (uid.notEquals(Uid.nullUid())) {
                    if (parentNodeName != null) {
                        SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
                        XidImple loadedXid = (XidImple) saa.getXid();
                        if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
                            String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
                            if ((loadedXidSubordinateNodeName == null && loadedXidSubordinateNodeName == TxControl.getXANodeName()) || loadedXidSubordinateNodeName.equals(TxControl.getXANodeName())) {
                                if (parentNodeName.equals(saa.getParentNodeName())) {
                                    if (jtaLogger.logger.isDebugEnabled()) {
                                        jtaLogger.logger.debug("Found record for " + saa);
                                    }
                                    // TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                                    values.push(loadedXid);
                                }
                            }
                        }
                    } else if (xid == null) {
                        TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                        if (tx != null)
                            values.push(tx.baseXid());
                    } else {
                        SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
                        XidImple loadedXid = (XidImple) saa.getXid();
                        if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
                            String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
                            if (XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID()).equals(loadedXidSubordinateNodeName)) {
                                if (Arrays.equals(loadedXid.getGlobalTransactionId(), xid.getGlobalTransactionId())) {
                                    if (jtaLogger.logger.isDebugEnabled()) {
                                        jtaLogger.logger.debug("Found record for " + saa);
                                    }
                                    TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
                                    values.push(loadedXid);
                                }
                            }
                        }
                    }
                } else
                    finished = true;
            } while (!finished);
            if (values.size() > 0) {
                int index = 0;
                indoubt = new Xid[values.size()];
                while (!values.empty()) {
                    indoubt[index] = values.pop();
                    index++;
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return indoubt;
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple) IOException(java.io.IOException) SubordinateAtomicAction(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction) 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) 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)

Example 7 with TransactionImple

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

the class TransactionImporterImple method getInflightXids.

public Set<Xid> getInflightXids(String parentNodeName) {
    Iterator<AtomicReference<TransactionImple>> iterator = _transactions.values().iterator();
    Set<Xid> toReturn = new HashSet<Xid>();
    while (iterator.hasNext()) {
        AtomicReference<TransactionImple> holder = iterator.next();
        TransactionImple imported = holder.get();
        if (imported != null && imported.getParentNodeName().equals(parentNodeName)) {
            toReturn.add(imported.baseXid());
        }
    }
    return toReturn;
}
Also used : Xid(javax.transaction.xa.Xid) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet)

Example 8 with TransactionImple

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

the class TransactionImporterImple method removeImportedTransaction.

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

Example 9 with TransactionImple

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

the class XARecoveryModuleUnitTest method testRecover.

@Test
public void testRecover() throws Exception {
    ArrayList<String> r = new ArrayList<String>();
    TransactionImple tx = new TransactionImple(0);
    assertTrue(tx.enlistResource(new RecoveryXAResource()));
    assertEquals(tx.doPrepare(), TwoPhaseOutcome.PREPARE_OK);
    r.add("com.hp.mwtests.ts.jta.recovery.DummyXARecoveryResource");
    jtaPropertyManager.getJTAEnvironmentBean().setXaResourceRecoveryClassNames(r);
    XARecoveryModule xarm = new XARecoveryModule();
    assertNull(xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(), null)));
    for (int i = 0; i < 11; i++) {
        xarm.periodicWorkFirstPass();
        xarm.periodicWorkSecondPass();
    }
    assertTrue(xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(new Uid()), null)) == null);
    assertNull(xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(), null)));
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple) ArrayList(java.util.ArrayList) RecoveryXAResource(com.hp.mwtests.ts.jta.common.RecoveryXAResource) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Aggregations

TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple)9 Uid (com.arjuna.ats.arjuna.common.Uid)5 XAException (javax.transaction.xa.XAException)5 XidImple (com.arjuna.ats.jta.xa.XidImple)4 Xid (javax.transaction.xa.Xid)4 Test (org.junit.Test)4 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 XATerminator (javax.resource.spi.XATerminator)2 SystemException (javax.transaction.SystemException)2 Transaction (javax.transaction.Transaction)2 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)1 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)1 XATerminatorExtensions (com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions)1 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)1 UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)1 RecoveryXAResource (com.hp.mwtests.ts.jta.common.RecoveryXAResource)1 IOException (java.io.IOException)1