Search in sources :

Example 26 with POA

use of org.omg.PortableServer.POA 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)

Example 27 with POA

use of org.omg.PortableServer.POA in project ACS by ACS-Community.

the class SyncDummyComponentImpl method _testComponentPOALifecycle.

/**
	 * This test method can also be used to experiment with 
	 * @param destroyWhileBusy
	 * @param iterations
	 * @throws Exception
	 */
private void _testComponentPOALifecycle(boolean destroyWhileBusy, int iterations) throws Exception {
    final String compName = "virtualTestComp";
    for (int i = 0; i < iterations; i++) {
        m_logger.info("Will create and destroy component instance #" + i);
        final POA compPOA = acsCorba.createPOAForComponent(compName);
        assertNotNull(compPOA);
        // create a test component servant using that POA
        final SyncDummyComponentImpl impl = new SyncDummyComponentImpl();
        Servant servant = new DummyComponentPOATie(impl);
        final ComponentServantManager servantManager = acsCorba.setServantManagerOnComponentPOA(compPOA);
        // activate the component 
        org.omg.CORBA.Object objRef = acsCorba.activateComponent(servant, compName, compPOA);
        // make a simple CORBA call to the component, and then destroy the POA
        final DummyComponent testCompRef = DummyComponentHelper.narrow(objRef);
        testCompRef.dummyComponentsCanDoCloseToNothing();
        if (destroyWhileBusy) {
            final CountDownLatch sync = new CountDownLatch(1);
            impl.setMethodCallSync(sync);
            Runnable compMethodCallRunnable = new Runnable() {

                public void run() {
                    try {
                        testCompRef.callThatTakesSomeTime(1000);
                    } catch (Exception ex) {
                        exceptionInThread = ex;
                    }
                }
            };
            m_logger.info("Will destroy component POA while active request is still running.");
            (new Thread(compMethodCallRunnable)).start();
            boolean properSync = sync.await(10000, TimeUnit.MILLISECONDS);
            assertTrue(properSync);
        } else {
            testCompRef.callThatTakesSomeTime(0);
        }
        // timeout should be larger than pending call (callThatTakesSomeTime)
        boolean isInactive = acsCorba.deactivateComponentPOAManager(compPOA, compName, 2000);
        assertTrue(isInactive);
        // active calls are supposedly over already, so the timeout can be smaller than execution time for "callThatTakesSomeTime"
        boolean isEtherealized = acsCorba.destroyComponentPOA(compPOA, servantManager, 500);
        assertTrue("Timeout here probably means that 'deactivateComponentPOAManager' did not properly wait for active requests to finish.", isEtherealized);
        if (exceptionInThread != null) {
            fail("asynchronous component call (#callThatTakesSomeTime) failed: " + exceptionInThread.toString());
        }
    }
    m_logger.info("Done with testComponentPOALifecycle()");
}
Also used : ComponentServantManager(alma.acs.container.ComponentServantManager) POA(org.omg.PortableServer.POA) CountDownLatch(java.util.concurrent.CountDownLatch) Servant(org.omg.PortableServer.Servant) DummyComponent(alma.jconttest.DummyComponent) DummyComponentPOATie(alma.jconttest.DummyComponentPOATie)

Example 28 with POA

use of org.omg.PortableServer.POA in project ACS by ACS-Community.

the class WDAOImpl method destroy.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.DAOOperations#destroy()
	 */
public void destroy() {
    daoImpl.destroy();
    try {
        POA poa = getPOA();
        byte[] thisId = poa.servant_to_id(this);
        poa.deactivate_object(thisId);
    } catch (Exception e) {
        m_logger.log(AcsLogLevel.NOTICE, "Exception destroying object " + this + " : " + e);
        e.printStackTrace();
    }
}
Also used : WDAOPOA(com.cosylab.CDB.WDAOPOA) POA(org.omg.PortableServer.POA)

Example 29 with POA

use of org.omg.PortableServer.POA in project ACS by ACS-Community.

the class CharacteristicModelImpl method get_all_characteristics.

/**
	 * @see alma.ACS.CharacteristicModelOperations#get_all_characteristics()
	 */
