Search in sources :

Example 41 with IntHolder

use of org.omg.CORBA.IntHolder in project ACS by ACS-Community.

the class NCSubscriber method getSharedAdmin.

////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// Helper methods  ////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
/**
	 * Creates or reuses a shared server-side NC consumer admin object.
	 * 
	 * @throws AcsJException
	 */
private ConsumerAdmin getSharedAdmin() throws AcsJCORBAProblemEx, AcsJNarrowFailedEx {
    ConsumerAdmin ret = null;
    org.omg.CosNotifyChannelAdmin.ConsumerAdmin retBase = null;
    boolean created = false;
    int consumerAdminId = -1;
    AdminReuseCompatibilityHack adminReuseCompatibilityHack = new AdminReuseCompatibilityHack(channelName, logger);
    // while in real life we can have concurrent admin creation requests from different processes.
    synchronized (NCSubscriber.class) {
        // Check if we can reuse an already existing consumer admin
        for (int adminId : channel.get_all_consumeradmins()) {
            try {
                org.omg.CosNotifyChannelAdmin.ConsumerAdmin tmpAdmin = channel.get_consumeradmin(adminId);
                if (adminReuseCompatibilityHack.isSharedAdmin(tmpAdmin)) {
                    // (the -1 goes because of the dummy proxy that is attached to the shared admin)
                    if (tmpAdmin.push_suppliers().length - 1 < PROXIES_PER_ADMIN) {
                        retBase = tmpAdmin;
                        consumerAdminId = adminId;
                        break;
                    }
                }
            } catch (AdminNotFound e) {
                logger.log(AcsLogLevel.NOTICE, "Consumer admin with ID='" + adminId + "' not found for channel '" + channelName + "', " + "will continue anyway to search for shared consumer admins", e);
            }
        }
        // If no suitable consumer admin was found, we create a new one 
        if (retBase == null) {
            // create a new consumer admin
            IntHolder consumerAdminIDHolder = new IntHolder();
            // We use filters only on proxy objects, not on admin objects.
            // An admin object without filters will opt to pass all events.
            // We need a logical AND to be used when comparing the event passing decisions
            // made by the set of proxy supplier filters and by the admin object.
            InterFilterGroupOperator adminProxyFilterLogic = InterFilterGroupOperator.AND_OP;
            retBase = channel.new_for_consumers(adminProxyFilterLogic, consumerAdminIDHolder);
            consumerAdminId = consumerAdminIDHolder.value;
            created = true;
        }
    }
    try {
        // cast to TAO extension type
        ret = ConsumerAdminHelper.narrow(retBase);
    } catch (BAD_PARAM ex) {
        if (created) {
            retBase.destroy();
        }
        LOG_NC_TaoExtensionsSubtypeMissing.log(logger, "ConsumerAdmin for channel " + channelName, ConsumerAdminHelper.id(), org.omg.CosNotifyChannelAdmin.ConsumerAdminHelper.id());
        AcsJNarrowFailedEx ex2 = new AcsJNarrowFailedEx(ex);
        ex2.setNarrowType(ConsumerAdminHelper.id());
        throw ex2;
    }
    if (created) {
        // @TODO: Remove this workaround once it is no longer needed.
        adminReuseCompatibilityHack.markAsSharedAdmin(ret);
    }
    LOG_NC_ConsumerAdminObtained_OK.log(logger, consumerAdminId, (created ? "created" : "reused"), clientName, channelName, getNotificationFactoryName());
    return ret;
}
Also used : ConsumerAdmin(gov.sandia.NotifyMonitoringExt.ConsumerAdmin) InterFilterGroupOperator(org.omg.CosNotifyChannelAdmin.InterFilterGroupOperator) BAD_PARAM(org.omg.CORBA.BAD_PARAM) IntHolder(org.omg.CORBA.IntHolder) AcsJNarrowFailedEx(alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx) AdminNotFound(org.omg.CosNotifyChannelAdmin.AdminNotFound)

