Search in sources :

Example 6 with TransactionFactory

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

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

the class GridClient method test.

@Test
public void test() throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    myORB = ORB.getInstance("test");
    myOA = OA.getRootOA(myORB);
    myORB.initORB(new String[] {}, null);
    myOA.initOA();
    ORBManager.setORB(myORB);
    ORBManager.setPOA(myOA);
    TransactionFactory theOTS = null;
    Control myControl = null;
    grid gridVar = null;
    int h = -1, w = -1, v = -1;
    String gridReference = "/tmp/grid.ref";
    String serverName = "Grid";
    if (System.getProperty("os.name").startsWith("Windows")) {
        gridReference = "C:\\temp\\grid.ref";
    }
    Services serv = new Services(myORB);
    try {
        String[] params = new String[1];
        params[0] = Services.otsKind;
        org.omg.CORBA.Object obj = serv.getService(Services.transactionService, params);
        params = null;
        theOTS = TransactionFactoryHelper.narrow(obj);
    } catch (Exception e) {
        fail("Unexpected bind exception: " + e);
    }
    System.out.println("Creating transaction.");
    try {
        myControl = theOTS.create(0);
    } catch (Exception e) {
        fail("Create call failed: " + e);
        e.printStackTrace();
    }
    try {
        gridVar = gridHelper.narrow(serv.getService(gridReference, null, Services.FILE));
    } catch (Exception e) {
        fail("Grid bind failed: " + e);
    }
    try {
        h = gridVar.height();
        w = gridVar.width();
    } catch (Exception e) {
        fail("Grid invocation failed: " + e);
    }
    System.out.println("height is " + h);
    System.out.println("width  is " + w);
    try {
        System.out.println("calling set");
        gridVar.set(2, 4, 123, myControl);
        System.out.println("calling get");
        v = gridVar.get(2, 4, myControl);
    } catch (Exception sysEx) {
        fail("Grid set/get failed: " + sysEx);
    }
    // no problem setting and getting the elememt:
    System.out.println("grid[2,4] is " + v);
    // sanity check: make sure we got the value 123 back:
    if (v != 123) {
        // oops - we didn't:
        fail("something went seriously wrong");
        try {
            myControl.get_terminator().rollback();
        } catch (Exception e) {
        }
    } else {
        System.out.println("Committing transaction.");
        try {
            Terminator handle = myControl.get_terminator();
            handle.commit(true);
        } catch (Exception sysEx) {
            fail("Transaction commit error: " + sysEx);
        }
    }
    try {
        OTSManager.destroyControl(myControl);
    } catch (Exception e) {
        fail("Caught destroy exception: " + e);
    }
    myOA.destroy();
    myORB.shutdown();
    System.out.println("Test completed successfully.");
}
Also used : RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) Services(com.arjuna.orbportability.Services) Control(org.omg.CosTransactions.Control) TestModule.grid(com.hp.mwtests.ts.jts.TestModule.grid) TransactionFactory(org.omg.CosTransactions.TransactionFactory) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 8 with TransactionFactory

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

the class TransactionTest1 method test.

