* keeps track of time spent in each component
*/
protected void callAnalysisComponentProcess(CAS aCAS) throws AnalysisEngineProcessException {
// logging and instrumentation
String resourceName = getMetaData().getName();
Logger logger = getLogger();
logger.logrb(Level.FINE, CLASS_NAME.getName(), "process", LOG_RESOURCE_BUNDLE,
"UIMA_analysis_engine_process_begin__FINE", resourceName);
try {
CAS view = null;
// call Annotator's process method
try {
// Get the right view of the CAS. Sofa-aware components get the base CAS.
// Sofa-unaware components get whatever is mapped to the _InitialView.
view = Util.getStartingView(aCAS, mSofaAware, getUimaContextAdmin().getComponentInfo());
// now get the right interface(e.g. CAS or JCAS)
// must precede the switchClassLoader call below UIMA-2211
Class<? extends AbstractCas> requiredInterface = mAnalysisComponent.getRequiredCasInterface();
AbstractCas casToPass = getCasManager().getCasInterface(view, requiredInterface);
// check if there was a change in the ResultSpecification or in
// the TypeSystem. If so, set the changed type system into the ResultSpecification and
// inform the component
if (mResultSpecChanged || mLastTypeSystem != view.getTypeSystem()) {
if (mLastTypeSystem != view.getTypeSystem()) {
mLastTypeSystem = view.getTypeSystem();
mCurrentResultSpecification.setTypeSystem(mLastTypeSystem);
rsFromOutputCapabilities = new ResultSpecification_impl(mLastTypeSystem);
rsFromOutputCapabilities.addCapabilities(this.getAnalysisEngineMetaData().getCapabilities());
}
// the actual ResultSpec we send to the component is formed by
// looking at this primitive AE's declared output types and eliminating
// any that are not in mCurrentResultSpecification.
ResultSpecification analysisComponentResultSpec =
((ResultSpecification_impl)mCurrentResultSpecification).intersect((ResultSpecification_impl)rsFromOutputCapabilities);
mAnalysisComponent.setResultSpecification(analysisComponentResultSpec);
mResultSpecChanged = false;
}
// insure view is passed to switch / restore class loader https://issues.apache.org/jira/browse/UIMA-2211
((CASImpl)view).switchClassLoaderLockCasCL(this.getResourceManager().getExtensionClassLoader());
// call the process method
mAnalysisComponent.process(casToPass);
getMBean().incrementCASesProcessed();
//note we do not clear the CAS's currentComponentInfo at this time
// nor do we unlock the cas and switch it back (class loader-wise). The AnalysisComponents still
//can access the CAS until such time as its hasNext method returns false. Thus is is the
//AnalysisComponentCasIterator that knows when it is time to clear the currentComponentInfo.
} catch (Exception e) {
// catching Throwable to catch out-of-memory errors too, which are not Exceptions
if (null != view) {
view.setCurrentComponentInfo(null);
((CASImpl)view).restoreClassLoaderUnlockCas();
}
if (e instanceof AnalysisEngineProcessException) {
throw (AnalysisEngineProcessException) e;
} else {
throw new AnalysisEngineProcessException(
AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, null, e);
}
} catch (Error e) { // out of memory error, for instance
if (null != view) {
view.setCurrentComponentInfo(null);
((CASImpl)view).restoreClassLoaderUnlockCas();
}
throw e;
}
// log end of event
logger.logrb(Level.FINE, CLASS_NAME.getName(), "process", LOG_RESOURCE_BUNDLE,
"UIMA_analysis_engine_process_end__FINE", resourceName);
} catch (Exception e) {
// log and rethrow exception
logger.log(Level.SEVERE, "", e);
if (e instanceof AnalysisEngineProcessException)
throw (AnalysisEngineProcessException) e;
else
throw new AnalysisEngineProcessException(e);
}