org.apache.uima.UimaContextAdmin Java Examples

The following examples show how to use org.apache.uima.UimaContextAdmin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FixedFlowControllerTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  analysisEngineMetaDataMap = new HashMap<>();
  AnalysisEngineMetaData delegateMd = new AnalysisEngineMetaData_impl();
  delegateMd.setOperationalProperties(new OperationalProperties_impl());
  analysisEngineMetaDataMap.put("key1", delegateMd);
  analysisEngineMetaDataMap.put("key2", delegateMd);
  analysisEngineMetaDataMap.put("key3", delegateMd);
  
  AnalysisEngineMetaData aggregateMd = new AnalysisEngineMetaData_impl();
  FixedFlow fixedFlow = new FixedFlow_impl();
  fixedFlow.setFixedFlow(new String[]{"key1", "key2", "key3"});
  aggregateMd.setFlowConstraints(fixedFlow);
  OperationalProperties opProps = new OperationalProperties_impl();
  aggregateMd.setOperationalProperties(opProps);
  
  UimaContextAdmin rootContext = UIMAFramework.newUimaContext(
          UIMAFramework.getLogger(), UIMAFramework.newDefaultResourceManager(),
          UIMAFramework.newConfigurationManager());
  Map<String, String> aSofaMappings = Collections.emptyMap();
  FlowControllerContext fcContext = new FlowControllerContext_impl(
          rootContext, "_FlowController", aSofaMappings,
          analysisEngineMetaDataMap, aggregateMd);
  fixedFlowController = new FixedFlowController();
  fixedFlowController.initialize(fcContext);    
}
 
Example #2
Source File: UimacppAnalysisEngineImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
   * A utility method that performs initialization logic for a primitive AnalysisEngine.
   * 
   * @throws ResourceInitializationException
   *           if an initialization failure occurs
   */
  protected void initializeAnalysisComponent()
          throws ResourceInitializationException {
    // create Annotator Context and set Logger
    UimaContextAdmin uimaContext = getUimaContextAdmin();
    uimaContext.setLogger(UIMAFramework.getLogger(UimacppAnalysisComponent.class));
    mAnnotatorContext = new AnnotatorContext_impl(uimaContext);

    if (!mVerificationMode) {
      mAnnotator = new UimacppAnalysisComponent(mDescription, this);

      getUimaContextAdmin().defineCasPool(mAnnotator.getCasInstancesRequired(),
              getPerformanceTuningSettings(), mSofaAware);

      callInitializeMethod(mAnnotator, uimaContext);
//      mAnnotator.initialize(uimaContext);
    }
  }
 
Example #3
Source File: ExternalResourceInitializer.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Get all resources declared in the context.
 */
private static Collection<?> getResources(UimaContext aContext)
        throws ResourceInitializationException {
  if (!(aContext instanceof UimaContextAdmin)) {
    return Collections.emptyList();
  }

  ResourceManager resMgr = ((UimaContextAdmin) aContext).getResourceManager();
  if (!(resMgr instanceof ResourceManager_impl)) {
    // Unfortunately there is not official way to access the list of resources. Thus we
    // have to rely on the UIMA implementation details and access the internal resource
    // map via reflection. If the resource manager is not derived from the default
    // UIMA resource manager, then we cannot really do anything here.
    throw new IllegalStateException("Unsupported resource manager implementation ["
            + resMgr.getClass() + "]");
  }
  
  return resMgr.getExternalResources();
}
 
Example #4
Source File: ConfigurationParameterInitializer.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize a component from a map.
 *
 * @param component
 *          the component to initialize.
 * @param map
 *          a UIMA context with configuration parameters.
 * @see #initialize(Object, UimaContext)
 * @throws ResourceInitializationException
 *           if a failure occurs during initialization.
 */
