Search in sources :

Example 6 with NoTransaction

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

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

the class AtomicTransaction method rollback.

/*
	 * Rollback the transaction. If the current transaction associated with the
	 * thread is not this transaction, then this transaction is rolled back and
	 * leave current alone.
	 * 
	 * @exception org.omg.CosTransactions.NoTransaction if the transaction has
	 * already been terminated.
	 * 
	 * @exception org.omg.CORBA.WRONG_TRANSACTION if the current transaction is
	 * not this transaction.
	 */
public void rollback() throws NoTransaction, WrongTransaction, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("AtomicTransaction::rollback 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.rollback();
        _theStatus = Status.StatusRolledBack;
    } catch (NoTransaction e) {
        _theStatus = Status.StatusNoTransaction;
        throw e;
    } catch (TRANSACTION_ROLLEDBACK e) {
        _theStatus = Status.StatusRolledBack;
    } 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) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK)

Example 8 with NoTransaction

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

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

the class TransactionFactoryImple method getChildTransactions.

/**
 * @return the list of child transactions.
 */
public org.omg.CosTransactions.otid_t[] getChildTransactions(otid_t parent) throws Inactive, NoTransaction, SystemException {
    Uid u = Utility.otidToUid(parent);
    org.omg.CosTransactions.otid_t[] ctx = null;
    if (u == null)
        throw new BAD_PARAM("otid_t " + jtsLogger.i18NLogger.get_orbspecific_otiderror());
    else {
        BasicAction act = ActionManager.manager().get(u);
        if (act == null)
            throw new NoTransaction();
        else {
            if (act.status() == ActionStatus.RUNNING) {
                Object[] children = act.childTransactions();
                int size = ((children == null) ? 0 : children.length);
                if (size > 0) {
                    ctx = new org.omg.CosTransactions.otid_t[size];
                    for (int i = 0; i < size; i++) {
                        ctx[i] = Utility.uidToOtid((Uid) children[i]);
                    }
                }
            } else
                throw new Inactive();
        }
    }
    return ctx;
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) CosTransactions.otid_t(org.omg.CosTransactions.otid_t) BAD_PARAM(org.omg.CORBA.BAD_PARAM) Uid(com.arjuna.ats.arjuna.common.Uid) Inactive(org.omg.CosTransactions.Inactive)

Example 10 with NoTransaction

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

the class GridTest method test.

@Test
public void test() {
    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);
        TransactionFactoryImple theOTS = new TransactionFactoryImple();
        Control myControl;
        grid_i localGrid = new grid_i(100, 100);
        int h, w, v;
        myControl = theOTS.create(0);
        assertNotNull(myControl);
        h = localGrid.height();
        w = localGrid.width();
        localGrid.set(2, 4, 123, myControl);
        v = localGrid.get(2, 4, myControl);
        // no problem setting and getting the elememt:
        System.out.println("grid[2,4] is " + v);
        assertEquals(123, v);
        Terminator handle = myControl.get_terminator();
        try {
            if (handle != null) {
                handle.commit(false);
            } else
                System.err.println("Error - no transaction terminator!");
        } catch (Exception ex) {
            System.out.println("Test error! Caught: " + ex);
        }
        ORBManager.getPOA().shutdownObject(theOTS);
        ORBManager.getPOA().shutdownObject(localGrid);
    } catch (UserException e) {
        fail("Caught UserException: " + e);
        e.printStackTrace();
    } catch (SystemException e) {
        fail("Caught SystemException: " + e);
        e.printStackTrace();
    }
    System.out.println("\nWill now try different thread terminating transaction.\n");
    try {
        org.omg.CosTransactions.Current current = OTSManager.get_current();
        System.out.println("Starting new transaction.");
        current.begin();
        Control tc = current.get_control();
        if (tc != null) {
            System.out.println("Creating new thread.");
            TransactionalThread tranThread = new TransactionalThread(tc);
            System.out.println("Waiting for thread to terminate transaction.\n");
            tranThread.start();
            while (!tranThread.finished()) Thread.yield();
            System.out.println("\nCreator will now attempt to rollback transaction. Should fail.");
            try {
                current.rollback();
                fail("Error - managed to rollback transaction!");
            } catch (NoTransaction e1) {
                System.out.println("Correct termination - caught: " + e1);
            } catch (INVALID_TRANSACTION e2) {
                System.out.println("Correct termination - caught: " + e2);
            } catch (Exception e3) {
                fail("Wrong termination - caught unexpected exception: " + e3);
                e3.printStackTrace();
            }
            System.out.println("Test completed successfully.");
        } else
            System.err.println("Error - null transaction control!");
    } catch (Exception e) {
        System.out.println("Caught unexpected exception: " + e);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : TransactionalThread(com.hp.mwtests.ts.jts.resources.TransactionalThread) NoTransaction(org.omg.CosTransactions.NoTransaction) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) com.hp.mwtests.ts.jts.orbspecific.resources.grid_i(com.hp.mwtests.ts.jts.orbspecific.resources.grid_i) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) UserException(org.omg.CORBA.UserException) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Aggregations

NoTransaction (org.omg.CosTransactions.NoTransaction)32 Current (org.omg.CosTransactions.Current)17 SystemException (org.omg.CORBA.SystemException)9 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)5 CosTransactions.otid_t (org.omg.CosTransactions.otid_t)5 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)4 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)4 HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)4 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)4 Inactive (org.omg.CosTransactions.Inactive)4 BAD_PARAM (org.omg.CORBA.BAD_PARAM)3 WrongTransaction (org.omg.CORBA.WrongTransaction)3 Unavailable (org.omg.CosTransactions.Unavailable)3 GlobalTransactionInfo (com.arjuna.ArjunaOTS.GlobalTransactionInfo)2 Uid (com.arjuna.ats.arjuna.common.Uid)2 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)2 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)2 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)2 Test (org.junit.Test)2 UserException (org.omg.CORBA.UserException)2