use of org.omg.PortableServer.Servant 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);
}
use of org.omg.PortableServer.Servant 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()");
}
use of org.omg.PortableServer.Servant in project ACS by ACS-Community.
the class DALImpl method get_DAO_Servant.
/**
* create DAO servant with requested XML
*/
public synchronized DAO get_DAO_Servant(String curl) throws CDBRecordDoesNotExistEx, CDBXMLErrorEx {
totalDALInvocationCounter.incrementAndGet();
// make sure CURL->DAO mapping is surjective function, remove leading slash
if (curl.length() > 1 && curl.charAt(0) == '/')
curl = curl.substring(1);
// make sure there are no identical DAOs created
synchronized (daoMap) {
if (daoMap.containsKey(curl))
return daoMap.get(curl);
}
// do the hardwork here
XMLHandler xmlSolver;
try {
xmlSolver = loadRecords(curl, false);
} catch (AcsJCDBXMLErrorEx e) {
// @todo watch if this log also needs a repeat guard, similar to logRecordNotExistWithRepeatGuard
m_logger.log(AcsLogLevel.NOTICE, "Failed to read curl '" + curl + "'.", e);
throw e.toCDBXMLErrorEx();
} catch (AcsJCDBRecordDoesNotExistEx e) {
logRecordNotExistWithRepeatGuard(curl);
throw e.toCDBRecordDoesNotExistEx();
}
if (xmlSolver == null) {
// @TODO can this happen? Should we not throw an exception then?
return null;
}
try {
DAO href = null;
// bind to map
synchronized (daoMap) {
// execution when different DAO are created
if (daoMap.containsKey(curl))
return daoMap.get(curl);
final DAOImpl servantDelegate = new DAOImpl(curl, xmlSolver.m_rootNode, poa, m_logger);
DAOOperations topLevelServantDelegate = servantDelegate;
if (Boolean.getBoolean(Server.LOG_CDB_CALLS_PROPERTYNAME)) {
// Currently we only intercept the functional IDL-defined methods, by wrapping servantDelegate.
// If we want to also intercept the CORBA admin methods, then *servant* below should be wrapped with a dynamic proxy instead.
DAOOperations interceptingServantDelegate = SimpleCallInterceptor.createSimpleInterceptor(DAOOperations.class, servantDelegate, m_logger);
topLevelServantDelegate = interceptingServantDelegate;
}
final Servant servant = new DAOPOATie(topLevelServantDelegate);
// create object id.
// Note that the ID *must* be derived from the curl, because DAOImpl#destroy will do the same in POA#deactivate_object.
byte[] id = curl.getBytes();
// activate object
poa.activate_object_with_id(id, servant);
href = DAOHelper.narrow(poa.servant_to_reference(servant));
// map DAO reference
daoMap.put(curl, href);
}
m_logger.log(AcsLogLevel.DEBUG, "Returning DAO servant for: " + curl);
return href;
} catch (Throwable t) {
String info = "DAO::get_DAO_Servant " + t;
AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
xmlErr.setErrorString(info);
m_logger.log(AcsLogLevel.NOTICE, info);
throw xmlErr.toCDBXMLErrorEx();
}
}
use of org.omg.PortableServer.Servant in project ACS by ACS-Community.
the class AlarmSystemContainerServices method deactivateOffShoot.
@Override
public void deactivateOffShoot(Object offshootImpl) throws AcsJContainerServicesEx {
if (offshootImpl instanceof Servant) {
Servant cbServant = (Servant) offshootImpl;
try {
checkOffShootServant(cbServant);
POA rootPOA = alSysCorbaServer.getRootPOA();
if (cbServant == null || rootPOA == null) {
String msg = "deactivateOffShoot called with missing parameter.";
AcsJContainerEx ex = new AcsJContainerEx();
ex.setContextInfo(msg);
throw ex;
}
byte[] id = null;
try {
POA offshootPoa = getPOAForOffshoots(rootPOA);
id = offshootPoa.servant_to_id(cbServant);
offshootPoa.deactivate_object(id);
} catch (AcsJContainerEx e) {
throw e;
} catch (Throwable thr) {
String msg = "failed to deactivate offshoot of type '" + cbServant.getClass().getName() + "' (ID=" + String.valueOf(id) + ")";
logger.log(Level.WARNING, msg, thr);
AcsJContainerEx ex = new AcsJContainerEx(thr);
ex.setContextInfo(msg);
throw ex;
}
} catch (AcsJContainerEx ex) {
throw new AcsJContainerServicesEx(ex);
}
} else {
AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
ex.setContextInfo("Not yet implemented");
throw ex;
}
}
use of org.omg.PortableServer.Servant in project ACS by ACS-Community.
the class AlarmSystemCorbaServer method instantiateCernAS.
/**
* Instantiate the CERN alarm service.
* <P>
* At this point the CERN class are still unknown because they are built
* very late in ACS.
* Therefore the CERN alarm system is instantiated dynamically.
*
* @return The CERN alarm service
*/
private Servant instantiateCernAS() throws Exception {
Thread t = Thread.currentThread();
ClassLoader loader = t.getContextClassLoader();
Class cl = loader.loadClass("alma.alarmsystem.corbaservice.AlarmSystemContainerServices");
Class[] classes = { AlarmSystemCorbaServer.class, AcsLogger.class };
Constructor constructor = cl.getConstructor(classes);
java.lang.Object contSvcs = constructor.newInstance(AlarmSystemCorbaServer.this, m_logger);
m_logger.log(AcsLogLevel.DEBUG, "Built the alarm system implementation of ContainerServices");
m_logger.log(AcsLogLevel.INFO, "Activating the CERN alarm service");
Class laserCL = loader.loadClass("com.cosylab.acs.laser.LaserComponent");
Class[] laserClasses = { AlarmSystemCorbaServer.class, contSvcs.getClass() };
Constructor ctor = laserCL.getConstructor(laserClasses);
return (Servant) ctor.newInstance(AlarmSystemCorbaServer.this, contSvcs);
}
Aggregations