Search in sources :

Example 16 with HeuristicHazard

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

the class ArjunaTransactionImple method commit.

/**
 * If the transaction has already been committed (by another thread, for
 * example) then we do nothing - could throw TransactionRequired or
 * INVALID_TRANSACTION. However, if it was rolledback then we throw
 * TRANSACTION_ROLLEDBACK. Seems like an inconsistency.
 *
 * OTS is vague as to what to do if the transaction has been terminated,
 * so we make a sensible choice.
 *
 * report_heuristics is ignored if we are a subtransaction.
 */
public void commit(boolean report_heuristics) throws HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::commit for " + get_uid());
    }
    if (ArjunaTransactionImple._checkedTransactions && !checkAccess()) {
        throw new NO_PERMISSION(0, CompletionStatus.COMPLETED_NO);
    }
    int outcome = super.status();
    if ((outcome == ActionStatus.RUNNING) || // have we already been
    (outcome == ActionStatus.ABORT_ONLY)) // committed?
    {
        try {
            if (_synchs != null) {
                if (outcome == ActionStatus.RUNNING || (outcome == ActionStatus.ABORT_ONLY && TxControl.isBeforeCompletionWhenRollbackOnly())) {
                    doBeforeCompletion();
                }
            }
        } catch (Exception e) {
        /*
				 * Don't do anything, since we will have marked the transaction
				 * as rollback only.
				 */
        }
        if (parentTransaction != null) {
            parentTransaction.removeChildAction(this);
        }
        outcome = super.End(report_heuristics);
        try {
            if (_synchs != null) {
                currentStatus = determineStatus(this);
                doAfterCompletion(currentStatus);
                _synchs = null;
            }
        } catch (Exception e) {
        }
        destroyAction();
    } else if (outcome == ActionStatus.ABORTED || outcome == ActionStatus.H_ROLLBACK) {
        throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.FAILED_TO_COMMIT, CompletionStatus.COMPLETED_NO);
    } else {
        throw new INVALID_TRANSACTION(0, CompletionStatus.COMPLETED_NO);
    }
    switch(outcome) {
        case ActionStatus.COMMITTED:
        case ActionStatus.H_COMMIT:
        case // in case asynchronous commit!
        ActionStatus.COMMITTING:
            return;
        case ActionStatus.ABORTED:
        // in case of asynchronous abort!
        case ActionStatus.ABORTING:
        case ActionStatus.H_ROLLBACK:
            throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.FAILED_TO_COMMIT, CompletionStatus.COMPLETED_NO);
        case ActionStatus.H_MIXED:
            if (report_heuristics)
                throw new HeuristicMixed();
            break;
        case ActionStatus.H_HAZARD:
        default:
            if (report_heuristics)
                throw new HeuristicHazard();
            break;
    }
}
Also used : NO_PERMISSION(org.omg.CORBA.NO_PERMISSION) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) SystemException(org.omg.CORBA.SystemException) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 17 with HeuristicHazard

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

the class ServerNestedAction method commit_subtransaction.

public void commit_subtransaction(Coordinator parent) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerNestedAction::commit_subtransaction : " + _theUid);
    }
    if (_theControl == null) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_nullcontrol_1("ServerNestedAction.commit_subtransaction");
        throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
    }
    if (_theControl.isWrapper()) {
        destroyResource();
        return;
    }
    ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
    try {
        theTransaction.commit(false);
    } catch (TRANSACTION_ROLLEDBACK e1) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e1);
        throw e1;
    } catch (INVALID_TRANSACTION e5) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e5);
        throw e5;
    } catch (HeuristicMixed e2) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e2);
        throw new BAD_OPERATION(ExceptionCodes.HEURISTIC_COMMIT, CompletionStatus.COMPLETED_MAYBE);
    } catch (HeuristicHazard e3) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e3);
        throw new BAD_OPERATION(ExceptionCodes.HEURISTIC_COMMIT, CompletionStatus.COMPLETED_MAYBE);
    } catch (SystemException e4) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e4);
        throw e4;
    } catch (Exception e5) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e5);
        throw new UNKNOWN(e5.toString());
    } finally {
        ThreadActionData.popAction();
        destroyResource();
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) UNKNOWN(org.omg.CORBA.UNKNOWN) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SystemException(org.omg.CORBA.SystemException)

Example 18 with HeuristicHazard

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

the class ServerTopLevelAction method commit_one_phase.

