Search in sources :

Example 1 with Resource

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

the class SingleResourceRegistration method work.

public void work() throws PerfTestException {
    try {
        /**
         * Retrieve ORB and OA references
         */
        ORB orb = ORB.getInstance(PerformanceFramework.ORB_INSTANCE_NAME);
        OA oa = OA.getRootOA(orb);
        Control control = OTSManager.get_current().get_control();
        Coordinator coordinator = control.get_coordinator();
        DemoResource resource = new DemoResource();
        oa.objectIsReady(resource);
        Resource res = ResourceHelper.narrow(oa.corbaReference(resource));
        coordinator.register_resource(res);
    } catch (Exception e) {
        e.printStackTrace(System.err);
        throw new PerfTestException();
    }
}
Also used : DemoResource(org.jboss.jbossts.qa.performance.resources.DemoResource) OA(com.arjuna.orbportability.OA) Control(org.omg.CosTransactions.Control) DemoResource(org.jboss.jbossts.qa.performance.resources.DemoResource) Resource(org.omg.CosTransactions.Resource) Coordinator(org.omg.CosTransactions.Coordinator) ORB(com.arjuna.orbportability.ORB)

Example 2 with Resource

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

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

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

the class BeforeCrashServiceImpl01 method setup_oper.

public void setup_oper(ResourceBehavior[] resource_behaviors) {
    ResourceImpl01[] resourceImpl = new ResourceImpl01[resource_behaviors.length];
    Resource[] resource = new Resource[resource_behaviors.length];
    RecoveryCoordinator[] recoveryCoordinator = new RecoveryCoordinator[resource_behaviors.length];
    for (int index = 0; index < resource_behaviors.length; index++) {
        try {
            resourceImpl[index] = new ResourceImpl01(_serviceNumber, _objectNumber, index, resource_behaviors[index]);
            ResourcePOATie servant = new ResourcePOATie(resourceImpl[index]);
            OAInterface.objectIsReady(servant);
            resource[index] = ResourceHelper.narrow(OAInterface.corbaReference(servant));
            recoveryCoordinator[index] = OTS.current().get_control().get_coordinator().register_resource(resource[index]);
            System.out.println("BeforeCrashServiceImpl01: storing IOR \"RecoveryCoordinator_" + _serviceNumber + "_" + _objectNumber + "_" + index + "\"");
            ServerIORStore.storeIOR("RecoveryCoordinator_" + _serviceNumber + "_" + _objectNumber + "_" + index, ORBInterface.orb().object_to_string(recoveryCoordinator[index]));
        } catch (Exception exception) {
            System.err.println("BeforeCrashServiceImpl01.setup_oper: " + exception);
            exception.printStackTrace(System.err);
            _isCorrect = false;
        }
    }
}
Also used : Resource(org.omg.CosTransactions.Resource) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) ResourcePOATie(org.omg.CosTransactions.ResourcePOATie)

Aggregations

Resource (org.omg.CosTransactions.Resource)4 ORB (com.arjuna.orbportability.ORB)3 Control (org.omg.CosTransactions.Control)3 Coordinator (org.omg.CosTransactions.Coordinator)3 RootOA (com.arjuna.orbportability.RootOA)2 AtomicResource (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource)2 Test (org.junit.Test)2 SystemException (org.omg.CORBA.SystemException)2 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)2 HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)2 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)2 RecoveryCoordinator (org.omg.CosTransactions.RecoveryCoordinator)2 Status (org.omg.CosTransactions.Status)2 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)1 OA (com.arjuna.orbportability.OA)1 com.hp.mwtests.ts.jts.orbspecific.resources.heuristic (com.hp.mwtests.ts.jts.orbspecific.resources.heuristic)1 ResourceTrace (com.hp.mwtests.ts.jts.utils.ResourceTrace)1 DemoResource (org.jboss.jbossts.qa.performance.resources.DemoResource)1 Current (org.omg.CosTransactions.Current)1 NotPrepared (org.omg.CosTransactions.NotPrepared)1