use of alma.acs.container.ComponentServantManager in project ACS by ACS-Community.
the class AcsCorba method setServantManagerOnComponentPOA.
/**
* Creates a servant manager of type <code>ComponentServantManager</code>,
* attaches it to the POA, and activates the servant manager.
* <p>
* This <code>ComponentServantManager</code> can be used as a semaphore to synchronize
* with component etherealization during POA destruction.
* <p>
* Note that {@link org.omg.PortableServer.POAOperations#get_servant_manager()} will not return
* the <code>ComponentServantManager</code> implementation class, but instead a proxy object (_ServantActivatorStub).
* @param componentPOA a component POA
*
* @return the new <code>ComponentServantManager</code>.
* @throws AcsJContainerServicesEx
*/
public ComponentServantManager setServantManagerOnComponentPOA(POA componentPOA) throws AcsJContainerEx {
ComponentServantManager servantManager;
try {
servantManager = new ComponentServantManager(m_logger);
componentPOA.set_servant_manager(servantManager);
} catch (Throwable thr) {
String msg = "Failed to set a servant activator on the component POA " + componentPOA.the_name();
m_logger.log(Level.FINE, msg, thr);
AcsJContainerEx ex = new AcsJContainerEx(thr);
ex.setContextInfo(msg);
throw ex;
}
return servantManager;
}
use of alma.acs.container.ComponentServantManager 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()");
}
Aggregations