@Test
public void test() throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    myORB = ORB.getInstance("test");
    myOA = OA.getRootOA(myORB);
    myORB.initORB(new String[] {}, null);
    myOA.initOA();
    ORBManager.setORB(myORB);
    ORBManager.setPOA(myOA);
    TransactionFactory theFactory = OTSManager.get_factory();
    Control topLevelControl = null;
    Control nestedControl = null;
    Terminator terminator = null;
    try {
        org.omg.CosTransactions.Current current = OTSManager.get_current();
        current.begin();
        topLevelControl = current.get_control();
        current.begin();
        nestedControl = current.get_control();
        /*
            * Try to commit top-level action without terminating nested
            * action.
            */
        terminator = topLevelControl.get_terminator();
        System.out.println("\nAttempting to terminate out of sequence 'current'. Should fail!");
        try {
            terminator.commit(true);
            fail();
        } catch (TRANSACTION_ROLLEDBACK e) {
            System.err.println("Commit failed! " + e);
        }
        System.out.println("\nNow attempting to terminate 'current' hierarchy. Should fail!");
        try {
            current.commit(true);
            fail();
        } catch (INVALID_TRANSACTION e1) {
            System.err.println("Nested commit failed! " + e1);
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.err.println("Nested commit failed! " + e1);
        } catch (Exception e2) {
            fail("Nested commit threw unexpected exception: " + e2);
        }
        try {
            current.commit(true);
            fail();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.err.println("Top-level commit failed! " + e1);
        } catch (INVALID_TRANSACTION e2) {
            System.err.println("Top-level commit failed! " + e2);
        } catch (Exception e3) {
            fail("Top-level commit threw unexpected exception: " + e3);
        }
        /*
            * Now with the factory.
            */
        System.out.println("\nNow creating new top-level action.");
        topLevelControl = theFactory.create(0);
        nestedControl = topLevelControl.get_coordinator().create_subtransaction();
        terminator = topLevelControl.get_terminator();
        System.out.println("\nAttempting to terminate out of sequence 'factory' action. Should fail!");
        try {
            terminator.commit(true);
            fail();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.err.println("Commit failed! " + e1);
        } catch (INVALID_TRANSACTION e2) {
            System.err.println("Commit failed! " + e2);
        }
        terminator = nestedControl.get_terminator();
        System.out.println("\nNow attempting to terminate 'factory' nested action. Should fail!");
        try {
            terminator.commit(true);
            fail();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.err.println("Commit failed! " + e1);
        } catch (INVALID_TRANSACTION e2) {
            System.err.println("Commit failed! " + e2);
        }
        System.out.println("Test completed successfully.");
    } catch (Exception e) {
        fail("Test failed - received unexpected exception " + e);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : Control(org.omg.CosTransactions.Control) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TransactionFactory(org.omg.CosTransactions.TransactionFactory) RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 9 with TransactionFactory

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

the class TMTest method test.

@Test
public void test() throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    TransactionFactory theOTS = null;
    Control topLevelControl = null;
    Services serv = new Services(myORB);
    int resolver = Services.getResolver();
    try {
        String[] params = new String[1];
        params[0] = Services.otsKind;
        org.omg.CORBA.Object obj = serv.getService(Services.transactionService, params, resolver);
        params = null;
        theOTS = TransactionFactoryHelper.narrow(obj);
    } catch (Exception e) {
        fail("Unexpected bind exception: " + e);
        e.printStackTrace(System.err);
    }
    System.out.println("Creating transaction.");
    try {
        topLevelControl = theOTS.create(0);
    } catch (Exception e) {
        fail("Create call failed: " + e);
        e.printStackTrace(System.err);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : RootOA(com.arjuna.orbportability.RootOA) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Services(com.arjuna.orbportability.Services) Control(org.omg.CosTransactions.Control) TransactionFactory(org.omg.CosTransactions.TransactionFactory) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 10 with TransactionFactory

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

the class TMClient method test.

@Test
public void test() throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    myORB = ORB.getInstance("test");
    myOA = OA.getRootOA(myORB);
    myORB.initORB(new String[] {}, null);
    myOA.initOA();
    ORBManager.setORB(myORB);
    ORBManager.setPOA(myOA);
    TransactionFactory theOTS = null;
    Control topLevelControl = null;
    Control nestedControl = null;
    String server = "/tmp/hammer1.ref";
    boolean slave = false;
    if (System.getProperty("os.name").startsWith("Windows")) {
        server = "C:\\temp\\hammer1.ref";
    }
    Services serv = new Services(myORB);
    int resolver = Services.getResolver();
    try {
        String[] params = new String[1];
        params[0] = Services.otsKind;
        org.omg.CORBA.Object obj = serv.getService(Services.transactionService, params, resolver);
        params = null;
        theOTS = TransactionFactoryHelper.narrow(obj);
    } catch (Exception e) {
        fail("Unexpected bind exception: " + e);
        e.printStackTrace(System.err);
    }
    System.out.println("Creating transaction.");
    try {
        topLevelControl = theOTS.create(0);
    } catch (Exception e) {
        fail("Create call failed: " + e);
        e.printStackTrace(System.err);
    }
    System.out.println("Creating subtransaction.");
    try {
        nestedControl = topLevelControl.get_coordinator().create_subtransaction();
    } catch (Exception e) {
        System.err.println("Subtransaction create call failed: " + e);
        try {
            topLevelControl.get_terminator().rollback();
        } catch (Exception ex) {
        }
        e.printStackTrace(System.err);
        fail();
    }
    try {
        DistributedHammerWorker1.hammerObject_1 = HammerHelper.narrow(serv.getService(server, null, Services.FILE));
        if (!DistributedHammerWorker1.hammerObject_1.incr(1, nestedControl))
            System.out.println("Could not increment!");
        else
            System.out.println("incremented.");
        System.out.println("sleeping.");
        Thread.sleep(20000);
        nestedControl.get_terminator().rollback();
        if (!slave) {
            System.out.println("master sleeping again.");
            Thread.sleep(20000);
        }
        IntHolder value = new IntHolder(0);
        org.omg.CosTransactions.PropagationContext ctx = topLevelControl.get_coordinator().get_txcontext();
        assertTrue(DistributedHammerWorker1.hammerObject_1.get(value, topLevelControl));
        topLevelControl.get_terminator().rollback();
    } catch (Exception e) {
        fail("TMClient: " + e);
        e.printStackTrace(System.err);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : RootOA(com.arjuna.orbportability.RootOA) Services(com.arjuna.orbportability.Services) Control(org.omg.CosTransactions.Control) TransactionFactory(org.omg.CosTransactions.TransactionFactory) IntHolder(org.omg.CORBA.IntHolder) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Aggregations

TransactionFactory (org.omg.CosTransactions.TransactionFactory)19 Control (org.omg.CosTransactions.Control)16 ORB (com.arjuna.orbportability.ORB)4 RootOA (com.arjuna.orbportability.RootOA)4 Test (org.junit.Test)4 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)4 Services (com.arjuna.orbportability.Services)3 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)3 Terminator (org.omg.CosTransactions.Terminator)2 TestModule.grid (com.hp.mwtests.ts.jts.TestModule.grid)1 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)1 IOException (java.io.IOException)1 IntHolder (org.omg.CORBA.IntHolder)1 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)1