public static void initialize(final Object component, final Map<String, Object> map)
        throws ResourceInitializationException {
  // If there is already a ResourceManager then re-use that, otherwise create a new one.
  ResourceManager resMgr;
  if (component instanceof Resource) {
    resMgr = ((Resource) component).getResourceManager();
  } else {
    resMgr = newResourceManager();
  }

  UimaContextAdmin context = newUimaContext(getLogger(), resMgr, newConfigurationManager());

  ConfigurationManager cfgMgr = context.getConfigurationManager();
  cfgMgr.setSession(context.getSession());

  for (Entry<String, Object> e : map.entrySet()) {
    cfgMgr.setConfigParameterValue(context.getQualifiedContextName() + e.getKey(), e.getValue());
  }

  initialize(component, context);
}
 
Example #5
Source File: LocalFeaturesTcAnnotator.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context)
        throws ResourceInitializationException
{
    super.initialize(context);

    try {
        featureExtractors = loadLocalResourceDescriptionOfFeatures(tcModelLocation, context);
        mlAdapter = SaveModelUtils.initMachineLearningAdapter(tcModelLocation);
        featureMode = SaveModelUtils.initFeatureMode(tcModelLocation);
        learningMode = SaveModelUtils.initLearningMode(tcModelLocation);

        validateUimaParameter();

        AnalysisEngineDescription connector = getSaveModelConnector(tcModelLocation.getAbsolutePath(), mlAdapter.getDataWriterClass().toString(),
                learningMode, featureMode, mlAdapter.getFeatureStore(),
                featureExtractors);

        Map<String, Object> additionalParams = new HashMap<>();
        additionalParams.put("language", language);

        // Obtain resource manager from enclosing AE
        ResourceManager mgr = ((UimaContextAdmin) getContext()).getResourceManager();

        engine = UIMAFramework.produceAnalysisEngine(connector,
                mgr, additionalParams);

    }
    catch (Exception e) {
        throw new ResourceInitializationException(e);
    }
}
 
Example #6
Source File: SofaTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testGetViewIterator() throws Exception {
  this.cas.reset();
  CAS view1 = this.cas.createView("View1");
  CAS view2 = this.cas.createView("View2");
  checkViewsExist(this.cas.getViewIterator(), cas, view1, view2);
  
  CAS viewE1 = this.cas.createView("EnglishDocument");
  CAS viewE2 = this.cas.createView("EnglishDocument.2");
  checkViewsExist(this.cas.getViewIterator("EnglishDocument"), viewE1, viewE2);
  
  //try with Sofa mappings
  UimaContextAdmin rootCtxt = UIMAFramework.newUimaContext(
          UIMAFramework.getLogger(), UIMAFramework.newDefaultResourceManager(),
          UIMAFramework.newConfigurationManager());
  Map<String, String> sofamap = new HashMap<>();
  sofamap.put("SourceDocument","EnglishDocument");
  UimaContextAdmin childCtxt = rootCtxt.createChild("test", sofamap);
  cas.setCurrentComponentInfo(childCtxt.getComponentInfo());
  checkViewsExist(this.cas.getViewIterator("SourceDocument"), viewE1, viewE2);
    
  this.cas.setCurrentComponentInfo(null);
  
  //repeat with JCas
  this.cas.reset();
  JCas jcas = this.cas.getJCas();
  JCas jview1 = jcas.createView("View1");
  JCas jview2 = jcas.createView("View2");
  checkViewsExist(jcas.getViewIterator(), jcas, jview1, jview2);
      
  JCas jviewE1 = jcas.createView("EnglishDocument");
  JCas jviewE2 = jcas.createView("EnglishDocument.2");
  checkViewsExist(jcas.getViewIterator("EnglishDocument"), jviewE1, jviewE2);
  
  //try with Sofa mappings
  cas.setCurrentComponentInfo(childCtxt.getComponentInfo());
  checkViewsExist(jcas.getViewIterator("SourceDocument"), jviewE1, jviewE2);
}
 
