Search in sources :

Example 6 with HeuristicMixed

use of org.omg.CosTransactions.HeuristicMixed 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 7 with HeuristicMixed

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

the class AtomicTransaction method commit.

/*
	 * Commit the transaction. If the current transaction associated with the
	 * thread is not this transaction, then this transaction is rolled back and
	 * leave current alone.
	 * 
	 * @param report_heuristics indicates whether heuristic reporting is
	 * desired.
	 * 
	 * @exception org.omg.CosTransactions.NoTransaction if the transaction has
	 * already been terminated.
	 * 
	 * @exception org.omg.CORBA.TRANSACTION_ROLLEDBACK if the transaction rolls
	 * back.
	 * 
	 * @exception org.omg.CosTransactions.HeuristicMixed if some of the
	 * transaction participants committed, while some rolled back.
	 * 
	 * @exception org.omg.CosTransactions.HeuristicHazard if some of the
	 * transaction participants committed, some rolled back, and the outcome of
	 * others is indeterminate.
	 * 
	 * @exception org.omg.CORBA.WRONG_TRANSACTION if the current transaction is
	 * not this transaction.
	 */
public void commit(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, WrongTransaction, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("AtomicTransaction::commit ( " + report_heuristics + " ) for " + _theAction);
    }
    synchronized (_theStatus) {
        if (_theAction == null) {
            throw new NoTransaction();
        }
    }
    if (!validTransaction()) {
        throw new WrongTransaction();
    }
    /*
		 * OK to use current since we have just guaranteed that the transaction
		 * is the same as current. Use current rather than saved control since
		 * it will do thread tracking for us.
		 */
    CurrentImple current = OTSImpleManager.current();
    try {
        current.commit(report_heuristics);
        _theStatus = Status.StatusCommitted;
    } catch (NoTransaction e) {
        _theStatus = Status.StatusNoTransaction;
        throw e;
    } catch (HeuristicMixed e) {
        _theStatus = getStatus();
        throw e;
    } catch (HeuristicHazard e) {
        _theStatus = getStatus();
        throw e;
    } catch (TRANSACTION_ROLLEDBACK e) {
        _theStatus = Status.StatusRolledBack;
        throw e;
    } catch (SystemException e) {
        _theStatus = getStatus();
        throw e;
    }
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) WrongTransaction(org.omg.CORBA.WrongTransaction) SystemException(org.omg.CORBA.SystemException) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 8 with HeuristicMixed

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

the class tx method tx_commit.

