Search in sources :

Example 6 with Control

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

the class Client12 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        TransactionFactory transactionFactory = null;
        String[] transactionFactoryParams = new String[1];
        transactionFactoryParams[0] = ORBServices.otsKind;
        transactionFactory = TransactionFactoryHelper.narrow(ORBServices.getService(ORBServices.transactionService, transactionFactoryParams));
        int numberOfControls = Integer.parseInt(args[args.length - 1]);
        boolean correct = true;
        Control[] controls = new Control[numberOfControls];
        for (int index = 0; correct && (index < controls.length); index++) {
            controls[index] = transactionFactory.create(0);
            correct = correct && (controls[index].get_coordinator().get_status() == Status.StatusActive);
        }
        for (int index = 0; correct && (index < controls.length); index++) {
            controls[index].get_terminator().rollback();
        }
        if (correct) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Client12.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Client12.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : Control(org.omg.CosTransactions.Control) TransactionFactory(org.omg.CosTransactions.TransactionFactory)

Example 7 with Control

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

the class Client01 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        TransactionFactory transactionFactory = null;
        String[] transactionFactoryParams = new String[1];
        transactionFactoryParams[0] = ORBServices.otsKind;
        transactionFactory = TransactionFactoryHelper.narrow(ORBServices.getService(ORBServices.transactionService, transactionFactoryParams));
        boolean correct = true;
        Control control = transactionFactory.create(0);
        correct = correct && (control.get_coordinator().get_status() == Status.StatusActive);
        control.get_terminator().commit(true);
        if (correct) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Client01.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Client01.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : Control(org.omg.CosTransactions.Control) TransactionFactory(org.omg.CosTransactions.TransactionFactory)

Example 8 with Control

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

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

the class TransactionManagerImple method suspend.

/**
 * @return the suspended transaction.
 */
public Transaction suspend() throws javax.transaction.SystemException {
    if (jtaxLogger.logger.isTraceEnabled()) {
        jtaxLogger.logger.trace("TransactionManagerImple.suspend");
    }
    try {
        TransactionImple tx = TransactionImple.getTransaction();
        Control theControl = OTSManager.get_current().suspend();
        return tx;
    } catch (org.omg.CORBA.TRANSACTION_UNAVAILABLE e) {
        try {
            Uid uid = OTSImpleManager.systemCurrent().contextManager().getReceivedCoordinatorUid();
            if (uid != null) {
                OTSImpleManager.systemCurrent().contextManager().disassociateContext(OTSManager.getReceivedSlotId());
                return TransactionImple.getTransactions().get(uid);
            } else {
                return null;
            }
        } catch (InvalidSlot e1) {
            javax.transaction.SystemException systemException = new javax.transaction.SystemException(e.toString());
            systemException.initCause(e);
            throw systemException;
        }
    } catch (Exception e) {
        javax.transaction.SystemException systemException = new javax.transaction.SystemException(e.toString());
        systemException.initCause(e);
        throw systemException;
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) Control(org.omg.CosTransactions.Control) TRANSACTION_UNAVAILABLE(org.omg.CORBA.TRANSACTION_UNAVAILABLE) InvalidSlot(org.omg.PortableInterceptor.InvalidSlot) InvalidTransactionException(javax.transaction.InvalidTransactionException)

Example 10 with Control

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

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