Class ResourcePool

java.lang.Object
org.apache.uima.internal.util.ResourcePool

public class ResourcePool extends Object
This class represents a simple pool of Resource instances.

Clients check-out Resources from the pool using the getResource() method and check-in Resources using the releaseResource(Resource) method.

This resource pool implementation does not deal with differently configured resources in the same pool. All resources are assumed to be equivalent and to share the same metadata. Therefore, the resource metadata can be retrieved via the getMetaData() method without checking out a Resource instance from the pool.

  • Constructor Details

    • ResourcePool

      public ResourcePool(int aNumInstances, ResourceSpecifier aResourceSpecifier, Class<? extends Resource> aResourceClass) throws ResourceInitializationException
      Creates new ResourcePool_impl
      Parameters:
      aNumInstances - the number of Resource instances in the pool
      aResourceSpecifier - specifier that describes how to create the Resource instances for the pool
      aResourceClass - class of resource to instantiate
      Throws:
      ResourceInitializationException - if the Resource instances could not be created
    • ResourcePool

      public ResourcePool(int aNumInstances, ResourceSpecifier aResourceSpecifier, Class<? extends Resource> aResourceClass, Map<String,Object> aResourceInitParams) throws ResourceInitializationException
      Creates new ResourcePool_impl
      Parameters:
      aNumInstances - the number of Resource instances in the pool
      aResourceSpecifier - specifier that describes how to create the Resource instances for the pool
      aResourceClass - class of resource to instantiate
      aResourceInitParams - additional parameters to be passed to Resource.initialize(ResourceSpecifier,Map) methods. May be null if there are no parameters.
      Throws:
      ResourceInitializationException - if the Resource instances could not be created
  • Method Details

    • getResource

      public Resource getResource()
      Checks out a Resource from the pool.
      Returns:
      a Resource for use by the client. Returns null if none are available (in which case the client may wait on this object in order to be notified when an instance becomes available).
    • releaseResource

      public void releaseResource(Resource aResource)
      Checks in a Resource to the pool. Also notifies other Threads that may be waiting for a connection.
      Parameters:
      aResource - the resource to release
    • getResource

      public Resource getResource(long aTimeout)
      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.
      Parameters:
      aTimeout - the time to wait in milliseconds. A value of <=0 will wait forever.
      Returns:
      a Resource for use by the client. Returns null if none are available (in which case the client may wait on this object in order to be notified when an instance becomes available).
    • checkoutSpecificResource

      public void checkoutSpecificResource(Resource r)
    • destroy

      public void destroy()
      Destroys all Resources in this pool.
    • getSize

      public int getSize()
      Gets the size of this pool (the total number of instances that it can hold).
      Returns:
      the size of this pool
    • getMetaData

      public ResourceMetaData getMetaData()
      Gets the metadata for the Resources in this pool. This pool implementation currently assumes that all Resource instances in the pool are equivalent and share the same metadata.
      Returns:
      the size of this pool
    • fillPool

      protected void fillPool(ResourceSpecifier aResourceSpecifier, Class<? extends Resource> aResourceClass, Map<String,Object> aResourceInitParams) throws ResourceInitializationException
      Utility method used in the constructor to fill the pool with Resource instances.
      Parameters:
      aResourceSpecifier - specifier that describes how to create the Resource instances for the pool
      aResourceClass - class of resource to instantiate
      aResourceInitParams - initialization parameters to be passed to the Resource.initialize(ResourceSpecifier,Map) method.
      Throws:
      ResourceInitializationException - if the Resource instances could not be created
    • getAllInstances

      protected Vector<Resource> getAllInstances()
    • getFreeInstances

      protected Vector<Resource> getFreeInstances()