Search in sources :

Example 1 with Status

use of org.omg.CosTransactions.Status in project narayana by jbosstm.

the class TransactionCache method getOriginalStatus.

/**
 * Get the status of a transaction as it is in the original process
 * (so type is not needed)
 * NoTransaction means the original process has gone
 */
public static Status getOriginalStatus(Uid actionUid, String theType) throws SystemException {
    Status theStatus = Status.StatusUnknown;
    TransactionCacheItem cacheItem = get(actionUid, theType);
    if (cacheItem != null) {
        synchronized (cacheItem) {
            RecoveringTransaction theTransaction = cacheItem.freshTransaction();
            if (theTransaction != null) {
                if (jtsLogger.logger.isDebugEnabled()) {
                    jtsLogger.logger.debug("asking the tran for original status");
                }
                theStatus = theTransaction.getOriginalStatus();
            } else {
                if (jtsLogger.logger.isDebugEnabled()) {
                    jtsLogger.logger.debug("no transaction in cache so not asking for original status");
                }
            }
        }
    }
    return theStatus;
}
Also used : Status(org.omg.CosTransactions.Status)

Example 2 with Status

use of org.omg.CosTransactions.Status in project narayana by jbosstm.

the class TransactionRecoveryModule method recoverTransaction.

private void recoverTransaction(Uid tranUid) // protected void recoverTransaction (Uid tranUid)
{
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("TransactionRecoveryModule.recoverTransaction(" + tranUid + ")");
    }
    Status currentStatus = Status.StatusUnknown;
    CachedRecoveredTransaction cachedRecoveredTransaction = new CachedRecoveredTransaction(tranUid, _transactionType);
    currentStatus = cachedRecoveredTransaction.get_status();
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("Activated transaction " + tranUid + " status = " + Utility.stringStatus(currentStatus));
    }
    // but first check that the original transaction isn't in mid-flight
    if (cachedRecoveredTransaction.originalBusy()) {
        if (jtsLogger.logger.isDebugEnabled()) {
            jtsLogger.logger.debug("Transaction " + tranUid + " still busy");
        }
        return;
    }
    cachedRecoveredTransaction.replayPhase2();
    cachedRecoveredTransaction = null;
}
Also used : StateStatus(com.arjuna.ats.arjuna.objectstore.StateStatus) Status(org.omg.CosTransactions.Status)

Example 3 with Status

use of org.omg.CosTransactions.Status in project narayana by jbosstm.

the class RecoveredServerTransaction method replayPhase2.

/**
 * Causes phase 2 of the commit protocol to be replayed.
 */
public void replayPhase2() {
    _recoveryStatus = RecoveryStatus.REPLAYING;
    Status theStatus = get_status();
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("RecoveredServerTransaction.replayPhase2(" + get_uid() + ") - status = " + Utility.stringStatus(theStatus));
    }
    if (theStatus == Status.StatusPrepared) {
        /*
             * We need to get the status from the our parent transaction in the
             * interposition hierarchy.
             */
        theStatus = getStatusFromParent();
        if (jtsLogger.logger.isDebugEnabled()) {
            jtsLogger.logger.debug("RecoveredServerTransaction.replayPhase2(" + get_uid() + ") -" + " status after contacting parent = " + Utility.stringStatus(theStatus));
        }
    }
    if ((theStatus == Status.StatusCommitting) || (theStatus == Status.StatusCommitted)) {
        phase2Commit(_reportHeuristics);
        _recoveryStatus = RecoveryStatus.REPLAYED;
        _txStatus = Status.StatusCommitted;
    } else if ((theStatus == Status.StatusRolledBack) || (theStatus == Status.StatusRollingBack) || (theStatus == Status.StatusMarkedRollback) || (theStatus == Status.StatusNoTransaction)) {
        phase2Abort(_reportHeuristics);
        _recoveryStatus = RecoveryStatus.REPLAYED;
        _txStatus = Status.StatusRolledBack;
    } else if (theStatus == Status.StatusUnknown) {
        jtsLogger.i18NLogger.info_recovery_transactions_RecoveredServerTransaction_6(get_uid());
        _recoveryStatus = RecoveryStatus.REPLAY_FAILED;
    } else {
        jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_7(Utility.stringStatus(theStatus));
        _recoveryStatus = RecoveryStatus.REPLAY_FAILED;
    }
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("RecoveredServerTransaction.replayPhase2: (" + get_uid() + ") finished");
    }
}
Also used : Status(org.omg.CosTransactions.Status) StateStatus(com.arjuna.ats.arjuna.objectstore.StateStatus)

