Search in sources :

Example 31 with CurrentImple

use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple in project narayana by jbosstm.

the class AtomicTransaction method validTransaction.

/**
 * If this transaction current? Assume we have checked that we are actually
 * a transaction!
 *
 * If not valid then abort this transaction here. Leave current alone.
 */
protected final boolean validTransaction() {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("AtomicTransaction::validTransaction called for " + _theAction);
    }
    /*
		 * If we get here then _theAction is not null.
		 */
    CurrentImple current = OTSImpleManager.current();
    boolean valid = false;
    try {
        ControlWrapper currentTransaction = current.getControlWrapper();
        if (currentTransaction == null) {
            jtsLogger.i18NLogger.warn_extensions_atnovalidtx("AtomicTransaction.validTransaction");
            return false;
        }
        valid = _theAction.equals(currentTransaction);
        if (!valid) {
            String transactionName = get_transaction_name();
            String currentTransactionName = currentTransaction.get_transaction_name();
            jtsLogger.i18NLogger.warn_extensions_atoutofseq("AtomicTransaction", transactionName);
            jtsLogger.i18NLogger.warn_extensions_atwillabort(currentTransactionName);
            try {
                _theAction.rollback();
            } catch (Exception ex) {
                jtsLogger.i18NLogger.warn_extensions_atcannotabort("AtomicTransaction", transactionName);
            }
        }
    } catch (Exception e) {
        jtsLogger.i18NLogger.warn_extensions_atgenerror("AtomicTransaction", e);
    }
    return valid;
}
Also used : ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException)

Example 32 with CurrentImple

use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple in project narayana by jbosstm.

the class TerminationTest method test.

@Test
public void test() {
    boolean commit = true;
    Control myControl = 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);
        TransactionFactoryImple theOTS = new TransactionFactoryImple();
        System.out.println("Creating transaction with 2 second timeout.");
        myControl = theOTS.create(2);
        assertNotNull(myControl);
        Terminator handle = myControl.get_terminator();
        try {
            System.out.println("Sleeping for 5 seconds.");
            Thread.sleep(5000);
        } catch (Exception e) {
        }
        if (handle != null) {
            System.out.print("Attempting to ");
            if (commit)
                System.out.println("commit transaction. Should fail!");
            else
                System.out.println("rollback transaction. Should fail!.");
            if (commit)
                handle.commit(true);
            else
                handle.rollback();
            assertFalse(commit);
            System.out.println("\nNow attempting to destroy transaction. Should fail!");
            OTSManager.destroyControl(myControl);
        } else
            System.err.println("No transaction terminator!");
    } catch (UserException e) {
        System.err.println("Caught UserException: " + e);
    } catch (SystemException e) {
        System.err.println("Caught SystemException: " + e);
        try {
            Coordinator coord = myControl.get_coordinator();
            Status s = coord.get_status();
            System.err.println("Transaction status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            coord = null;
        } catch (Exception ex) {
        }
    }
    try {
        CurrentImple current = OTSImpleManager.current();
        FakeCheckedAction act = new FakeCheckedAction();
        current.set_timeout(2);
        current.setCheckedAction(act);
        assertEquals(act, current.getCheckedAction());
        System.out.println("\nNow creating current transaction with 2 second timeout.");
        current.begin();
        myControl = current.get_control();
        try {
            System.out.println("Sleeping for 5 seconds.");
            Thread.sleep(5000);
        } catch (Exception e) {
        }
        System.out.print("Attempting to ");
        if (commit)
            System.out.println("commit transaction. Should fail!");
        else
            System.out.println("rollback transaction. Should fail!.");
        if (commit)
            current.commit(true);
        else
            current.rollback();
        assertFalse(commit);
        assertTrue(act.called);
    } catch (UserException e) {
        System.err.println("Caught UserException: " + e);
        System.out.println("Test did not completed successfully.");
    } catch (SystemException e) {
        System.err.println("Caught SystemException: " + e);
        try {
            Coordinator coord = myControl.get_coordinator();
            Status s = coord.get_status();
            System.err.println("Transaction status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            myControl = null;
            coord = null;
        } catch (Exception ex) {
        }
        System.out.println("Test completed successfully.");
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : Status(org.omg.CosTransactions.Status) RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) Coordinator(org.omg.CosTransactions.Coordinator) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) 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)

