Search in sources :

Example 1 with DummyComponentImpl

use of alma.jconttest.DummyComponentImpl.DummyComponentImpl in project ACS by ACS-Community.

the class SyncDummyComponentImpl method testPOAConfig.

public void testPOAConfig() throws Exception {
    final String compName = "virtualTestComp";
    POA compPOA = acsCorba.createPOAForComponent(compName);
    org.jacorb.poa.POA jacCompPOA = null;
    if (compPOA instanceof org.jacorb.poa.POA) {
        jacCompPOA = (org.jacorb.poa.POA) compPOA;
    } else {
        fail("this test is only meant for JacORB. Instead the POA impl is of type " + compPOA.getClass().getName());
    }
    //		Policy threadPolicy = jacCompPOA.getPolicy(THREAD_POLICY_ID.value);
    //		assertNotNull(threadPolicy); // currently null, which defaults to ORB_CTRL_MODEL (see POA#sSingleThreadModel())
    assertTrue(jacCompPOA.isUseServantManager());
    String theName = jacCompPOA.the_name();
    assertEquals("unexpected poa name ", "ComponentPOA_" + compName, theName);
    String qualName = jacCompPOA._getQualifiedName();
    assertEquals("unexpected qualified poa name ", "ComponentPOA/ComponentPOA_" + compName, qualName);
    String poaId = new String(jacCompPOA.getPOAId());
    assertEquals("unexpected poaId ", "StandardImplName/ComponentPOA/ComponentPOA_" + compName, poaId);
    // create a thread-aware test component servant using that POA
    DummyComponentImpl impl = new DummyComponentImpl() {

        public void dummyComponentsCanDoCloseToNothing() {
            Thread orbThread = Thread.currentThread();
            System.out.println("component called in thread " + orbThread.getName());
        }
    };
    Servant servant = new DummyComponentPOATie(impl);
    // activate the component 
    org.omg.CORBA.Object objRef = acsCorba.activateComponent(servant, compName, compPOA);
    // make CORBA calls to the component , and destroy the POA
    DummyComponent testCompRef = DummyComponentHelper.narrow(objRef);
    testCompRef.dummyComponentsCanDoCloseToNothing();
    // analyze thread structure		
    ThreadGroup rootThreadGroup = Thread.currentThread().getThreadGroup();
    while (rootThreadGroup.getParent() != null) {
        rootThreadGroup = rootThreadGroup.getParent();
    }
    // hopefully large enough 
    ThreadGroup[] allThreadGroups = new ThreadGroup[rootThreadGroup.activeCount() * 2];
    int numThreadGroups = rootThreadGroup.enumerate(allThreadGroups, true);
    for (int i = 0; i < numThreadGroups; i++) {
        System.out.println("thread group " + allThreadGroups[i].getName() + ":");
        // hopefully large enough 
        Thread[] allThreadsInGroup = new Thread[allThreadGroups[i].activeCount() * 2];
        int numThreads = allThreadGroups[i].enumerate(allThreadsInGroup, false);
        for (int j = 0; j < numThreads; j++) {
            System.out.println("\t" + allThreadsInGroup[j].getName());
        }
    }
    compPOA.destroy(false, true);
}
Also used : POA(org.omg.PortableServer.POA) Servant(org.omg.PortableServer.Servant) DummyComponent(alma.jconttest.DummyComponent) DummyComponentImpl(alma.jconttest.DummyComponentImpl.DummyComponentImpl) DummyComponentPOATie(alma.jconttest.DummyComponentPOATie)

Aggregations

DummyComponent (alma.jconttest.DummyComponent)1 DummyComponentImpl (alma.jconttest.DummyComponentImpl.DummyComponentImpl)1 DummyComponentPOATie (alma.jconttest.DummyComponentPOATie)1 POA (org.omg.PortableServer.POA)1 Servant (org.omg.PortableServer.Servant)1