org.apache.uima.resource.Resource Java Examples

The following examples show how to use org.apache.uima.resource.Resource. 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: 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 #2
Source File: ResourceInitializationUtil.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Handle Spring-initialization of resoures produced by the UIMA framework.
 */
public static Resource initResource(Resource aResource, ApplicationContext aApplicationContext) {
  AutowireCapableBeanFactory beanFactory = aApplicationContext.getAutowireCapableBeanFactory();

  if (aResource instanceof PrimitiveAnalysisEngine_impl) {
    PropertyAccessor pa = PropertyAccessorFactory.forDirectFieldAccess(aResource);

    // Access the actual AnalysisComponent and initialize it
    AnalysisComponent analysisComponent = (AnalysisComponent) pa
            .getPropertyValue("mAnalysisComponent");
    initializeBean(beanFactory, analysisComponent, aResource.getMetaData().getName());
    pa.setPropertyValue("mAnalysisComponent", analysisComponent);

    return aResource;
  } else {
    return (Resource) beanFactory.initializeBean(aResource, aResource.getMetaData().getName());
  }
}
 
Example #3
Source File: ResourcePoolTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testGetResource() throws Exception {
  try {
    Assert.assertEquals(3, pool1.getFreeInstances().size());

    // get two resources
    Resource foo = pool1.getResource();
    Assert.assertNotNull(foo);
    Assert.assertEquals(2, pool1.getFreeInstances().size());

    Resource bar = pool1.getResource();
    Assert.assertNotNull(bar);
    Assert.assertTrue(!foo.equals(bar));
    Assert.assertEquals(1, pool1.getFreeInstances().size());

    // get two more resources (should exhaust pool)
    Resource a = pool1.getResource();
    Assert.assertNotNull(a);
    Assert.assertEquals(0, pool1.getFreeInstances().size());

    Resource b = pool1.getResource();
    Assert.assertNull(b);
    Assert.assertEquals(0, pool1.getFreeInstances().size());
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #4
Source File: CollectionProcessingEngine_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testPerformanceTuningSettings() throws Exception {
  try {
    Properties newProps = UIMAFramework.getDefaultPerformanceTuningProperties();
    newProps.setProperty(UIMAFramework.CAS_INITIAL_HEAP_SIZE, "100000");
    HashMap params = new HashMap();
    params.put(Resource.PARAM_PERFORMANCE_TUNING_SETTINGS, newProps);

    CpeDescription cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription(
 new XMLInputSource(JUnitExtension
     .getFile("CollectionProcessingEngineImplTest/performanceTuningSettingsTestCpe.xml")));
    CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc,
 params);
    cpe.process();
    // Need to give CPE time to do its work. The following should work, but
    // doesn't
    // while (cpe.isProcessing())
    // {
    // Thread.sleep(1000);
    // }
    Thread.sleep(3000);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #5
Source File: ResourcePoolTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testDestroy() throws Exception {
  try {
    // do some stuff
    Resource foo = pool1.getResource();
    Resource bar = pool1.getResource();
    Resource a = pool1.getResource();
    pool1.releaseResource(foo);
    Resource b = pool1.getResource();
    pool1.releaseResource(b);

    // now some stuff should be recorded in the pool
    Assert.assertTrue(!pool1.getFreeInstances().isEmpty());

    // destroy the pool
    pool1.destroy();

    // check that everything is gone
    Assert.assertTrue(pool1.getFreeInstances().isEmpty());
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #6
Source File: ASB_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.uima.resource.Resource#destroy()
 */
public void destroy() {
  // destroy component AnalysisEngines that have been successfully initialized
  //   unsuccessful initializations are not put into the Map
  Iterator<Map.Entry<String, AnalysisEngine>> i = mComponentAnalysisEngineMap.entrySet().iterator();
  while (i.hasNext()) {
    Map.Entry<String, AnalysisEngine> entry = i.next();
    Resource delegate = entry.getValue();
    delegate.destroy();
  }
  
  if (mFlowControllerContainer != null &&
      // the container might be non-null, but the initialization could have failed
      mFlowControllerContainer.isInitialized()) {
    mFlowControllerContainer.destroy();
  }
}
 
Example #7
Source File: ASB_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes this ASB.
 * 
 * @param aSpecifier
 *          describes how to create this ASB.
 * @param aAdditionalParams
 *          parameters which are passed along to the delegate Analysis Engines when they are
 *          constructed
 * 
 * @return true if and only if initialization completed successfully. Returns false if this
 *         implementation cannot handle the given <code>ResourceSpecifier</code>.
 * 
 * @see org.apache.uima.resource.Resource#initialize(ResourceSpecifier, Map)
 */
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize",
          LOG_RESOURCE_BUNDLE, "UIMA_asb_init_begin__CONFIG");
  if (!(aSpecifier instanceof ResourceCreationSpecifier)) {
    return false;
  }

  // copy the additional parameters, since this method will modify them
  super.initialize(aSpecifier, aAdditionalParams = new HashMap<>(aAdditionalParams));

  // save parameters for later
  mInitParams = aAdditionalParams;

  // save the sofa mappings of the aggregate AE that this AE is part of
  mSofaMappings = (SofaMapping[]) mInitParams.remove(Resource.PARAM_AGGREGATE_SOFA_MAPPINGS);
  // also remove them from the aAdditionalParams map, as they don't need to be passed
  // on to delegates
  // if (mSofaMappings != null)
  // mInitParams.remove(mInitParams.get(Resource.PARAM_AGGREGATE_SOFA_MAPPINGS));

  UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize",
          LOG_RESOURCE_BUNDLE, "UIMA_asb_init_successful__CONFIG");
  return true;
}
 
Example #8
Source File: CompositeResourceFactory_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.uima.ResourceFactory#produceResource(java.lang.Class,
 *      org.apache.uima.resource.ResourceSpecifier, java.util.Map)
 */
public Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier,
        Map<String, Object> aAdditionalParams) throws ResourceInitializationException {
  // check for factories registered for this resource specifier type
  // (most recently registered first)
  ListIterator<Registration> it = mRegisteredFactories.listIterator(mRegisteredFactories.size());
  Resource result = null;
  while (it.hasPrevious()) {
    Registration reg = it.previous();
    if (reg.resourceSpecifierInterface.isAssignableFrom(aSpecifier.getClass())) {
      result = reg.factory.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
      if (result != null) {
        return result;
      }
    }
  }
  return null;
}
 