Example #7
Source File: ASB_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
protected void initFlowController(FlowControllerDeclaration aFlowControllerDeclaration,
        UimaContextAdmin aParentContext, AnalysisEngineMetaData aAggregateMetadata)
        throws ResourceInitializationException {
  String key = aFlowControllerDeclaration.getKey();
  if (key == null || key.length() == 0) {
    key = "_FlowController"; // default key
  }

  Map<String, Object> flowControllerParams = new HashMap<>(mInitParams);

  // retrieve the sofa mappings for the FlowControler
  Map<String, String> sofamap = new TreeMap<>();
  if (mSofaMappings != null && mSofaMappings.length > 0) {
    for (int s = 0; s < mSofaMappings.length; s++) {
      // the mapping is for this analysis engine
      if (mSofaMappings[s].getComponentKey().equals(key)) {
        // if component sofa name is null, replace it with the default for TCAS sofa name
        // This is to support single-view annotators.
        if (mSofaMappings[s].getComponentSofaName() == null)
          mSofaMappings[s].setComponentSofaName(CAS.NAME_DEFAULT_SOFA);
        sofamap.put(mSofaMappings[s].getComponentSofaName(), mSofaMappings[s]
                .getAggregateSofaName());
      }
    }
  }
  FlowControllerContext ctxt = new FlowControllerContext_impl(aParentContext, key, sofamap,
          getComponentAnalysisEngineMetaData(), aAggregateMetadata);
  flowControllerParams.put(PARAM_UIMA_CONTEXT, ctxt);
  flowControllerParams.put(PARAM_RESOURCE_MANAGER, getResourceManager());
  mFlowControllerContainer = new FlowControllerContainer();
  mFlowControllerContainer.initialize(aFlowControllerDeclaration.getSpecifier(),
          flowControllerParams);
}
 
Example #8
Source File: UimaContext_ImplBase.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public UimaContextAdmin createChild(String aContextName, Map<String, String> aSofaMappings) {

  // create child context with the absolute mappings
  ChildUimaContext_impl child = new ChildUimaContext_impl(this, aContextName, combineSofaMappings(aSofaMappings));

  // build a tree of MBeans that parallels the tree of UimaContexts
  mMBean.addComponent(aContextName, child.mMBean);

  return child;
}
 
Example #9
Source File: ChildUimaContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public ChildUimaContext_impl(UimaContextAdmin aParentContext, String aContextName,
        Map<String, String> aSofaMappings) {
  super(aParentContext.getQualifiedContextName() + aContextName + '/', aSofaMappings);
  mRootContext = aParentContext.getRootContext();
  mLogger = aParentContext.getRootContext().getLogger();
  mSessionNamespaceView = new SessionNamespaceView_impl(mRootContext.getSession(),
          mQualifiedContextName);
  parentContext = aParentContext;
}
 
Example #10
Source File: FlowControllerContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @param aParentContext -
 * @param aContextName -
 * @param aSofaMappings -
 * @param aAnalysisEngineMetaDataMap -
 * @param aAggregateMetadata -
 */
public FlowControllerContext_impl(UimaContextAdmin aParentContext, String aContextName,
        Map<String, String> aSofaMappings, Map<String, AnalysisEngineMetaData> aAnalysisEngineMetaDataMap,
        AnalysisEngineMetaData aAggregateMetadata) {
  super(aParentContext, aContextName, ((UimaContext_ImplBase)aParentContext).combineSofaMappings(aSofaMappings));
  mAnalysisEngineMetaDataMap = Collections.unmodifiableMap(aAnalysisEngineMetaDataMap);
  mAggregateMetadata = aAggregateMetadata;

  // add our MBean to the tree
  ((AnalysisEngineManagementImpl) aParentContext.getManagementInterface()).addComponent(
          aContextName, this.mMBean);
}
 