Example 42 with IntHolder

use of org.omg.CORBA.IntHolder in project narayana by jbosstm.

the class ImplicitArjunaClient 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];
    CurrentImple current = OTSImpleManager.current();
    // pointer the grid object that will be used.
    stack stackVar = null;
    try {
        current.begin();
        try {
            Services serv = new Services(myORB);
            stackVar = stackHelper.narrow(myORB.orb().string_to_object(TestUtility.getService(refFile)));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            TestUtility.fail(e.toString());
        }
        System.out.println("pushing 1 onto stack");
        stackVar.push(1);
        System.out.println("pushing 2 onto stack");
        stackVar.push(2);
    } catch (Exception e) {
        e.printStackTrace(System.err);
        TestUtility.fail(e.toString());
    }
    try {
        current.commit(false);
        current.begin();
        IntHolder val = new IntHolder(-1);
        if (stackVar.pop(val) == 0) {
            System.out.println("popped top of stack " + val.value);
            current.begin();
            stackVar.push(3);
            System.out.println("pushed 3 onto stack. Aborting nested action.");
            current.rollback();
            stackVar.pop(val);
            System.out.println("popped top of stack is " + val.value);
            current.commit(false);
            TestUtility.assertEquals(1, val.value);
        } else {
            TestUtility.fail("Error getting stack value.");
            current.rollback();
        }
    } 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) TestModule.stack(com.hp.mwtests.ts.jts.TestModule.stack) IntHolder(org.omg.CORBA.IntHolder) RootOA(com.arjuna.orbportability.RootOA) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB)

Example 43 with IntHolder

use of org.omg.CORBA.IntHolder in project narayana by jbosstm.

the class DistributedHammerWorker1 method get12.

public static void get12(char thr, int level) {
    boolean res = false;
    boolean res1 = false;
    boolean res2 = false;
    IntHolder value1 = new IntHolder(0);
    IntHolder value2 = new IntHolder(0);
    try {
        OTSImpleManager.current().begin();
        Control control = OTSImpleManager.current().get_control();
        Util.indent(thr, level);
        System.out.println("begin   get12");
        res1 = hammerObject_1.get(value1, control);
        res = res1;
        Util.indent(thr, level);
        System.out.println("part1   get12  : " + res1);
        if (res) {
            res2 = hammerObject_2.get(value2, control);
            res = res2;
            Util.indent(thr, level);
            System.out.println("part2   get12  : " + res2);
        }
        control = null;
        Util.indent(thr, level);
        if (res) {
            System.out.print("end ");
            OTSImpleManager.current().commit(true);
        } else {
            System.out.print("abort  ");
            OTSImpleManager.current().rollback();
        }
    } catch (Exception e) {
        System.err.println("DistributedHammerWorker1.get12: " + e);
        res1 = res2 = res = false;
    }
    Util.indent(thr, level);
    System.out.println(" get12  : " + res1 + " : " + res2 + " : " + res + " : " + value1.value + " : " + value2.value);
}
Also used : Control(org.omg.CosTransactions.Control) IntHolder(org.omg.CORBA.IntHolder)

Example 44 with IntHolder

use of org.omg.CORBA.IntHolder 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)

Example 45 with IntHolder

use of org.omg.CORBA.IntHolder in project narayana by jbosstm.

the class ExplicitArjunaClient method main.

