Package org.apache.uima.resource

Examples of org.apache.uima.resource.Resource


   *         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 = (Resource) mFreeInstances.remove(0);
      /*
       * UIMAFramework.getLogger().log( "Acquired resource " + r.getMetaData().getUUID() + " from
       * pool.");
       */
      return r;
View Full Code Here


   *         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) {
      }
View Full Code Here

   * Destroys all Resources in this pool.
   */
  public synchronized void destroy() {
    Iterator i = mAllInstances.iterator();
    while (i.hasNext()) {
      Resource current = (Resource) i.next();
      current.destroy();
    }
    mAllInstances.clear();
    mFreeInstances.clear();
  }
View Full Code Here

  public void destroy() {
    // destroy component AnalysisEngines
    Iterator i = mComponentAnalysisEngineMap.entrySet().iterator();
    while (i.hasNext()) {
      Map.Entry entry = (Map.Entry) i.next();
      Resource delegate = (Resource) entry.getValue();
      delegate.destroy();
    }
    if (mFlowControllerContainer != null) {
      mFlowControllerContainer.destroy();
    }
  }
View Full Code Here

  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);
    }
View Full Code Here

    try {
      // ask for resources with timeout of 2 seconds. should respond quickly
      // until resources are exhausted, then it will pause 2 seconds before
      // returning null
      long startTime = System.currentTimeMillis();
      Resource foo = pool1.getResource(2000);
      Assert.assertNotNull(foo);
      Assert.assertTrue(System.currentTimeMillis() - startTime < 1000);

      startTime = System.currentTimeMillis();
      Resource bar = pool1.getResource(2000);
      Assert.assertNotNull(bar);
      Assert.assertTrue(!foo.equals(bar));
      Assert.assertTrue(System.currentTimeMillis() - startTime < 1000);

      startTime = System.currentTimeMillis();
      Resource a = pool1.getResource(2000);
      Assert.assertNotNull(a);
      Assert.assertTrue(System.currentTimeMillis() - startTime < 1000);

      startTime = System.currentTimeMillis();
      Resource b = pool1.getResource(2000);
      Assert.assertNull(b);
      Assert.assertTrue(System.currentTimeMillis() - startTime >= 2000);

      // Start a thread that will release "foo" in 1 second. Demonstrate that
      // getResource() will not acquire a resource but getResource(2000) will.
View Full Code Here

  public void testReleaseResource() throws Exception {
    try {
      // acquire all the resources
      Assert.assertEquals(3, pool1.getFreeInstances().size());
      Resource foo = pool1.getResource();
      Resource bar = pool1.getResource();
      Resource blah = pool1.getResource();
      Assert.assertEquals(0, pool1.getFreeInstances().size());

      // release one
      pool1.releaseResource(foo);
      Assert.assertEquals(1, pool1.getFreeInstances().size());

      // try to release "foo" again - should not change the free instances count
      // this will log a warning - first we log that this is expected
      UIMAFramework.getLogger().log(Level.WARNING, "Unit test is expecting to log ResourcePool warning.");
      pool1.releaseResource(foo);
      Assert.assertEquals(1, pool1.getFreeInstances().size());

      // show that we can then check out a new one
      Resource test = pool1.getResource();
      Assert.assertNotNull(test);
      Assert.assertEquals(0, pool1.getFreeInstances().size());

      // release the others
      pool1.releaseResource(test);
View Full Code Here

  }

  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());
View Full Code Here

      } else if (current instanceof TypePriorities) {
        ProcessingResourceMetaData md = new ProcessingResourceMetaData_impl();
        md.setTypePriorities((TypePriorities) current);
        mdList.add(md);
      } else if (current instanceof ResourceSpecifier) {
        Resource resource = UIMAFramework.produceResource((ResourceSpecifier) current,
                Collections.EMPTY_MAP);
        ResourceMetaData metadata = resource.getMetaData();
        if (metadata instanceof ProcessingResourceMetaData) {
          mdList.add(metadata);
        }
        resource.destroy();
      } else {
        throw new ResourceInitializationException(
                ResourceInitializationException.UNSUPPORTED_OBJECT_TYPE_IN_CREATE_CAS,
                new Object[] { current.getClass().getName() });
      }
View Full Code Here

    // 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()) {
View Full Code Here

TOP

Related Classes of org.apache.uima.resource.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.