Example #11
Source File: KnowNER.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private AnalysisEngine initializeClassifier(String language) throws ResourceInitializationException, SQLException {
    logger.debug("Initializing KnowNER for '" + language + "'.");

    long start = System.currentTimeMillis();

    List<AnalysisEngineDescription> descriptions = new ArrayList<>();

    if (model.equals("NED")) {
        descriptions.add(AnalysisEngineFactory.createEngineDescription(BmeowTypeAnnotator.class,
                BmeowTypeAnnotator.GOLD, false));
        descriptions.add(AnalysisEngineFactory.createEngineDescription(RemoveNamedEntityAnnotator.class));
    }
    descriptions.add(AnalysisEngineFactory.createEngineDescription(DictionaryMatchAnnotator.class,
            DictionaryMatchAnnotator.PARAM_LANGUAGE, language));
    descriptions.add(AnalysisEngineFactory.createEngineDescription(DictionaryFeaturesAnnotator.class,
            DictionaryFeaturesAnnotator.PARAM_LANGUAGE, language));

    descriptions.add(createEngineDescription(LocalFeaturesTcAnnotator.class,
	TcAnnotator.PARAM_TC_MODEL_LOCATION, KnowNERSettings.getModelPath(language, model).toFile(),
	LocalFeaturesTcAnnotator.PARAM_LANGUAGE, language,
	TcAnnotator.PARAM_NAME_SEQUENCE_ANNOTATION, Sentence.class.getName(),
	TcAnnotator.PARAM_NAME_UNIT_ANNOTATION, Token.class.getName()));

    descriptions.add(createEngineDescription(KnowNERNamedEntityPostClassificationBMEOWAnnotator.class));

    AnalysisEngineDescription[] analysisEngineDescriptions = new AnalysisEngineDescription[descriptions.size()];
    for (int i = 0; i < descriptions.size(); i++) {
        analysisEngineDescriptions[i] = descriptions.get(i);
    }

    ResourceManager mgr = ((UimaContextAdmin) getContext()).getResourceManager();

    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(
            createEngineDescription(analysisEngineDescriptions), mgr, null);

    long dur = System.currentTimeMillis() - start;
    logger.info("Initialized KnowNER-" + language + " in " + dur/1000 + "s.");

    return ae;
}
 
Example #12
Source File: CasManager_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void releaseCas(AbstractCas aCAS) {
  if (!(aCAS instanceof CASImpl) &&
      !(aCAS instanceof JCas)) {
    throw new UIMARuntimeException(UIMARuntimeException.UNSUPPORTED_CAS_INTERFACE,
        new Object[] {aCAS.getClass()});
  }
  CASImpl baseCas = (aCAS instanceof JCas) ? ((JCas)aCAS).getCasImpl().getBaseCAS() 
                                           : ((CASImpl)aCAS).getBaseCAS();

  if (baseCas.containsCasState(CasState.UIMA_AS_WAIT_4_RESPONSE)) {
    throw new UIMARuntimeException(UIMARuntimeException.CAS_RELEASE_NOT_ALLOWED_WHILE_WAITING_FOR_UIMA_AS, new Object[0]);
  }
  
  CasPool pool = mCasToCasPoolMap.get(baseCas);
  if (pool == null) {
    // CAS doesn't belong to this CasManager!
    throw new UIMARuntimeException(UIMARuntimeException.CAS_RELEASED_TO_WRONG_CAS_MANAGER,
            new Object[0]);
  } else {
    //see if we have a UimaContext that we can notify that CAS was release
    UimaContextAdmin uc = (UimaContextAdmin)mCasToUimaContextMap.get(baseCas);
    if (uc != null) {
      uc.returnedCAS(aCAS);
    }
    
    //release the CAS
    pool.releaseCas((CAS) aCAS);
  }
}
 
Example #13
Source File: ASB_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Called after calling initialize() (see above)
 * by the Aggregate Analysis Engine to provide this ASB with information it needs to
 * operate.
 * 
 * @param aSpecifiers
 *          the specifiers for all component AEs within this Aggregate. The ASB will instantiate
 *          those AEs.
 * @param aParentContext
 *          UIMA context for the aggregate AE
 * @param aFlowControllerDeclaration
 *          declaration (key and specifier) of FlowController to be used for this aggregate.
 * @param aAggregateMetadata metadata for the aggregate AE
 * @throws ResourceInitializationException passthru
 */