public void commit_one_phase() throws HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::commit_one_phase for " + _theUid);
    }
    if (_theControl == null) {
        throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
    }
    if (_theControl.isWrapper()) {
        destroyResource();
        return;
    }
    ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
    if (theTransaction == null) {
        jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_notx("ServerTopLevelAction.commit_one_phase");
        throw new INVALID_TRANSACTION(ExceptionCodes.NO_TRANSACTION, CompletionStatus.COMPLETED_NO);
    }
    // LockManager needs to know if there is a transaction
    ThreadActionData.pushAction(theTransaction);
    try {
        /*
	     * This will commit and do any before/after_completion calls
	     * on registered synchronizations.
	     */
        theTransaction.doCommit(true);
    } catch (HeuristicHazard e1) {
        /*
	     * Is a heuristic, then don't remove the
	     * transaction information.
	     */
        ThreadActionData.popAction();
        throw e1;
    } catch (TRANSACTION_ROLLEDBACK e4) {
        ThreadActionData.popAction();
        throw e4;
    } catch (INVALID_TRANSACTION e5) {
        ThreadActionData.popAction();
        throw e5;
    } catch (SystemException e6) {
        ThreadActionData.popAction();
        throw e6;
    } catch (Exception e7) {
        ThreadActionData.popAction();
        throw new UNKNOWN(e7.toString());
    } finally {
        destroyResource();
    }
    ThreadActionData.popAction();
    destroyResource();
}
Also used : SystemException(org.omg.CORBA.SystemException) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) UNKNOWN(org.omg.CORBA.UNKNOWN) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SystemException(org.omg.CORBA.SystemException)

Example 19 with HeuristicHazard

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

the class RCTest method test.

@Test
public void test() {
    boolean shouldCommit = true;
    boolean passed = false;
    Coordinator coord = null;
    ORB myORB = null;
    RootOA myOA = null;
    try {
        myORB = ORB.getInstance("test");
        myOA = OA.getRootOA(myORB);
        myORB.initORB(new String[] {}, null);
        myOA.initOA();
        ORBManager.setORB(myORB);
        ORBManager.setPOA(myOA);
        CurrentImple current = OTSImpleManager.current();
        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.");
        RecoveryCoordinator rc = null;
        try {
            rc = coord.register_resource(atomicObject);
        } catch (Exception ex) {
            fail("Failed to register resources: " + ex);
            ex.printStackTrace();
        }
        if (rc == null)
            System.out.println("No recovery coordinator reference.");
        else {
            Status s = Status.StatusUnknown;
            try {
                System.out.println("Attempting to use recovery coordinator.");
                s = rc.replay_completion(atomicObject);
            } catch (NotPrepared e) {
                s = Status.StatusActive;
            } catch (Exception ex) {
                fail("Caught: " + ex);
                ex.printStackTrace();
            }
            System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            if (s == Status.StatusActive)
                passed = true;
        }
        System.out.println("committing top-level transaction.");
        if (shouldCommit)
            current.commit(true);
        else
            current.rollback();
        if (rc == null)
            System.out.println("No recovery coordinator reference.");
        else {
            Status s = Status.StatusUnknown;
            try {
                System.out.println("Attempting to use recovery coordinator.");
                s = rc.replay_completion(atomicObject);
            } catch (NotPrepared e) {
                s = Status.StatusActive;
            } catch (Exception ex) {
                fail("Caught: " + ex);
            }
            System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            if (passed && (s == Status.StatusRolledBack))
                passed = true;
            else
                passed = false;
        }
    } 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) {
        System.out.println("Caught unexpected exception: " + e4);
    }
    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
            System.out.println("\nCould not determine action status.");
    } catch (SystemException ex1) {
    // assume invalid reference - tx may have been garbage collected
    } catch (Exception e5) {
        System.out.println("Caught unexpected exception:" + e5);
    }
    System.out.println("\nFinal action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
    assertTrue(passed);
    myOA.destroy();
    myORB.shutdown();
}
Also used : Status(org.omg.CosTransactions.Status) AtomicResource(com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource) Resource(org.omg.CosTransactions.Resource) RootOA(com.arjuna.orbportability.RootOA) AtomicResource(com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) NotPrepared(org.omg.CosTransactions.NotPrepared) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) Status(org.omg.CosTransactions.Status) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Aggregations

HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)19 SystemException (org.omg.CORBA.SystemException)13 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)12 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)11 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)7 ServerTransaction (com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction)5 Test (org.junit.Test)5 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)4 UNKNOWN (org.omg.CORBA.UNKNOWN)4 NoTransaction (org.omg.CosTransactions.NoTransaction)4 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)3 NotSerializableException (java.io.NotSerializableException)3 XAException (javax.transaction.xa.XAException)3 NotPrepared (org.omg.CosTransactions.NotPrepared)3 ORB (com.arjuna.orbportability.ORB)2 RootOA (com.arjuna.orbportability.RootOA)2 ExtendedCrashRecord (com.hp.mwtests.ts.jta.jts.common.ExtendedCrashRecord)2 AtomicResource (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource)2 Control (org.omg.CosTransactions.Control)2 Coordinator (org.omg.CosTransactions.Coordinator)2