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<Resource> i = mAllInstances.iterator();
    while (i.hasNext()) {
      Resource current = (Resource) i.next();
      current.destroy();
    }
    mAllInstances.clear();
    mFreeInstances.clear();
  }
View Full Code Here

   * @throws ResourceInitializationException
   *           if a failure occurred during production of the resource.
   */
  public static Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier,
          Map<String, Object> aAdditionalParams) throws ResourceInitializationException {
    Resource resource = getResourceFactory().produceResource(aResourceClass, aSpecifier,
            aAdditionalParams);
    if (resource == null) {
      throw new ResourceInitializationException(ResourceInitializationException.DO_NOT_KNOW_HOW,
              new Object[] { aResourceClass.getName(), aSpecifier.getSourceUrlString() });
    }
View Full Code Here

          }
        }
       
        // try to instantiate the resource
       
        Resource resource = null;
        Map<String, Object> prParams = new HashMap<String, Object>();
        if (aResourceManager != null) {
          prParams.put(Resource.PARAM_RESOURCE_MANAGER, aResourceManager);
        }
        prParams.put(AnalysisEngineImplBase.PARAM_VERIFICATION_MODE, Boolean.TRUE);
        try {
          resource = UIMAFramework.produceResource((ResourceSpecifier) current, prParams);
//              (null == aResourceManager) ? Collections.<String, Object>emptyMap() : resourceMgrInMap);
        } catch (Exception e) {
          // record failure, so we don't ask for this again, for a while
          synchronized (metaDataCache) {
            if (cacheDebug) {
              System.err.format("GetMetaDataCache: saving entry in cache%n");
            }
            metaDataCache.put(metaDataCacheKey, new MetaDataCacheEntry(null));
          }
          // failed. If aOutputFailedRemotes is non-null, add an entry to it to it, else throw the
          // exception.
          if (aOutputFailedRemotes != null) {
            aOutputFailedRemotes.put(aContextName, e);
          } else {
            if (e instanceof ResourceInitializationException)
              throw (ResourceInitializationException) e;
            else if (e instanceof RuntimeException)
              throw (RuntimeException) e;
            else
              throw new RuntimeException(e);
          }
        }
        ResourceMetaData metadata = (resource == null) ? null : resource.getMetaData();

        synchronized (metaDataCache) {
          if (cacheDebug) {
            System.err.format("GetMetaDataCache: saving entry in cache%n");
          }
          metaDataCache.put(metaDataCacheKey, new MetaDataCacheEntry(metadata));
        }

        if (resource != null) {
          if (metadata instanceof ProcessingResourceMetaData) {
            mdList.add((ProcessingResourceMetaData) metadata);
          }
          resource.destroy();
        }
      } else {
        throw new ResourceInitializationException(
            ResourceInitializationException.UNSUPPORTED_OBJECT_TYPE_IN_CREATE_CAS,
            new Object[] { current.getClass().getName() });
View Full Code Here

   * @throws ResourceInitializationException
   *           if a failure occurred during production of the resource.
   */
  public static Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier,
          Map<String, Object> aAdditionalParams) throws ResourceInitializationException {
    Resource resource = getResourceFactory().produceResource(aResourceClass, aSpecifier,
            aAdditionalParams);
    if (resource == null) {
      throw new ResourceInitializationException(ResourceInitializationException.DO_NOT_KNOW_HOW,
              new Object[] { aResourceClass.getName(), aSpecifier.getSourceUrlString() });
    }
View Full Code Here

        ResourceInitializationException currentException = null;
        try {
          // check to see if this is a subclass of aResourceClass
          if (aResourceClass.isAssignableFrom(currentClass)) {
            // instantiate this Resource Class
            Resource resource = currentClass.newInstance();
            // attempt to initialize it
            UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(),
                    "produceResource", LOG_RESOURCE_BUNDLE, "UIMA_trying_resource_class__CONFIG",
                    currentClass.getName());

            if (resource.initialize(aSpecifier, aAdditionalParams)) {
              // success!
              return resource;
            }
          }
        }
View Full Code Here

          }
        }
       
        // try to instantiate the resource
       
        Resource resource = null;
        Map<String, Object> prParams = new HashMap<String, Object>();
        if (aResourceManager != null) {
          prParams.put(Resource.PARAM_RESOURCE_MANAGER, aResourceManager);
        }
        prParams.put(AnalysisEngineImplBase.PARAM_VERIFICATION_MODE, Boolean.TRUE);
        try {
          resource = UIMAFramework.produceResource((ResourceSpecifier) current, prParams);
//              (null == aResourceManager) ? Collections.<String, Object>emptyMap() : resourceMgrInMap);
        } catch (Exception e) {
          // record failure, so we don't ask for this again, for a while
          synchronized (metaDataCache) {
            if (cacheDebug) {
              System.err.format("GetMetaDataCache: saving entry in cache%n");
            }
            metaDataCache.put(metaDataCacheKey, new MetaDataCacheEntry(null));
          }
          // failed. If aOutputFailedRemotes is non-null, add an entry to it to it, else throw the
          // exception.
          if (aOutputFailedRemotes != null) {
            aOutputFailedRemotes.put(aContextName, e);
          } else {
            if (e instanceof ResourceInitializationException)
              throw (ResourceInitializationException) e;
            else if (e instanceof RuntimeException)
              throw (RuntimeException) e;
            else
              throw new RuntimeException(e);
          }
        }
        ResourceMetaData metadata = (resource == null) ? null : resource.getMetaData();

        synchronized (metaDataCache) {
          if (cacheDebug) {
            System.err.format("GetMetaDataCache: saving entry in cache%n");
          }
          metaDataCache.put(metaDataCacheKey, new MetaDataCacheEntry(metadata));
        }

        if (resource != null) {
          if (metadata instanceof ProcessingResourceMetaData) {
            mdList.add((ProcessingResourceMetaData) metadata);
          }
          resource.destroy();
        }
      } else {
        throw new ResourceInitializationException(
            ResourceInitializationException.UNSUPPORTED_OBJECT_TYPE_IN_CREATE_CAS,
            new Object[] { current.getClass().getName() });
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() {
    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

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.