public void setup(Map<String, ResourceSpecifier> aSpecifiers, UimaContextAdmin aParentContext,
        FlowControllerDeclaration aFlowControllerDeclaration,
        AnalysisEngineMetaData aAggregateMetadata) throws ResourceInitializationException {
  mAggregateUimaContext = aParentContext;

  // clear the delegate AnalysisEngine and AnalysisEngineMetaData maps
  mComponentAnalysisEngineMap.clear();
  mComponentAnalysisEngineMetaDataMap.clear();
  mAllComponentMetaDataMap.clear();

  // loop through all entries in the (key, specifier) map
  Iterator<Map.Entry<String,ResourceSpecifier>> i = aSpecifiers.entrySet().iterator();
  while (i.hasNext()) {
    Map.Entry<String,ResourceSpecifier> entry = i.next();
    String key =entry.getKey();
    ResourceSpecifier spec = entry.getValue();

    Map<String, String> sofamap = new TreeMap<>();

    // retrieve the sofa mappings for input/output sofas of this analysis engine
    if (mSofaMappings != null && mSofaMappings.length > 0) {
      for (int s = 0; s < mSofaMappings.length; s++) {
        // the mapping is for this analysis engine
        if (mSofaMappings[s].getComponentKey().equals(key)) {
          // if component sofa name is null, replace it with the default for CAS sofa name
          // This is to support single-view annotators.
          if (mSofaMappings[s].getComponentSofaName() == null)
            mSofaMappings[s].setComponentSofaName(CAS.NAME_DEFAULT_SOFA);
          sofamap.put(mSofaMappings[s].getComponentSofaName(), mSofaMappings[s]
                  .getAggregateSofaName());
        }
      }
    }

    // create child UimaContext and insert into mInitParams map
    // mInitParams was previously set to the value of aAdditionalParams
    //  passed to the initialize method of this aggregate, by the
    //  preceeding call to initialize().
    
    if (mInitParams == null)
      mInitParams = new HashMap<>();
    UimaContextAdmin childContext = aParentContext.createChild(key, sofamap);
    mInitParams.put(Resource.PARAM_UIMA_CONTEXT, childContext);

    AnalysisEngine ae;

    // if running in "validation mode", don't try to connect to any services
    if (mInitParams.containsKey(AnalysisEngineImplBase.PARAM_VERIFICATION_MODE)
            && !(spec instanceof ResourceCreationSpecifier)) {
      // but we need placeholder entries in maps to satisfy later checking
      ae = new DummyAnalysisEngine();
    } else {
      // construct an AnalysisEngine - initializing it with the parameters
      // passed to this ASB's initialize method
      ae = UIMAFramework.produceAnalysisEngine(spec, mInitParams);
    }

    // add the Analysis Engine and its metadata to the appropriate lists

    // add AnlaysisEngine to maps based on key
    mComponentAnalysisEngineMap.put(key, ae);
    mComponentAnalysisEngineMetaDataMap.put(key, ae.getAnalysisEngineMetaData());
  }

  // make Maps unmodifiable
  mComponentAnalysisEngineMap = Collections.unmodifiableMap(mComponentAnalysisEngineMap);
  mComponentAnalysisEngineMetaDataMap = Collections
          .unmodifiableMap(mComponentAnalysisEngineMetaDataMap);

  mOutputNewCASes = aAggregateMetadata.getOperationalProperties().getOutputsNewCASes();

  // initialize the FlowController
  initFlowController(aFlowControllerDeclaration, aParentContext, aAggregateMetadata);

  // initialize the AllComponentMetaData map to include AEs plus the FlowController
  mAllComponentMetaDataMap = new LinkedHashMap<>(mComponentAnalysisEngineMetaDataMap);
  mAllComponentMetaDataMap.put(aFlowControllerDeclaration.getKey(), mFlowControllerContainer
          .getProcessingResourceMetaData());
  mAllComponentMetaDataMap = Collections.unmodifiableMap(mAllComponentMetaDataMap);
}
 
Example #14
Source File: FakeContentExtractor.java    From baleen with Apache License 2.0 4 votes vote down vote up
@Override
public UimaContextAdmin getUimaContextAdmin() {
  return null;
}
 
Example #15
Source File: PearAnalysisEngineWrapper.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public UimaContextAdmin getUimaContextAdmin() {
  return ae.getUimaContextAdmin();
}
 
Example #16
Source File: AnalysisEngineImplBase.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public AnalysisEngineManagement getManagementInterface() {
  UimaContextAdmin uc = getUimaContextAdmin();
  return uc == null ? null : uc.getManagementInterface();
}
 