Example 4 with Status

use of org.omg.CosTransactions.Status in project narayana by jbosstm.

the class HeuristicTest method test.

@Test
public void test() throws Exception {
    boolean shouldCommit = true;
    boolean heuristicPrepare = false;
    Coordinator coord = null;
    ORB myORB = null;
    RootOA myOA = null;
    heuristic hImpl = null;
    try {
        myORB = ORB.getInstance("test");
        myOA = OA.getRootOA(myORB);
        myORB.initORB(new String[] {}, null);
        myOA.initOA();
        ORBManager.setORB(myORB);
        ORBManager.setPOA(myOA);
        Current current = OTSManager.get_current();
        hImpl = new heuristic(heuristicPrepare);
        Resource heuristicObject = hImpl.getReference();
        AtomicResource aImpl = new AtomicResource(shouldCommit);
        Resource atomicObject = aImpl.getReference();
        System.out.println("beginning top-level transaction.");
        current.begin();
        Control myControl = current.get_control();
        assertNotNull(myControl);
        System.out.println("getting coordinator");
        coord = myControl.get_coordinator();
        myControl = null;
        System.out.println("registering resources.");
        try {
            coord.register_resource(heuristicObject);
            coord.register_resource(atomicObject);
        } catch (Exception ex) {
            fail("Failed to register resources: " + ex);
            ex.printStackTrace(System.err);
        }
        System.out.println("committing top-level transaction.");
        current.commit(true);
    } catch (TRANSACTION_ROLLEDBACK e1) {
        System.out.println("\nTransaction RolledBack exception");
    } catch (HeuristicMixed e2) {
        System.out.println("\nTransaction HeuristicMixed exception");
    } catch (HeuristicHazard e3) {
        System.out.println("\nTransaction HeuristicHazard exception");
    } catch (Exception e4) {
        fail("Caught unexpected exception: " + e4);
        e4.printStackTrace(System.err);
    }
    System.out.println("Trying to determing final transaction outcome.");
    org.omg.CosTransactions.Status status = Status.StatusUnknown;
    try {
        if (coord != null) {
            status = coord.get_status();
            coord = null;
        } else {
            fail("\nCould not determine action status.");
        }
    } catch (SystemException ex1) {
    // assume invalid reference - tx may have been garbage collected
    } catch (Exception e5) {
        fail("Caught unexpected exception:" + e5);
        e5.printStackTrace(System.err);
    }
    System.out.println("\nFinal action status: " + Utility.stringStatus(status));
    System.out.println("Test completed successfully.");
    ResourceTrace trace = hImpl.getTrace();
    if ((!heuristicPrepare) && (shouldCommit) && (trace.getTrace() == ResourceTrace.ResourceTracePrepareCommitHeurisiticRollbackForget)) {
    // assertSuccess();
    } else {
        if ((!heuristicPrepare) && (!shouldCommit) && (trace.getTrace() == ResourceTrace.ResourceTracePrepareRollback)) {
        // assertSuccess();
        } else {
            if ((heuristicPrepare) && (shouldCommit) && (trace.getTrace() == ResourceTrace.ResourceTracePrepareHeuristicHazardForget)) {
            // assertSuccess();
            } else {
                fail();
            }
        }
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : AtomicResource(com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource) Resource(org.omg.CosTransactions.Resource) RootOA(com.arjuna.orbportability.RootOA) com.hp.mwtests.ts.jts.orbspecific.resources.heuristic(com.hp.mwtests.ts.jts.orbspecific.resources.heuristic) AtomicResource(com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) ResourceTrace(com.hp.mwtests.ts.jts.utils.ResourceTrace) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) Status(org.omg.CosTransactions.Status) Current(org.omg.CosTransactions.Current) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 5 with Status

use of org.omg.CosTransactions.Status in project narayana by jbosstm.

the class RecoveredServerTransaction method replayPhase2.

/**
 * Causes phase 2 of the commit protocol to be replayed.
 */
public void replayPhase2() {
    _recoveryStatus = RecoveryStatus.REPLAYING;
    Status theStatus = get_status();
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("RecoveredServerTransaction.replayPhase2(" + get_uid() + ") - status = " + Utility.stringStatus(theStatus));
    }
    if (theStatus == Status.StatusPrepared) {
        /*
             * We need to get the status from the our parent transaction in the
             * interposition hierarchy.
             */
        theStatus = getStatusFromParent();
        if (jtsLogger.logger.isDebugEnabled()) {
            jtsLogger.logger.debug("RecoveredServerTransaction.replayPhase2(" + get_uid() + ") -" + " status after contacting parent = " + Utility.stringStatus(theStatus));
        }
    }
    if ((theStatus == Status.StatusCommitting) || (theStatus == Status.StatusCommitted)) {
        phase2Commit(_reportHeuristics);
        _recoveryStatus = RecoveryStatus.REPLAYED;
        _txStatus = Status.StatusCommitted;
    } else if ((theStatus == Status.StatusRolledBack) || (theStatus == Status.StatusRollingBack) || (theStatus == Status.StatusMarkedRollback) || (theStatus == Status.StatusNoTransaction)) {
        phase2Abort(_reportHeuristics);
        _recoveryStatus = RecoveryStatus.REPLAYED;
        _txStatus = Status.StatusRolledBack;
    } else if (theStatus == Status.StatusUnknown) {
        jtsLogger.i18NLogger.info_recovery_transactions_RecoveredServerTransaction_6(get_uid());
        _recoveryStatus = RecoveryStatus.REPLAY_FAILED;
    } else {
        jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_7(Utility.stringStatus(theStatus));
        _recoveryStatus = RecoveryStatus.REPLAY_FAILED;
    }
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("RecoveredServerTransaction.replayPhase2: (" + get_uid() + ") finished");
    }
}
Also used : Status(org.omg.CosTransactions.Status) StateStatus(com.arjuna.ats.arjuna.objectstore.StateStatus) RecoveryStatus(com.arjuna.ats.internal.jts.recovery.transactions.RecoveryStatus)

Aggregations

Status (org.omg.CosTransactions.Status)18 SystemException (org.omg.CORBA.SystemException)9 StateStatus (com.arjuna.ats.arjuna.objectstore.StateStatus)8 Test (org.junit.Test)5 Control (org.omg.CosTransactions.Control)5 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)4 ORB (com.arjuna.orbportability.ORB)4 RootOA (com.arjuna.orbportability.RootOA)4 Coordinator (org.omg.CosTransactions.Coordinator)4 Inactive (org.omg.CosTransactions.Inactive)4 NotPrepared (org.omg.CosTransactions.NotPrepared)4 OBJECT_NOT_EXIST (org.omg.CORBA.OBJECT_NOT_EXIST)3 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)3 TRANSIENT (org.omg.CORBA.TRANSIENT)3 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)2 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)2 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)2 ServerRecoveryTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerRecoveryTopLevelAction)2 RecoveryStatus (com.arjuna.ats.internal.jts.recovery.transactions.RecoveryStatus)2 AtomicResource (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource)2