Example #9
Source File: BaleenContentExtractorTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddMetadata() throws ResourceInitializationException {
  FakeBaleenContentExtractor annotator = new MockedBaleenContentExtractor();
  annotator.initialize(
      new CustomResourceSpecifier_impl(), ImmutableMap.of(Resource.PARAM_UIMA_CONTEXT, context));

  Metadata md = annotator.addMetadata(jCas, KEY, VALUE);
  verify(support).add(md);

  assertNull(annotator.addMetadata(jCas, "", VALUE));
  assertNull(annotator.addMetadata(jCas, null, VALUE));
  assertNull(annotator.addMetadata(jCas, KEY, ""));
  assertNull(annotator.addMetadata(jCas, KEY, null));

  resetMocked();
}
 
Example #10
Source File: BaleenContentExtractorTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupport() throws ResourceInitializationException {
  FakeBaleenContentExtractor annotator = new MockedBaleenContentExtractor();
  annotator.initialize(
      new CustomResourceSpecifier_impl(), ImmutableMap.of(Resource.PARAM_UIMA_CONTEXT, context));

  List<Annotation> list = Collections.singletonList(annotation);

  annotator.addToJCasIndex(annotation);
  verify(support, only()).add(annotation);
  resetMocked();

  annotator.addToJCasIndex(list);
  verify(support, only()).add(list);
  resetMocked();

  annotator.getDocumentAnnotation(jCas);
  resetMocked();
}
 
Example #11
Source File: ResourceManager_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.uima.resource.ResourceManager#getResourceClass(java.lang.String)
 */
@Override
@SuppressWarnings("unchecked")
public Class<?> getResourceClass(String aName) {
  checkDestroyed();
  Object r = mResourceMap.get(aName);
  if (r == null) // no such resource
  {
    return null;
  }

  // if this is a ParameterizedDataResource, look up its class
  if (r instanceof ParameterizedDataResource) {
    Class<?> customResourceClass = mParameterizedResourceImplClassMap.get(aName);
    if (customResourceClass == EMPTY_RESOURCE_CLASS) {
      // return the default class
      return DataResource_impl.class;
    }
    return customResourceClass;
  } else {
    // return r's Class
    // could be, for 
    return (Class<? extends Resource>) r.getClass();
  }
}
 
