Search in sources :

Example 1 with ComponentQueryDescriptor

use of alma.acs.component.ComponentQueryDescriptor in project ACS by ACS-Community.

the class ContainerServicesImpl method getCollocatedComponent.

public org.omg.CORBA.Object getCollocatedComponent(String compUrl, String targetCompUrl) throws AcsJContainerServicesEx {
    if (compUrl == null) {
        AcsJBadParameterEx cause = new AcsJBadParameterEx();
        cause.setParameter("compUrl");
        cause.setParameterValue("null");
        throw new AcsJContainerServicesEx(cause);
    }
    if (targetCompUrl == null) {
        AcsJBadParameterEx cause = new AcsJBadParameterEx();
        cause.setParameter("targetCompUrl");
        cause.setParameterValue("null");
        throw new AcsJContainerServicesEx(cause);
    }
    ComponentQueryDescriptor cqd = new ComponentQueryDescriptor(compUrl, null);
    return getCollocatedComponent(cqd, false, targetCompUrl);
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) ComponentQueryDescriptor(alma.acs.component.ComponentQueryDescriptor) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Example 2 with ComponentQueryDescriptor

use of alma.acs.component.ComponentQueryDescriptor in project ACS by ACS-Community.

the class ContainerServicesTesterImpl method testGetDynamicDummyComponent.

/**
	 * @see alma.jconttest.ContainerServicesTesterOperations#testGetDynamicDummyComponent(org.omg.CORBA.StringHolder)
	 */
public boolean testGetDynamicDummyComponent(StringHolder compName) {
    boolean ret = false;
    try {
        ComponentQueryDescriptor compQueryDesc = new ComponentQueryDescriptor();
        //			compQueryDesc.setComponentName(ComponentQueryDescriptor.ANY);
        compQueryDesc.setComponentType(DummyComponentHelper.DUMMYCOMPONENT_CORBATYPE);
        org.omg.CORBA.Object compObj = m_containerServices.getDynamicComponent(compQueryDesc, false);
        DummyComponent dummyComp = alma.jconttest.DummyComponentHelper.narrow(compObj);
        // return the name that was dynamically assigned
        compName.value = dummyComp.name();
        m_logger.info("received dynamic instance of " + DummyComponentHelper.DUMMYCOMPONENT_CORBATYPE);
        // now check the component descriptor
        ComponentDescriptor compDesc = m_containerServices.getComponentDescriptor(compName.value);
        m_logger.info("Component data: " + compDesc.toString());
        m_containerServices.releaseComponent(dummyComp.name());
        ret = true;
    } catch (Exception e) {
        // todo: IDL ex
        m_logger.warning(e.toString());
        // prevent CORBA marshalling ex
        compName.value = "!!!failed!!!";
    }
    return ret;
}
Also used : DummyComponent(alma.jconttest.DummyComponent) ComponentDescriptor(alma.acs.component.ComponentDescriptor) ComponentQueryDescriptor(alma.acs.component.ComponentQueryDescriptor)

Example 3 with ComponentQueryDescriptor

use of alma.acs.component.ComponentQueryDescriptor in project ACS by ACS-Community.

the class AcsCorbaTestWithContainer method _testComponentPOALifecycle.

/**
	 * @param destroyWhileBusy
	 * @param iterations
	 * @throws Exception
	 */
