Search in sources :

Example 16 with Services

use of com.arjuna.orbportability.Services in project narayana by jbosstm.

the class StackServer method main.

public static void main(String[] args) throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    String refFile = args[0];
    stackPOATie theStack = new stackPOATie(new StackImple());
    myOA.objectIsReady(theStack);
    Services serv = new Services(myORB);
    try {
        TestUtility.registerService(refFile, myORB.orb().object_to_string(stackHelper.narrow(myOA.corbaReference(theStack))));
        System.out.println("Ready");
        myOA.run();
    } catch (Exception e) {
        TestUtility.fail("StackServer caught exception: " + e);
    }
    myOA.shutdownObject(theStack);
    System.out.println("**StackServer exiting**");
}
Also used : ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Services(com.arjuna.orbportability.Services) StackImple(com.hp.mwtests.ts.jts.orbspecific.resources.StackImple) RootOA(com.arjuna.orbportability.RootOA) TestModule.stackPOATie(com.hp.mwtests.ts.jts.TestModule.stackPOATie) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB)

Example 17 with Services

use of com.arjuna.orbportability.Services 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 18 with Services

use of com.arjuna.orbportability.Services 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 19 with Services

use of com.arjuna.orbportability.Services in project narayana by jbosstm.

the class TranGridServer method test.

@Test
public void test() throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    String serverName = "TranGrid";
    String refFile = "/tmp/trangrid.ref";
    if (System.getProperty("os.name").startsWith("Windows")) {
        refFile = "C:\\temp\\trangrid.ref";
    }
    trangrid_i gridI = new trangrid_i((short) 100, (short) 100);
    Services serv = new Services(myORB);
    try {
        TestUtility.registerService(refFile, myORB.orb().object_to_string(gridI.getReference()));
        System.out.println("**TranGrid server started**");
        // assertReady();
        myOA.run();
    } catch (Exception e) {
        fail("TranGrid server caught exception: " + e);
    }
    myOA.shutdownObject(gridI);
    System.out.println("**TranGrid server exiting**");
}
Also used : com.hp.mwtests.ts.jts.orbspecific.resources.trangrid_i(com.hp.mwtests.ts.jts.orbspecific.resources.trangrid_i) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Services(com.arjuna.orbportability.Services) RootOA(com.arjuna.orbportability.RootOA) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 20 with Services

use of com.arjuna.orbportability.Services 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

Services (com.arjuna.orbportability.Services)21 ORB (com.arjuna.orbportability.ORB)19 RootOA (com.arjuna.orbportability.RootOA)18 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)16 Control (org.omg.CosTransactions.Control)6 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)5 Test (org.junit.Test)5 IntHolder (org.omg.CORBA.IntHolder)5 TransactionFactory (org.omg.CosTransactions.TransactionFactory)3 SetGet (com.hp.mwtests.ts.jts.TestModule.SetGet)2 TestModule.grid (com.hp.mwtests.ts.jts.TestModule.grid)2 com.hp.mwtests.ts.jts.orbspecific.resources.trangrid_i (com.hp.mwtests.ts.jts.orbspecific.resources.trangrid_i)2 OA (com.arjuna.orbportability.OA)1 SimpleObjectImpl (com.hp.mwtests.orbportability.orbspecific.orbinstance.SimpleObjectImpl)1 ExplicitStackPOATie (com.hp.mwtests.ts.jts.TestModule.ExplicitStackPOATie)1 HammerPOATie (com.hp.mwtests.ts.jts.TestModule.HammerPOATie)1 TranGrid (com.hp.mwtests.ts.jts.TestModule.TranGrid)1 TestModule.stack (com.hp.mwtests.ts.jts.TestModule.stack)1 TestModule.stackPOATie (com.hp.mwtests.ts.jts.TestModule.stackPOATie)1 DHThreadObject2 (com.hp.mwtests.ts.jts.orbspecific.resources.DHThreadObject2)1