Example #12
Source File: AnalysisEnginePool.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.uima.analysis_engine.AnalysisEngine#setResultSpecification(ResultSpecification)
 * This version only called for setResultSpecification called from an appl on the
 * MultiprocessingAnalysisEngine directly.  process(cas, result-spec) calls
 * setResultSpecification on the individual analysis engine from the pool.
 * @param aResultSpec -
 */
public void setResultSpecification(ResultSpecification aResultSpec) {
  
  // set Result Spec on each AnalysisEngine in the pool

  Vector<Resource> allInstances = mPool.getAllInstances();
  for (int i = 0; i < mPool.getSize(); i++) {
    AnalysisEngine ae = (AnalysisEngine)allInstances.get(i);
    
    mPool.checkoutSpecificResource(ae);
    
    try {
    //    set result spec
    ae.setResultSpecification(aResultSpec);
    } finally {
    mPool.releaseResource(ae);
    }
  }
 
}
 
Example #13
Source File: CustomResourceSpecifierFactory_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testProduceResource() throws Exception {
  CustomResourceSpecifier specifier = UIMAFramework.getResourceSpecifierFactory().createCustomResourceSpecifier();
  specifier.setResourceClassName("org.apache.uima.impl.SomeCustomResource");
  Parameter[] parameters = new Parameter[2];
  parameters[0] = UIMAFramework.getResourceSpecifierFactory().createParameter();
  parameters[0].setName("param1");
  parameters[0].setValue("val1");
  parameters[1] = UIMAFramework.getResourceSpecifierFactory().createParameter();
  parameters[1].setName("param2");
  parameters[1].setValue("val2");
  specifier.setParameters(parameters);    
  
  Resource res = crFactory.produceResource(Resource.class, specifier, Collections.EMPTY_MAP);   
  assertTrue(res instanceof SomeCustomResource);
  assertEquals("val1", ((SomeCustomResource)res).paramMap.get("param1"));
  assertEquals("val2", ((SomeCustomResource)res).paramMap.get("param2"));
  
  //also UIMAFramework.produceResource should do the same thing
  res = UIMAFramework.produceResource(specifier, Collections.EMPTY_MAP);    
  assertTrue(res instanceof SomeCustomResource);
  assertEquals("val1", ((SomeCustomResource)res).paramMap.get("param1"));
  assertEquals("val2", ((SomeCustomResource)res).paramMap.get("param2"));  
}
 
Example #14
Source File: MongoGazetteer.java    From baleen with Apache License 2.0 6 votes vote down vote up
/**
 * Configure a new instance of MongoGazetteer. The following config parameters are
 * expected/allowed:
 *
 * <ul>
 *   <li><b>collection</b> - The collection containing the gazetteer; defaults to gazetteer
 *   <li><b>valueField</b> - The field containing the gazetteer values; defaults to value
 * </ul>
 *
 * @param connection A SharedMongoResource object to use to connect to Mongo
 * @param config A map of additional configuration options
 * @throws InvalidParameterException if the passed connection parameter is not a
 *     SharedMongoResource
 */
@Override
public void init(Resource connection, Map<String, Object> config) throws BaleenException {
  SharedMongoResource mongo;
  try {
    mongo = (SharedMongoResource) connection;
  } catch (ClassCastException cce) {
    throw new InvalidParameterException(
        "Unable to cast connection parameter to SharedMongoResource", cce);
  }

  valueField = DEFAULT_VALUE_FIELD;
  if (config.containsKey(CONFIG_VALUE_FIELD)) {
    valueField = config.get(CONFIG_VALUE_FIELD).toString();
  }

  String collection = DEFAULT_COLLECTION;
  if (config.containsKey(CONFIG_COLLECTION)) {
    collection = config.get(CONFIG_COLLECTION).toString();
  }

  coll = mongo.getDB().getCollection(collection);

  super.init(connection, config);
}
 
Example #15
Source File: ResourcePool.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Checks out a Resource from the pool. If none is currently available, wait for the specified
 * amount of time for one to be checked in.
 * 
 * @param aTimeout
 *          the time to wait in milliseconds. A value of &lt;=0 will wait forever.
 * 
 * @return a Resource for use by the client. Returns <code>null</code> if none are available (in
 *         which case the client may wait on this object in order to be notified when an instance
 *         becomes available).
 */