Example #17
Source File: AnalysisEngineManagementImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the name of this AnalyaisEngineManagement object, and also computes the unique MBean name
 * that can later be used to register this object with an MBeanServer.
 * 
 * @param aName
 *          the simple name of this AnalysisEngine (generally this is the <code>name</code>
 *          property from the AnalysisEngineMetaData)
 * @param aContext
 *          the UimaContext for this AnalysisEngine. Needed to compute the unique name, which is
 *          hierarchical
 * @param aCustomPrefix an optional prefix provided by the Application, which will be
 *          prepended to the name generated by UIMA.  If null, the prefix
 *          "org.apache.uima:" will be used.
 */
public void setName(String aName, UimaContextAdmin aContext, String aCustomPrefix) {   
  // set the simple name
  name = aName;
  
  //determine the MBean name prefix we should use
  String prefix;
  if (aCustomPrefix == null) {
    prefix = "org.apache.uima:";
  } else {
    prefix = aCustomPrefix;
    if (!prefix.endsWith(":") && !prefix.endsWith(",")) {
      prefix += ",";
    }
  }
  // compute the unique name   
  // (first get the rootMBean and assign it a unique name if it doesn't already have one)
  AnalysisEngineManagementImpl rootMBean = (AnalysisEngineManagementImpl) aContext
          .getRootContext().getManagementInterface();
  if (rootMBean.getUniqueMBeanName() == null) {
    // try to find a unique name for the root MBean
    rootMBean.uniqueMBeanName = prefix + "name=" + escapeValue(getRootName(rootMBean.getName()));
  }

  if (rootMBean != this) {
    // form the MBean name hierarchically starting from the root name
    String rootName = rootMBean.getUniqueMBeanName();
    // strip off the MBean name prefix to get just the simple name
    rootName = rootName.substring(prefix.length() + "name=".length());
    // form the hierarchical MBean name
    prefix += "p0=";
    //we add "Components" to the end of the rootName, but be aware of quoting issues
    if (rootName.endsWith("\"")) {
      prefix += rootName.substring(0,rootName.length() - 1) + " Components\",";
    }
    else {
      prefix += rootName + " Components,";
    }      
    uniqueMBeanName = makeMBeanName(prefix, aContext.getQualifiedContextName().substring(1), 1);
  }
}
 
Example #18
Source File: UIMATermSuiteResourceWrapper.java    From termsuite-core with Apache License 2.0 4 votes vote down vote up
@Override
public UimaContextAdmin getUimaContextAdmin() {
	throw new UnsupportedOperationException();
}
 
Example #19
Source File: ResourceManagerFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
@Override
public ResourceManager newResourceManager() throws ResourceInitializationException {
  UimaContext activeContext = UimaContextHolder.getContext();
  if (activeContext != null) {
    // If we are already in a UIMA context, then we re-use it. Mind that the JCas cannot
    // handle switching across more than one classloader.
    // This can be done since UIMA 2.9.0 and starts being handled in uimaFIT 2.3.0
    // See https://issues.apache.org/jira/browse/UIMA-5056
    return ((UimaContextAdmin) activeContext).getResourceManager();
  }
  else {
    // If there is no UIMA context, then we create a new resource manager
    // UIMA core still does not fall back to the context classloader in all cases.
    // This was the default behavior until uimaFIT 2.2.0.
    ResourceManager resMgr;
    if (Thread.currentThread().getContextClassLoader() != null) {
      // If the context classloader is set, then we want the resource manager to fallb
      // back to it. However, it may not reliably do that that unless we explictly pass
      // null here. See. UIMA-6239.
      resMgr = new ResourceManager_impl(null);
    }
    else {
      resMgr = UIMAFramework.newDefaultResourceManager();
    }
    
    // Since UIMA Core version 2.10.3 and 3.0.1 the thread context classloader is taken
    // into account by the core framework. Thus, we no longer have to explicitly set a
    // classloader these or more recent versions. (cf. UIMA-5802)
    short maj = UimaVersion.getMajorVersion();
    short min = UimaVersion.getMinorVersion();
    short rev = UimaVersion.getBuildRevision();
    boolean uimaCoreIgnoresContextClassloader = 
            (maj == 2 && (min < 10 || (min == 10 && rev < 3))) || // version < 2.10.3
            (maj == 3 && ((min == 0 && rev < 1)));                // version < 3.0.1
    if (uimaCoreIgnoresContextClassloader) {
      try {
        resMgr.setExtensionClassPath(ClassUtils.getDefaultClassLoader(), "", true);
      }
      catch (MalformedURLException e) {
        throw new ResourceInitializationException(e);
      }
    }
    
    return resMgr;
  }
}
 