private void _testComponentPOALifecycle(boolean destroyWhileBusy, int iterations) throws Exception {
    // times in milliseconds
    final int remoteCallDurationMin = (destroyWhileBusy ? 2000 : 0);
    final int callOverheadMax = 600;
    for (int i = 0; i < iterations; i++) {
        m_logger.info("Will create, use and destroy component instance #" + i);
        org.omg.CORBA.Object compObj = getContainerServices().getDynamicComponent(new ComponentQueryDescriptor(null, DUMMYCOMP_TYPENAME), false);
        assertNotNull(compObj);
        dummyComponent = DummyComponentHelper.narrow(compObj);
        String compName = dummyComponent.name();
        assertNotNull(compName);
        exceptionInThread = null;
        // make CORBA calls to the component, and have it destroyed
        dummyComponent.dummyComponentsCanDoCloseToNothing();
        if (destroyWhileBusy) {
            Runnable compMethodCallRunnable = new Runnable() {

                public void run() {
                    try {
                        dummyComponent.callThatTakesSomeTime(remoteCallDurationMin);
                    } catch (Exception ex) {
                        m_logger.log(Level.SEVERE, "Async client call 'dummyComponent#callThatTakesSomeTime' failed with exception.", ex);
                        exceptionInThread = ex;
                    }
                }
            };
            m_logger.info("Will release component while active request is still running.");
            (new Thread(compMethodCallRunnable)).start();
            // Sleep a bit so that we are sure the component method 'callThatTakesSomeTime' is executing (=sleeping).
            // TODO: use proper synchronization to wait until dymmyComponent has received the call to 'callThatTakesSomeTime'
            // this could be done using ACS callbacks.
            Thread.sleep(callOverheadMax);
        } else {
            dummyComponent.callThatTakesSomeTime(remoteCallDurationMin);
        }
        // we expect the releaseComponent call to take some time, because the container must wait for the 
        // currently active call to finish before the component can be unloaded.
        // Without any call and container overhead, the component is busy already for as long as we slept (=callOverheadMax).
        // In that case we should measure timeReleaseCompCall == remoteCallDurationMin-callOverheadMax.
        // Any overhead in the 'callThatTakesSomeTime' and the return of 'releaseComponent' only increases the measured timeReleaseCompCall.
        // When running the test, we still see occasional failures of returning a few milliseconds too early.
        // 2012-06-13: Assuming that these errors come from granularity issues with the timer and that measuring nanoseconds 
        // will improve this situation, we change from System.currentTimeMillis diffs to using System.nanoTime().
        long timeBeforeRelease = System.nanoTime();
        getContainerServices().releaseComponent(compName);
        int timeReleaseCompCallMillis = (int) ((System.nanoTime() - timeBeforeRelease) / 1000000);
        int timeReleaseCompCallMillisExpectedMin = remoteCallDurationMin - callOverheadMax;
        int timeReleaseCompCallMillisExpectedMax = timeReleaseCompCallMillisExpectedMin + 2 * callOverheadMax;
        if (destroyWhileBusy) {
            assertTrue("Releasing component '" + compName + "' took " + timeReleaseCompCallMillis + " ms, when between " + timeReleaseCompCallMillisExpectedMin + " ms and " + timeReleaseCompCallMillisExpectedMax + " were expected.", timeReleaseCompCallMillis >= remoteCallDurationMin - callOverheadMax && timeReleaseCompCallMillis <= timeReleaseCompCallMillisExpectedMax);
        }
        if (exceptionInThread != null) {
            fail("asynchronous component call number " + i + " (callThatTakesSomeTime) failed: " + exceptionInThread.toString());
        }
    }
}
Also used : ComponentQueryDescriptor(alma.acs.component.ComponentQueryDescriptor)

Example 4 with ComponentQueryDescriptor

use of alma.acs.component.ComponentQueryDescriptor in project ACS by ACS-Community.

the class AcsCorbaTestWithContainer method testParallelCalls.

public void testParallelCalls() throws Exception {
    org.omg.CORBA.Object compObj = getContainerServices().getDynamicComponent(new ComponentQueryDescriptor(null, DUMMYCOMP_TYPENAME), false);
    assertNotNull(compObj);
    dummyComponent = DummyComponentHelper.narrow(compObj);
    String compName = dummyComponent.name();
    assertNotNull(compName);
    exceptionInThread = null;
    // run a call to 'callThatTakesSomeTime' from a client thread
    Runnable compMethodCallRunnable = new Runnable() {

        public void run() {
            try {
                dummyComponent.callThatTakesSomeTime(2000);
            } catch (Exception ex) {
                m_logger.log(Level.SEVERE, "Async client call 'dummyComponent#callThatTakesSomeTime' failed with exception.", ex);
                exceptionInThread = ex;
            }
        }
    };
    (new Thread(compMethodCallRunnable)).start();
    // now run another call from the main thread
    // just to make sure the first call is out
    Thread.sleep(500);
    compMethodCallRunnable.run();
    // some other parallel call that uses ContainerServices
    getContainerServices().getDynamicComponent(new ComponentQueryDescriptor(null, DUMMYCOMP_TYPENAME), false);
    assertNull("got an exception in the first of two calls", exceptionInThread);
}
Also used : ComponentQueryDescriptor(alma.acs.component.ComponentQueryDescriptor)

Example 5 with ComponentQueryDescriptor

use of alma.acs.component.ComponentQueryDescriptor in project ACS by ACS-Community.

the class ContainerServicesTesterImpl method testGetCollocatedComponent.

public void testGetCollocatedComponent(String curl, String compType, String targetCurl) throws CouldntPerformActionEx {
    String msg = "component '" + curl + "' of type '" + compType + "' collocated with '" + targetCurl + "'";
    m_logger.info("Received call to testGetCollocatedComponent for " + msg);
    try {
        ComponentQueryDescriptor cqd = new ComponentQueryDescriptor(curl, compType);
        org.omg.CORBA.Object compObj = m_containerServices.getCollocatedComponent(cqd, false, targetCurl);
        if (compObj == null) {
            throw new NullPointerException("Got null reference for " + msg);
        }
        // curl could be given as "*" or null for dynamic name assignment, therefore we ask the name() from the component
        m_containerServices.releaseComponent(ACSComponentHelper.narrow(compObj).name());
    } catch (Throwable thr) {
        throw (new AcsJCouldntPerformActionEx("testGetCollocatedComponent failed for " + msg, thr)).toCouldntPerformActionEx();
    }
}
Also used : AcsJCouldntPerformActionEx(alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx) ComponentQueryDescriptor(alma.acs.component.ComponentQueryDescriptor)

Aggregations

ComponentQueryDescriptor (alma.acs.component.ComponentQueryDescriptor)5 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)1 AcsJCouldntPerformActionEx (alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx)1 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)1 ComponentDescriptor (alma.acs.component.ComponentDescriptor)1 DummyComponent (alma.jconttest.DummyComponent)1