public synchronized Resource getResource(long aTimeout) {
  long startTime = new Date().getTime();
  Resource resource;
  while ((resource = getResource()) == null) {
    try {
      wait(aTimeout);
    } catch (InterruptedException e) {
    }
    if (aTimeout > 0 && (new Date().getTime() - startTime) >= aTimeout) {
      // Timeout has expired
      return null;
    }
  }
  return resource;
}
 
Example #16
Source File: ResourcePool.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Checks in a Resource to the pool. Also notifies other Threads that may be waiting for a
 * connection.
 * 
 * @param aResource
 *          the resource to release
 */
public synchronized void releaseResource(Resource aResource) {
  // make sure this Resource was actually belongs to this pool and is checked out
  if (!mAllInstances.contains(aResource) || mFreeInstances.contains(aResource)) {
    UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
            "releaseResource", LOG_RESOURCE_BUNDLE, "UIMA_return_resource_to_pool__WARNING");
  } else {
    /*
     * UIMAFramework.getLogger().log( "Returned resource " + aResource.getMetaData().getUUID() + "
     * to the pool.");
     */
    // Add the Resource to the end of the free instances List
    mFreeInstances.add(aResource);
  }

  // Notify any threads waiting on this object
  notifyAll();
}
 
Example #17
Source File: BaleenContentExtractorTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoInitialize() throws ResourceInitializationException {
  FakeBaleenContentExtractor annotator = new FakeBaleenContentExtractor();
  annotator.initialize(
      new CustomResourceSpecifier_impl(), ImmutableMap.of(Resource.PARAM_UIMA_CONTEXT, context));
  assertTrue(annotator.initialised);
}
 
Example #18
Source File: CollectionReaderFactory_impl.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
@Override
public Resource produceResource(Class<? extends Resource> aResourceClass,
        ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
  return initResource(resource, applicationContext);
}
 
Example #19
Source File: ExternalResourceFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public static ExternalResourceDependency createResourceDependency(Field field) {
  ExternalResource era = ReflectionUtil.getAnnotation(field, ExternalResource.class);

  // Get the binding key for the specified field. If no key is set, use the field name as key.
  String key = era.key();
  if (key.length() == 0) {
    key = field.getName();
  }

  // Get the type of class/interface a resource has to implement to bind to the annotated field.
  // If no API is set, get it from the annotated field type.
  Class<? extends Resource> api = era.api();
  
  // If no API is specified, look at the annotated field
  if (api == Resource.class) {
    if (
            Resource.class.isAssignableFrom(field.getType()) || 
            SharedResourceObject.class.isAssignableFrom(field.getType())
    ) {
      // If no API is set, check if the field type is already a resource type
      api = (Class<? extends Resource>) field.getType();
    } else {
      // If the field does not have a resource type, assume whatever. This allows to use
      // a resource locator without having to specify the api parameter. It also allows
      // to directly inject Java objects - yes, I know that Object does not extend
      // Resource - REC, 2011-03-25
      api = (Class) Object.class;
    }
  }

  return createResourceDependency(key, api, !era.mandatory(), era.description());
}
 
Example #20
Source File: CasInitializerFactory_impl.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
@Override
public Resource produceResource(Class<? extends Resource> aResourceClass,
        ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
  return initResource(resource, applicationContext);
}
 
Example #21
Source File: CasConsumerFactory_impl.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
@Override
public Resource produceResource(Class<? extends Resource> aResourceClass,
        ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
  return initResource(resource, applicationContext);
}
 
Example #22
Source File: CustomResourceFactory_impl.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
@Override
public Resource produceResource(Class<? extends Resource> aResourceClass,
        ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
  return initResource(resource, applicationContext);
}
 
Example #23
Source File: AnalysisEngineFactory_impl.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
@Override
public Resource produceResource(Class<? extends Resource> aResourceClass,
        ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
  return initResource(resource, applicationContext);
}
 