Example #20
Source File: CasManager_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void defineCasPool(UimaContextAdmin aRequestorContext, int aMinimumSize, Properties aPerformanceTuningSettings) throws ResourceInitializationException {
  defineCasPool(aRequestorContext, aRequestorContext.getUniqueName(), aMinimumSize, aPerformanceTuningSettings);
}
 
Example #21
Source File: FlowControllerContainer.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  UimaContext prevContext = setContextHolder();   // Get this early so the restore in correct
  try {
    // specifier must be a FlowControllerDescription. (Eventually, we
    // might support remote specifiers, but not yet)
    if (!(aSpecifier instanceof FlowControllerDescription)) {
      throw new ResourceInitializationException(
              ResourceInitializationException.NOT_A_FLOW_CONTROLLER_DESCRIPTOR, new Object[] {
                  aSpecifier.getSourceUrlString(), aSpecifier.getClass().getName() });
    }
    ResourceCreationSpecifier desc = (ResourceCreationSpecifier) aSpecifier;

    // also framework implementation must start with org.apache.uima.java
    final String fwImpl = desc.getFrameworkImplementation();
    if (fwImpl == null
            || !fwImpl.equalsIgnoreCase(Constants.JAVA_FRAMEWORK_NAME)) {
      throw new ResourceInitializationException(
              ResourceInitializationException.UNSUPPORTED_FRAMEWORK_IMPLEMENTATION, new Object[] {
                  fwImpl, aSpecifier.getSourceUrlString() });
    }

    super.initialize(aSpecifier, aAdditionalParams);

    // validate the descriptor
    desc.validate(getResourceManager());

    // instantiate FlowController
    mFlowController = instantiateFlowController(desc);

    // record metadata
    setMetaData(desc.getMetaData());

    // add our metadata to the CasManager, so that it will pick up our
    // type system, priorities, and indexes
    getCasManager().addMetaData(getProcessingResourceMetaData());

    // determine if this component is Sofa-aware (based on whether it
    // declares any input or output sofas in its capabilities)
    mSofaAware = getProcessingResourceMetaData().isSofaAware();
    
    // Set Logger, to enable component-specific logging configuration
    UimaContextAdmin uimaContext = getUimaContextAdmin();
    Logger logger = UIMAFramework.getLogger(mFlowController.getClass());
    logger.setResourceManager(this.getResourceManager());
    uimaContext.setLogger(logger);
    
    Logger classLogger = getLogger();
    classLogger.logrb(Level.CONFIG, this.getClass().getName(), "initialize", LOG_RESOURCE_BUNDLE,
            "UIMA_flow_controller_init_begin__CONFIG", getMetaData().getName());
    
    // initialize FlowController
    mFlowController.initialize(getFlowControllerContext());

    mMBeanServer = null;
    String mbeanNamePrefix = null;
    if (aAdditionalParams != null) {
      mMBeanServer = aAdditionalParams.get(AnalysisEngine.PARAM_MBEAN_SERVER);
      mbeanNamePrefix = (String)aAdditionalParams.get(AnalysisEngine.PARAM_MBEAN_NAME_PREFIX);
    }
    // update MBean with the name taken from metadata
    getMBean().setName(getMetaData().getName(), getUimaContextAdmin(), mbeanNamePrefix);
    // register MBean with MBeanServer. If no MBeanServer specified in the
    // additionalParams map, this will use the platform MBean Server
    // (Java 1.5 only)
    JmxMBeanAgent.registerMBean(getMBean(), mMBeanServer);

    classLogger.logrb(Level.CONFIG, this.getClass().getName(), "initialize", LOG_RESOURCE_BUNDLE,
            "UIMA_flow_controller_init_successful__CONFIG", getMetaData().getName());
    
    initialized = true;
    return true;
  } catch (ResourceConfigurationException e) {
    throw new ResourceInitializationException(e);
  } finally {
    UimaContextHolder.setContext(prevContext);
  }
}
 