Example 33 with CurrentImple

use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple in project narayana by jbosstm.

the class DemoSubTranResource method registerResource.

public void registerResource(boolean registerSubtran) throws Unavailable, Inactive, NotSubtransaction, SystemException {
    CurrentImple current = OTSImpleManager.current();
    Control myControl = current.get_control();
    Coordinator coord = myControl.get_coordinator();
    if (registerSubtran)
        coord.register_subtran_aware(ref);
    else
        coord.register_resource(ref);
    System.out.println("Registered DemoSubTranResource");
}
Also used : Control(org.omg.CosTransactions.Control) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) Coordinator(org.omg.CosTransactions.Coordinator)

Example 34 with CurrentImple

use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple in project narayana by jbosstm.

the class trangrid_i method set.

public void set(short n, short m, short value) throws SystemException {
    CurrentImple current = OTSImpleManager.current();
    org.omg.CosTransactions.Control control = current.get_control();
    if (control != null) {
        System.out.println("trangrid_i.set - found implicit transactional context!");
        try {
            org.omg.CosTransactions.Coordinator co = control.get_coordinator();
            co.register_resource(ref);
        } catch (Exception e) {
            System.err.println("trangrid_i.set - caught exception: " + e);
        }
    } else
        System.err.println("Error - set has no transaction control, therefore will ignore!");
    m_a[n][m] = value;
}
Also used : CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException)

Example 35 with CurrentImple

use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple in project narayana by jbosstm.

the class setget_i method set.

public void set(short n, Control control) throws SystemException {
    System.out.println("setget_i.set " + n);
    try {
        if (control != null) {
            ExplicitInterposition manager = new ExplicitInterposition();
            manager.registerTransaction(control);
            System.out.println("setget_i.set - managed to set up interposition hierarchy");
            CurrentImple current = OTSImpleManager.current();
            Control cont = current.get_control();
            if (cont == null)
                System.err.println("setget_i.set error - current returned no control!");
            else {
                System.out.println("setget_i.set - current returned a control!");
                cont = null;
            }
            System.out.println("setget_i.set - beginning nested action");
            current.begin();
            cont = current.get_control();
            if (cont != null) {
                Coordinator coord = cont.get_coordinator();
                System.out.println("setget_i.set - registering self");
                coord.register_resource(ref);
                coord = null;
                cont = null;
            } else
                System.err.println("setget_i.set - current did not return control after begin!");
            value = n;
            System.out.println("setget_i.set - committing nested action");
            current.commit(true);
            manager.unregisterTransaction();
            manager = null;
        } else
            System.err.println("setget_i::set error - no control!");
    } catch (InterpositionFailed ex) {
        System.err.println("setget_i.set - error in setting up hierarchy");
        throw new UNKNOWN();
    } catch (Throwable e) {
        System.err.println("setget_i::set - caught exception: " + e);
    }
    System.out.println("setget_i.set - finished");
}
Also used : Control(org.omg.CosTransactions.Control) InterpositionFailed(com.arjuna.ArjunaOTS.InterpositionFailed) ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) UNKNOWN(org.omg.CORBA.UNKNOWN) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) Coordinator(org.omg.CosTransactions.Coordinator)

Aggregations

CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)47 Control (org.omg.CosTransactions.Control)14 SystemException (org.omg.CORBA.SystemException)12 ORB (com.arjuna.orbportability.ORB)9 RootOA (com.arjuna.orbportability.RootOA)9 IOException (java.io.IOException)7 Lock (com.arjuna.ats.txoj.Lock)6 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)6 Coordinator (org.omg.CosTransactions.Coordinator)6 Services (com.arjuna.orbportability.Services)5 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)5 ExplicitInterposition (com.arjuna.ats.jts.ExplicitInterposition)4 Test (org.junit.Test)4 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)3 TestException (com.hp.mwtests.ts.jts.exceptions.TestException)3 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)3 NoTransaction (org.omg.CosTransactions.NoTransaction)3 InterpositionFailed (com.arjuna.ArjunaOTS.InterpositionFailed)2 FatalError (com.arjuna.ats.arjuna.exceptions.FatalError)2 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)2