Search in sources :

Example 41 with CurrentImple

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

the class DemoResource method registerResource.

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

Example 42 with CurrentImple

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

the class HammerObject method set.

public boolean set(int value, Control control) throws SystemException {
    boolean res = false;
    ExplicitInterposition inter = new ExplicitInterposition();
    try {
        inter.registerTransaction(control);
    } catch (Exception e) {
        System.err.println("WARNING HammerObject.set - could not do interposition");
        return false;
    }
    CurrentImple current = OTSImpleManager.current();
    try {
        current.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            _value = value;
            current.commit(true);
            res = true;
        } else
            current.rollback();
    } catch (Exception e) {
        System.err.println("HammerObject.set: " + e);
        res = false;
    }
    inter.unregisterTransaction();
    return res;
}
Also used : ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 43 with CurrentImple

use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple 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)

Example 44 with CurrentImple

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

the class TimeoutClient method main.

public static void main(String[] args) throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    try {
        ServerORB orb = new ServerORB();
        myORB = orb.getORB();
        myOA = orb.getOA();
        CurrentImple current = OTSImpleManager.current();
        Control theControl = null;
        String objectReference = args[0];
        SetGet SetGetVar = null;
        System.out.println("Setting transaction timeout to " + timeout * mfactor + " seconds.");
        current.set_timeout(timeout * mfactor);
        current.begin();
        current.begin();
        long startTime = System.currentTimeMillis();
        try {
            Services serv = new Services(myORB);
            SetGetVar = SetGetHelper.narrow(myORB.orb().string_to_object(TestUtility.getService(objectReference)));
        } catch (Exception e) {
            TestUtility.fail("Bind to object failed: " + e);
            e.printStackTrace(System.err);
        }
        try {
            theControl = current.get_control();
            SetGetVar.set((short) 2, theControl);
            theControl = null;
            System.out.println("Set value.");
        } catch (Exception e) {
            TestUtility.fail("Call to set or get failed: " + e);
            e.printStackTrace(System.err);
        }
        try {
            long timeNow = System.currentTimeMillis();
            long setTime = (timeNow - startTime);
            long timeoutTime = (timeout * 1000 * mfactor);
            long sleepTime = timeoutTime - setTime;
            if (sleepTime > 0) {
                System.out.println("Now sleeping for " + sleepTime * mfactor + " milliseconds.");
                Thread.sleep(sleepTime * mfactor);
            }
        } catch (Exception e) {
        }
        System.out.println("\ncommitting nested action.");
        try {
            current.commit(true);
            TestUtility.fail("commit worked");
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.out.println("Caught TransactionRolledBack");
        } catch (INVALID_TRANSACTION e1) /* For JacORB */
        {
            System.out.println("Caught InvalidTransaction");
        }
        System.out.println("\ncommitting top-level action");
        try {
            current.commit(true);
            TestUtility.fail("commit worked");
        } catch (TRANSACTION_ROLLEDBACK e2) {
            System.out.println("Caught TransactionRolledBack");
        } catch (INVALID_TRANSACTION e3) {
            System.out.println("Caught InvalidTransaction");
        } catch (Exception e) {
            TestUtility.fail("Caught other exception: " + e);
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
        TestUtility.fail(e.toString());
    }
    myOA.destroy();
    myORB.shutdown();
    System.out.println("Passed");
}
Also used : ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Services(com.arjuna.orbportability.Services) Control(org.omg.CosTransactions.Control) SetGet(com.hp.mwtests.ts.jts.TestModule.SetGet) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) RootOA(com.arjuna.orbportability.RootOA) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB)

Example 45 with CurrentImple

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

the class TransactionalThread method run.

public void run() {
    boolean shouldWork = false;
    CurrentImple current = OTSImpleManager.current();
    if (control != null) {
        System.out.println("New thread resuming transaction.");
        try {
            current.resume(control);
        } catch (Exception e) {
            System.err.println("Caught unexpected exception: " + e);
            System.exit(1);
        }
    }
    try {
        System.out.print("Non-creating thread trying to commit transaction. ");
        if (control == null)
            System.out.println("Should fail - no transaction associated with thread!");
        else
            System.out.println("Should succeed.");
        current.commit(true);
        System.out.print("Non-creating thread committed transaction. ");
        if (control == null) {
            System.out.println("Error.");
            System.exit(1);
        } else
            System.out.println();
    } catch (Exception e) {
        System.err.println("Caught unexpected exception: " + e);
    }
    done = true;
}
Also used : CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple)

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