public static final synchronized int tx_commit() {
    int toReturn = tx.TX_OK;
    CurrentImple current = OTSImpleManager.current();
    Boolean report_heuristics = (Boolean) __tx_report_heuristics.get(Thread.currentThread());
    if (report_heuristics == null)
        // default TRUE
        report_heuristics = new Boolean(true);
    try {
        boolean when_return = report_heuristics.booleanValue();
        current.commit(when_return);
    } catch (NoTransaction e1) {
        toReturn = tx.TX_NO_BEGIN;
    } catch (HeuristicMixed e2) {
        toReturn = tx.TX_HAZARD;
    } catch (HeuristicHazard e3) {
        toReturn = tx.TX_HAZARD;
    } catch (TRANSACTION_ROLLEDBACK e4) {
        toReturn = tx.TX_ROLLBACK;
    } catch (Exception e5) {
        toReturn = tx.TX_FAIL;
    }
    return toReturn;
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 9 with HeuristicMixed

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

the class XAResourceRecordUnitTest method testRollbackFailure.

@Test
public void testRollbackFailure() throws Exception {
    ThreadActionData.purgeActions();
    OTSImpleManager.current().contextManager().purgeActions();
    FailureXAResource fxa = new FailureXAResource(FailureXAResource.FailLocation.rollback);
    TransactionImple tx = new TransactionImple();
    XAResourceRecord xares = new XAResourceRecord(tx, fxa, tx.getTxId(), null);
    assertEquals(xares.prepare(), Vote.VoteCommit);
    try {
        xares.rollback();
        fail();
    } catch (final HeuristicMixed ex) {
    }
    xares.forget();
}
Also used : XAResourceRecord(com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) Test(org.junit.Test)

Example 10 with HeuristicMixed

use of org.omg.CosTransactions.HeuristicMixed in project Payara by payara.

the class XATerminatorImpl method commit.

/**
 * Commits the global transaction specified by xid.
 *
 * @param xid A global transaction identifier
 *
 * @param onePhase If true, the resource manager should use a one-phase
 * commit protocol to commit the work done on behalf of xid.
 *
 * @exception XAException An error has occurred. Possible XAExceptions
 * are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR,
 * XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 *
 * <P>If the resource manager did not commit the transaction and the
 *  parameter onePhase is set to true, the resource manager may throw
 *  one of the XA_RB* exceptions. Upon return, the resource manager has
 *  rolled back the branch's work and has released all held resources.
 */
public void commit(Xid xid, boolean onePhase) throws XAException {
    // check if xid is valid
    check(xid);
    GlobalTID tid = new GlobalTID(xid);
    if (onePhase) {
        // in method javax.Synchronization.beforeCompletion
        try {
            recreate(xid, 0);
        } catch (Throwable e) {
            // failed check for concurrent activity
            XAException xaExc = new XAException(XAException.XAER_PROTO);
            xaExc.initCause(e);
            throw xaExc;
        }
    } else {
        // check for concurrrent activity
        if (RecoveryManager.readAndUpdateTxMap(tid) == false) {
            throw new XAException(XAException.XAER_PROTO);
        }
    }
    boolean exceptionFlag = false;
    int errorCode = XAException.XAER_PROTO;
    try {
        // First of all make sure it has been recovered if necessary
        RecoveryManager.waitForRecovery();
        // Look up the Coordinator for the transaction.
        TopCoordinator coord = (TopCoordinator) RecoveryManager.getCoordinator(tid);
        if (coord == null) {
            // error to receive commit more than once
            errorCode = XAException.XAER_PROTO;
            throw new XAException(errorCode);
        }
        // operation. Tell the Coordinator to commit.
        synchronized (coord) {
            if (onePhase) {
                coord.beforeCompletion();
                if (coord.getParticipantCount() == 1) {
                    coord.commitOnePhase();
                } else {
                    Vote vote;
                    try {
                        vote = coord.prepare();
                    } catch (HeuristicMixed exc) {
                        errorCode = XAException.XA_HEURHAZ;
                        throw new XAException(errorCode);
                    }
                    if (vote == Vote.VoteCommit) {
                        coord.commit();
                    } else if (vote == Vote.VoteRollback) {
                        coord.rollback(true);
                    }
                }
            } else {
                coord.commit();
            }
        }
    } catch (Throwable exc) {
        exceptionFlag = true;
        XAException xaExc = new XAException(errorCode);
        xaExc.initCause(exc);
        throw xaExc;
    } finally {
        if (onePhase) {
            // beforeCompletion calls in prepare phase of one phase commit.
            try {
                release(xid);
            } catch (Throwable t) {
                if (!exceptionFlag) {
                    XAException xaExc = new XAException(XAException.XAER_PROTO);
                    xaExc.initCause(t);
                    throw xaExc;
                }
            }
        } else {
            Thread thread = RecoveryManager.removeFromTxMap(tid);
            if (thread == null || (thread != Thread.currentThread())) {
                // error
                if (!exceptionFlag) {
                    // no exception yet
                    throw new XAException(XAException.XAER_RMERR);
                }
            }
        }
    }
}
Also used : Vote(org.omg.CosTransactions.Vote) XAException(javax.transaction.xa.XAException) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed)

Aggregations

HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)15 HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)12 SystemException (org.omg.CORBA.SystemException)10 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)9 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)6 ServerTransaction (com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction)4 Test (org.junit.Test)4 NoTransaction (org.omg.CosTransactions.NoTransaction)4 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)3 NotPrepared (org.omg.CosTransactions.NotPrepared)3 XAResourceRecord (com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord)2 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)2 ORB (com.arjuna.orbportability.ORB)2 RootOA (com.arjuna.orbportability.RootOA)2 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)2 AtomicResource (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource)2 XAException (javax.transaction.xa.XAException)2 UNKNOWN (org.omg.CORBA.UNKNOWN)2 Control (org.omg.CosTransactions.Control)2 Coordinator (org.omg.CosTransactions.Coordinator)2