Example #24
Source File: CollectionProcessingEngine_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void initialize(CpeDescription aCpeDescription, Map aAdditionalParams)
        throws ResourceInitializationException {
  if (mCPM != null) // repeat initialization - not allowed
  {
    throw new UIMA_IllegalStateException(UIMA_IllegalStateException.RESOURCE_ALREADY_INITIALIZED,
            new Object[] { getClass().getName() });
  }

  // get the ResourceManager (if any) supplied in the aAdditionalParams map
  ResourceManager resMgr = aAdditionalParams == null ? null : (ResourceManager) aAdditionalParams
          .get(Resource.PARAM_RESOURCE_MANAGER);

  // get performance tuning settings (if any) supplied in the aAdditionalParams map
  Properties perfSettings = aAdditionalParams == null ? null : (Properties) aAdditionalParams
          .get(Resource.PARAM_PERFORMANCE_TUNING_SETTINGS);

  // get ProcessControllerAdapter responsible for launching fenced services
  ProcessControllerAdapter pca = aAdditionalParams == null ? null
          : (ProcessControllerAdapter) aAdditionalParams.get("ProcessControllerAdapter");
  // instantiate CPM from Descriptor
  try {
    mCPM = new BaseCPMImpl(aCpeDescription, resMgr, false, perfSettings);
    if (perfSettings != null) {
      mCPM.setPerformanceTuningSettings(perfSettings);
    }
    if (pca != null) {
      mCPM.setProcessControllerAdapter(pca);
    }
  } catch (Exception e) {
    throw new ResourceInitializationException(e);
  }
}
 
Example #25
Source File: CollectionReaderAdapter.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void initialize(UimaContext aContext) throws ResourceInitializationException {
  // Initialize the CollectionReader, passing the appropriate UimaContext
  // We pass an empty descriptor to satisfy the Collection Reader's initialize
  // method; we don't want to do any additional set-up of resources or
  // config params, that's all handled in the initialization of the enclosing
  // Primitive AnalysisEngine.
  AnalysisEngineDescription_impl desc = new AnalysisEngineDescription_impl();

  Map<String, Object> paramsMap = new HashMap<>();
  paramsMap.put(Resource.PARAM_UIMA_CONTEXT, aContext);
  mCollectionReader.initialize(desc, paramsMap);
  mUimaContext = aContext;
}
 
Example #26
Source File: ResourcePool.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Destroys all Resources in this pool.
 */
public synchronized void destroy() {
  Iterator<Resource> i = mAllInstances.iterator();
  while (i.hasNext()) {
    Resource current = i.next();
    current.destroy();
  }
  mAllInstances.clear();
  mFreeInstances.clear();
}
 
Example #27
Source File: ResourcePool.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public synchronized void checkoutSpecificResource(Resource r) {
  while (!mFreeInstances.contains(r)) {
    try {
      wait();
    } catch (InterruptedException e) {
    }
  }
  mFreeInstances.remove(r);
}
 
Example #28
Source File: ResourceCreationSpecifier_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void doFullValidation(ResourceManager aResourceManager)
        throws ResourceInitializationException {
  // try to instantiate dummy resource - this checks config params
  // and resources
  DummyResource dummy = new DummyResource();
  Map<String, Object> params = new HashMap<>();
  params.put(Resource.PARAM_RESOURCE_MANAGER, aResourceManager);
  dummy.initialize(this, params);

  // subclasses should override to check CAS creation and
  // loading of the user-supplied CAS as appropriate
}
 
Example #29
Source File: Class_TCCL.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
static public <T> Class<T> forName(String className, Map<String, Object> additionalParams) 
    throws ClassNotFoundException {
  ResourceManager rm = (additionalParams != null)
                         ? (ResourceManager) additionalParams.get(Resource.PARAM_RESOURCE_MANAGER)
                         : null;
  return forName(className, rm);
}
 
Example #30
Source File: ResourcePool.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Checks out a Resource from the pool.
 * 
 * @return a Resource for use by the client. Returns <code>null</code> if none are available (in
 *         which case the client may wait on this object in order to be notified when an instance
 *         becomes available).
 */
public synchronized Resource getResource() {
  if (!mFreeInstances.isEmpty()) {
    Resource r = mFreeInstances.remove(0);
    /*
     * UIMAFramework.getLogger().log( "Acquired resource " + r.getMetaData().getUUID() + " from
     * pool.");
     */
    return r;
  } else {
    // no instances available
    // UIMAFramework.getLogger().log("No Resource instances currently available");
    return null;
  }
}