Example #22
Source File: Resource_ImplBase.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the Admin interface to this Resource's UimaContext.
 */
@Override
public UimaContextAdmin getUimaContextAdmin() {
  return mUimaContextAdmin;
}
 
Example #23
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new AnnotatorContext_impl.
 * 
 * @param aUimaContext
 *          the UIMA Context that this AnnotatorContext wraps.
 * 
 */
public AnnotatorContext_impl(UimaContextAdmin aUimaContext) {
  mUimaContext = aUimaContext;
}
 
Example #24
Source File: ASB.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Called by the Aggregate Analysis Engine to provide this ASB with information it needs to
 * operate.
 * <p>
 * This includes a collection of {@link org.apache.uima.resource.ResourceSpecifier} objects that
 * describe how to create or locate the component AnalysisEngines within the aggregate. Each
 * <code>ResourceSpecifier</code> has an associated key, which the aggregate Analysis Engine and
 * the FlowController use to identify that component.
 * <p>
 * This method is where the component AnalysisEngines and the FlowController are instantiated.
 * 
 * @param aComponentSpecifiers
 *          a Map from String keys to <code>ResourceSpecifier</code> values, which specify how
 *          to create or locate the component CasObjectProcessors.
 * @param aParentContext
 *          the UIMA Context of the parent AnalysisEngine, used to construct the subcontexts for
 *          the components.
 * @param aFlowControllerDeclaration
 *          declaration (key and specifier) of FlowController to be used for this aggregate.
 * @param aAggregateMetadata
 *          metadata for the Aggregate AE, needed by the FlowController
 * 
 * @throws ResourceInitializationException
 *           if the {@link org.apache.uima.ResourceFactory} could not create or acquire a
 *           CasObjectProcessor instance for one of the specifiers in
 *           <code>aComponentSpecifiers</code>.
 */
public void setup(Map<String, ResourceSpecifier> aComponentSpecifiers, UimaContextAdmin aParentContext,
        FlowControllerDeclaration aFlowControllerDeclaration,
        AnalysisEngineMetaData aAggregateMetadata) throws ResourceInitializationException;
 
Example #25
Source File: RootUimaContext_impl.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Get the Root Context
 * 
 * @return root context
 */
@Override
public UimaContextAdmin getRootContext() {
  return this;
}
 
Example #26
Source File: ChildUimaContext_impl.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Get the Root Context
 * 
 * @return root context
 */
@Override
public UimaContextAdmin getRootContext() {
  return mRootContext;
}
 
Example #27
Source File: CasManager.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Defines the CAS pool required by a particular AnalysisEngine. (The AnalysisEngine must contain
 * a CAS Multiplier if it requires a CAS pool.)
 * 
 * @param aRequestorContext
 *          the UimaContext of the AE that will request the CASes
 *          (AnalysisEngine.getUimaContextAdmin()).
 * @param aMinimumSize
 *          the minimum CAS pool size required
 * @param aPerformanceTuningSettings
 *          settings, including initial CAS heap size, for the AE
 * @throws ResourceInitializationException
 *           if a CAS could not be created.
 */
void defineCasPool(UimaContextAdmin aRequestorContext, int aMinimumSize, Properties aPerformanceTuningSettings)
        throws ResourceInitializationException;
 
Example #28
Source File: Resource.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the Administrative interface to the UIMA Context. This can be used by deployment wrappers
 * to modify the UimaContext (for example, by setting the Session object).
 * 
 * @return the administrative interface to this Resource's UimaContext
 */
public UimaContextAdmin getUimaContextAdmin();