public static void main(String[] args) throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    CurrentImple current = OTSImpleManager.current();
    String refFile = args[0];
    int value = 1;
    Control cont = null;
    try {
        System.out.println("Starting initialising top-level transaction.");
        current.begin();
        System.out.println("Initialising transaction name: " + current.get_transaction_name());
    } catch (Exception e) {
        TestUtility.fail(e.toString());
    }
    // pointer the grid object that will be used.
    ExplicitStack stackVar = null;
    try {
        stackVar = ExplicitStackHelper.narrow(myORB.orb().string_to_object(TestUtility.getService(refFile)));
    } catch (Exception e) {
        TestUtility.fail("Bind error: " + e);
    }
    try {
        System.out.println("pushing " + value + " onto stack");
        cont = current.get_control();
        stackVar.push(value, cont);
        System.out.println("\npushing " + (value + 1) + " onto stack");
        stackVar.push(value + 1, cont);
        cont = null;
    } catch (Exception e) {
        TestUtility.fail(e.toString());
    }
    try {
        current.commit(true);
        System.out.println("Committed top-level transaction");
        System.out.println("\nBeginning top-level transaction");
        current.begin();
        System.out.println("Top-level name: " + current.get_transaction_name());
        IntHolder val = new IntHolder(-1);
        cont = current.get_control();
        if (stackVar.pop(val, cont) == 0) {
            System.out.println("popped top of stack " + val.value);
            System.out.println("\nbeginning nested transaction");
            current.begin();
            System.out.println("nested name: " + current.get_transaction_name());
            cont = null;
            cont = current.get_control();
            stackVar.push(value + 2, cont);
            System.out.println("pushed " + (value + 2) + " onto stack. Aborting nested action.");
            // current will destroy this control!
            cont = null;
            current.rollback();
            cont = current.get_control();
            System.out.println("current transaction name: " + current.get_transaction_name());
            System.out.println("rolledback nested transaction");
            stackVar.pop(val, cont);
            System.out.println("\npopped top of stack is " + val.value);
            System.out.println("\nTrying to print stack contents - should fail.");
            stackVar.printStack();
            cont = null;
            current.commit(true);
            System.out.println("\nCommitted top-level transaction");
            if (current.get_transaction_name() == null)
                System.out.println("current transaction name: null");
            else
                System.out.println("Error - current transaction name: " + current.get_transaction_name());
            TestUtility.assertEquals(value, val.value);
        } else {
            System.out.println("Error getting stack value.");
            current.rollback();
            System.out.println("\nRolledback top-level transaction.");
        }
        try {
            System.out.println("\nPrinting stack contents (should be empty).");
            stackVar.printStack();
        } catch (Exception e) {
            TestUtility.fail("\nError - could not print.");
        }
    } catch (Exception e) {
        TestUtility.fail("Caught unexpected exception: " + e);
    }
    myOA.destroy();
    myORB.shutdown();
    System.out.println("Passed");
}
Also used : ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Control(org.omg.CosTransactions.Control) IntHolder(org.omg.CORBA.IntHolder) RootOA(com.arjuna.orbportability.RootOA) ExplicitStack(com.hp.mwtests.ts.jts.TestModule.ExplicitStack) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB)

Aggregations

IntHolder (org.omg.CORBA.IntHolder)72 AtomicTransaction (com.arjuna.ats.jts.extensions.AtomicTransaction)12 Control (org.omg.CosTransactions.Control)10 ORB (com.arjuna.orbportability.ORB)6 RootOA (com.arjuna.orbportability.RootOA)6 HitCountRequest (org.codice.alliance.nsili.common.GIAS.HitCountRequest)6 Services (com.arjuna.orbportability.Services)5 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)5 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)4 NameAlreadyUsed (gov.sandia.NotifyMonitoringExt.NameAlreadyUsed)3 NameMapError (gov.sandia.NotifyMonitoringExt.NameMapError)3 Test (org.junit.Test)3 BAD_PARAM (org.omg.CORBA.BAD_PARAM)3 AdminLimitExceeded (org.omg.CosNotifyChannelAdmin.AdminLimitExceeded)3 AcsJNarrowFailedEx (alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx)2 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)2 SubmitQueryRequest (org.codice.alliance.nsili.common.GIAS.SubmitQueryRequest)2 DAGListHolder (org.codice.alliance.nsili.common.UCO.DAGListHolder)2 InvalidInputParameter (org.codice.alliance.nsili.common.UCO.InvalidInputParameter)2 ProcessingFault (org.codice.alliance.nsili.common.UCO.ProcessingFault)2