public PropertySet get_all_characteristics() {
    String[] allSeq;
    try {
        if (prefix == "")
            allSeq = dao.get_string_seq("");
        else
            allSeq = dao.get_string_seq(prefix);
        Property[] p = new Property[allSeq.length];
        for (int i = 0; i < allSeq.length; i++) {
            Any a = get_characteristic_by_name(allSeq[i]);
            p[i] = new Property(allSeq[i], a);
        }
        //dangerous methods!! 
        ORB orb = m_container.getAdvancedContainerServices().getORB();
        POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        rootpoa.the_POAManager().activate();
        PropertySetImpl psetImpl = new PropertySetImpl(p);
        PropertySetPOATie psetTie = new PropertySetPOATie(psetImpl, rootpoa);
        return psetTie._this(orb);
    } catch (CDBFieldDoesNotExistEx e) {
    } catch (WrongCDBDataTypeEx e) {
    } catch (NoSuchCharacteristic e) {
    } catch (MultipleExceptions e) {
    } catch (InvalidName e) {
    } catch (AdapterInactive e) {
    } catch (NullPointerException e) {
        System.out.println(e);
    }
    throw new NO_IMPLEMENT();
}
Also used : NO_IMPLEMENT(org.omg.CORBA.NO_IMPLEMENT) POA(org.omg.PortableServer.POA) NoSuchCharacteristic(alma.ACS.NoSuchCharacteristic) AdapterInactive(org.omg.PortableServer.POAManagerPackage.AdapterInactive) Any(org.omg.CORBA.Any) PropertySetImpl(alma.ACS.jbaci.PropertySetImpl) PropertySetPOATie(org.omg.CosPropertyService.PropertySetPOATie) InvalidName(org.omg.CORBA.ORBPackage.InvalidName) CDBFieldDoesNotExistEx(alma.cdbErrType.CDBFieldDoesNotExistEx) MultipleExceptions(org.omg.CosPropertyService.MultipleExceptions) Property(org.omg.CosPropertyService.Property) ORB(org.omg.CORBA.ORB) WrongCDBDataTypeEx(alma.cdbErrType.WrongCDBDataTypeEx)

Example 30 with POA

use of org.omg.PortableServer.POA in project ACS by ACS-Community.

the class AcsCorba method deactivateOffShoot.

public void deactivateOffShoot(Servant servant, POA compPOA) throws AcsJContainerEx {
    if (servant == null || compPOA == null) {
        String msg = "deactivateOffShoot called with missing parameter.";
        AcsJContainerEx ex = new AcsJContainerEx();
        ex.setContextInfo(msg);
        throw ex;
    }
    byte[] id = null;
    try {
        POA offshootPoa = getPOAForOffshoots(compPOA);
        id = offshootPoa.servant_to_id(servant);
        offshootPoa.deactivate_object(id);
    } catch (AcsJContainerEx e) {
        throw e;
    } catch (Throwable thr) {
        String msg = "failed to deactivate offshoot of type '" + servant.getClass().getName() + "' (ID=" + String.valueOf(id) + ")";
        m_logger.log(Level.WARNING, msg, thr);
        AcsJContainerEx ex = new AcsJContainerEx(thr);
        ex.setContextInfo(msg);
        throw ex;
    }
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) POA(org.omg.PortableServer.POA)

Aggregations

POA (org.omg.PortableServer.POA)33 ORB (org.omg.CORBA.ORB)11 POAManager (org.omg.PortableServer.POAManager)10 AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)6 Properties (java.util.Properties)5 ClientPOA (si.ijs.maci.ClientPOA)5 Servant (org.omg.PortableServer.Servant)4 ManagerImpl (com.cosylab.acs.maci.manager.ManagerImpl)3 AcsJUnexpectedExceptionEx (alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx)2 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)2 AcsJException (alma.acs.exceptions.AcsJException)2 AcsLogger (alma.acs.logging.AcsLogger)2 AcsORBProfilerImplBase (alma.acs.profiling.orb.AcsORBProfilerImplBase)2 CDBFieldDoesNotExistEx (alma.cdbErrType.CDBFieldDoesNotExistEx)2 WrongCDBDataTypeEx (alma.cdbErrType.WrongCDBDataTypeEx)2 DummyComponent (alma.jconttest.DummyComponent)2 DummyComponentPOATie (alma.jconttest.DummyComponentPOATie)2 WDAOPOA (com.cosylab.CDB.WDAOPOA)2 HandleDataStore (com.cosylab.acs.maci.manager.HandleDataStore)2 FileWriter (java.io.FileWriter)2