Search in sources :

Example 51 with Control

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

the class SynchTest method test.

@Test
public void test() {
    org.omg.CosTransactions.Status status = Status.StatusUnknown;
    tranobject_i localObject = null;
    demosync sync = null;
    ORB myORB = null;
    RootOA myOA = null;
    try {
        ServerORB orb = new ServerORB();
        myORB = orb.getORB();
        myOA = orb.getOA();
        Control myControl = null;
        org.omg.CosTransactions.Current current = OTSManager.get_current();
        Coordinator coord = null;
        sync = new demosync();
        localObject = new tranobject_i();
        current.begin();
        myControl = current.get_control();
        coord = myControl.get_coordinator();
        coord.register_resource(localObject.getReference());
        coord.register_synchronization(sync.getReference());
        try {
            current.commit(true);
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.out.println("Transaction rolledback");
        }
        try {
            status = coord.get_status();
        } catch (SystemException ex) {
            // assume reference no longer valid!
            status = Status.StatusUnknown;
        }
    } catch (UserException e1) {
        fail("Caught UserException: " + e1);
        e1.printStackTrace();
    } catch (SystemException e2) {
        fail("Caught SystemException: " + e2);
        e2.printStackTrace();
    }
    System.out.print("Final action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
    System.out.println("\nTest completed successfully.");
    myOA.shutdownObject(sync);
    myOA.shutdownObject(localObject);
    myOA.destroy();
    myORB.shutdown();
}
Also used : com.hp.mwtests.ts.jts.orbspecific.resources.tranobject_i(com.hp.mwtests.ts.jts.orbspecific.resources.tranobject_i) com.hp.mwtests.ts.jts.orbspecific.resources.demosync(com.hp.mwtests.ts.jts.orbspecific.resources.demosync) RootOA(com.arjuna.orbportability.RootOA) Coordinator(org.omg.CosTransactions.Coordinator) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) Status(org.omg.CosTransactions.Status) UserException(org.omg.CORBA.UserException) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 52 with Control

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

the class FactoryListUnitTest method test.

@SuppressWarnings("static-access")
@Test
public void test() throws Exception {
    FactoryList factory = new FactoryList();
    factory.removeDefault();
    try {
        assertNull(factory.recreate(null, FactoryList.DEFAULT_ID));
        fail();
    } catch (final INVALID_TRANSACTION ex) {
    } catch (final Throwable ex) {
        fail();
    }
    FactoryList.remove(Arjuna.restrictedXID());
    TransactionFactoryImple imple = new TransactionFactoryImple("test");
    ControlImple tx = imple.createLocal(1000);
    PropagationContext ctx = tx.get_coordinator().get_txcontext();
    Control cont = FactoryList.recreate(ctx, Arjuna.XID());
    assertTrue(Utility.getUid(cont).equals(tx.get_uid()));
}
Also used : Control(org.omg.CosTransactions.Control) PropagationContext(org.omg.CosTransactions.PropagationContext) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) FactoryList(com.arjuna.ats.internal.jts.interposition.FactoryList) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 53 with Control

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

the class tx method tx_begin.

public static final synchronized int tx_begin() {
    int toReturn = tx.TX_OK;
    CurrentImple current = OTSImpleManager.current();
    if (!__tx_allow_nesting) {
        try {
            Control control = current.get_control();
            if (control != null) {
                /*
		     * Have a transaction already, and not allowed to
		     * create nested transactions!
		     */
                toReturn = tx.TX_PROTOCOL_ERROR;
                control = null;
            }
        } catch (Exception e) {
            // something went wrong!
            toReturn = tx.TX_FAIL;
        }
    }
    if (toReturn == tx.TX_OK) {
        try {
            current.begin();
        } catch (Exception e) {
            toReturn = tx.TX_FAIL;
        }
    }
    return toReturn;
}
Also used : Control(org.omg.CosTransactions.Control) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple)

Example 54 with Control

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

the class ExplicitInterposition method unregisterTransaction.

/**
 * We need this explicit method because we cannot rely upon the object
 * "destructor" being called by the time the method which instantiated the
 * interposition class ends!
 */
public synchronized void unregisterTransaction() throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ExplicitInterposition::unregisterTransaction ()");
    }
    if (!_inUse)
        throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
    else {
        try {
            Control control = OTSImpleManager.current().suspend();
            control = null;
            if (_remember && (_oldControl != null)) {
                try {
                    OTSImpleManager.current().resumeWrapper(_oldControl);
                    _oldControl = null;
                } catch (Exception exp) {
                    throw new UNKNOWN(exp.toString());
                }
            }
        } catch (UNKNOWN exp) {
            throw exp;
        } catch (SystemException ex) {
            _inUse = false;
            throw ex;
        } catch (Exception e) {
            _inUse = false;
            throw new UNKNOWN(e.toString());
        }
        _inUse = false;
    }
}
Also used : Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) UNKNOWN(org.omg.CORBA.UNKNOWN) SystemException(org.omg.CORBA.SystemException)

Example 55 with Control

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

the class CheckedTransactions 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);
        Control tx = null;
        System.out.println("Thread " + Thread.currentThread() + " starting transaction.");
        OTSImpleManager.current().setCheckedAction(new MyCheckedAction());
        OTSImpleManager.current().begin();
        tx = OTSImpleManager.current().get_control();
        TXThread txThread = new TXThread(tx);
        txThread.start();
        txThread.join();
        System.out.println("Thread " + Thread.currentThread() + " committing transaction.");
        OTSImpleManager.current().commit(false);
        System.out.println("Transaction committed. Checked transactions enabled.");
    } catch (Exception e) {
        System.out.println("Caught exception: " + e);
        fail("Checked transactions disabled!");
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : Control(org.omg.CosTransactions.Control) RootOA(com.arjuna.orbportability.RootOA) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Aggregations

Control (org.omg.CosTransactions.Control)103 Test (org.junit.Test)40 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)24 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)20 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)20 ORB (com.arjuna.orbportability.ORB)20 RootOA (com.arjuna.orbportability.RootOA)18 TransactionFactory (org.omg.CosTransactions.TransactionFactory)16 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)14 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)13 Coordinator (org.omg.CosTransactions.Coordinator)13 SystemException (org.omg.CORBA.SystemException)11 IntHolder (org.omg.CORBA.IntHolder)10 Current (org.omg.CosTransactions.Current)9 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)6 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)6 Services (com.arjuna.orbportability.Services)6 PropagationContext (org.omg.CosTransactions.PropagationContext)6 ActionControl (com.arjuna.ArjunaOTS.ActionControl)5 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)5