in uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java [224:383]
public void initializeAnalysisEngine() throws ResourceInitializationException {
ResourceSpecifier rSpecifier = null;
try {
// Acquire single-permit semaphore to serialize instantiation of AEs.
// This is done to control access to non-thread safe structures in the
// core. The sharedInitSemaphore is a static and is shared by all instances
// of this class.
sharedInitSemaphore.acquire();
// Parse the descriptor in the calling thread.
rSpecifier = UimaClassFactory.produceResourceSpecifier(super.aeDescriptor);
UimaContextAdmin uctx = null;
if ( parentController != null ) {
int scaleout = 1;
if (parentController instanceof AggregateAnalysisEngineController) {
String key = ((AggregateAnalysisEngineController) parentController)
.lookUpDelegateKey(endpointName);
if (key == null) {
if (((AggregateAnalysisEngineController) parentController).isDelegateKeyValid(endpointName)) {
key = endpointName;
}
}
if (key == null) {
throw new AsynchAEException(getName() + "-Unable to look up delegate "
+ endpointName + " in internal map");
}
Delegate d = ((AggregateAnalysisEngineController) parentController)
.lookupDelegate(key);
scaleout = d.getEndpoint().getConcurrentRequestConsumers();
}
if ( scaleout > 1) {
uctx = (UimaContextAdmin)parentController.getChildUimaContext(endpointName);
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) {
dumpContext(uctx);
}
paramsMap.remove(Resource.PARAM_UIMA_CONTEXT);
paramsMap.put(Resource.PARAM_UIMA_CONTEXT, uctx);
} else {
uctx = (UimaContextAdmin)paramsMap.get(Resource.PARAM_UIMA_CONTEXT);
}
}
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(rSpecifier, paramsMap);
super.addUimaObject(ae.getManagementInterface().getUniqueMBeanName());
// Call to produceAnalysisEngine() may take a long time to complete. While this
// method was executing, the service may have been stopped. Before continuing
// check if the service has been stopped. If so, destroy AE instance and return.
if ( isStopped() ) {
ae.destroy();
return;
}
if (aeInstancePool == null) {
aeInstancePool = new AnalysisEngineInstancePoolWithThreadAffinity();//analysisEnginePoolSize);
}
if (analysisEngineMetadata == null) {
analysisEngineMetadata = ae.getAnalysisEngineMetaData();
}
// Check if OperationalProperties allow replication of this AE. Throw exception if
// the deployment descriptor says to scale the service *but* the AE descriptor's
// OperationalProperties disallow it.
if ( !analysisEngineMetadata.getOperationalProperties().isMultipleDeploymentAllowed() &&
aeInstancePool.size() >= 1 ) {
throw new ResourceInitializationException( UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_multiple_deployment_not_allowed__WARNING", new Object[] {this.getComponentName(), ae.getMetaData().getName()});
}
aeInstancePool.checkin(ae);
if (!isStopped() && !casPoolInited) {
casPoolInited = true;
if (errorHandlerChain == null) {
super.plugInDefaultErrorHandlerChain();
}
getMonitor().setThresholds(getErrorHandlerChain().getThresholds());
// Initialize Cas Manager
if (getCasManagerWrapper() != null) {
try {
// Below should always be true. In spring context file AsynchAECasManager_impl
// is instantiated and setCasPoolSize() method is called which sets the
// initialized state = true. isInitialized() returning true just means that
// setCasPoolSize() was called.
if (getCasManagerWrapper().isInitialized()) {
getCasManagerWrapper().addMetadata(getAnalysisEngineMetadata());
if (isTopLevelComponent()) {
getCasManagerWrapper().initialize("PrimitiveAEService");
CAS cas = getCasManagerWrapper().getNewCas("PrimitiveAEService");
cas.release();
}
}
} catch( Exception e) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
"postInitialize", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_service_exception_WARNING", getComponentName());
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, getClass().getName(),
"postInitialize", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_exception__WARNING", e);
}
throw new AsynchAEException(e);
}
}
}
String warmUpDataPath=null;
// start warm up engine which will prime pipeline analytics
if ( isTopLevelComponent() && (warmUpDataPath = System.getProperty("WarmUpDataPath")) != null ) {
CountDownLatch warmUpLatch = new CountDownLatch(1);
warmUp(warmUpDataPath, warmUpLatch);
warmUpLatch.await();
}
if (aeInstancePool.size() == analysisEnginePoolSize) {
try {
postInitialize();
} catch (Exception e) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
"initializeAnalysisEngine", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_service_exception_WARNING", getComponentName());
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, getClass().getName(),
"initializeAnalysisEngine", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_exception__WARNING", e);
}
throw new ResourceInitializationException(e);
}
}
} catch (Exception e) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
"initializeAnalysisEngine", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_service_exception_WARNING", getComponentName());
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, getClass().getName(),
"initializeAnalysisEngine", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_exception__WARNING", e);
}
super.notifyListenersWithInitializationStatus(e);
if (isTopLevelComponent()) {
super.notifyListenersWithInitializationStatus(e);
} else {
// get the top level controller to notify
AnalysisEngineController controller = this.getParentController();
while (!controller.isTopLevelComponent()) {
controller = controller.getParentController();
}
getParentController().notifyListenersWithInitializationStatus(e);
}
throw new ResourceInitializationException(e);
} finally {
// Release the shared semaphore so that another instance of this class can instantiate
// an Analysis Engine.
sharedInitSemaphore.release();
}
}