Java Code Examples for org.apache.uima.UimaContextAdmin#setLogger()

The following examples show how to use org.apache.uima.UimaContextAdmin#setLogger() . 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: 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 2
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);
  }
}