org.apache.uima.internal.util
Class ResourcePool

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

public class ResourcePool
extends java.lang.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 Summary
ResourcePool(int aNumInstances, ResourceSpecifier aResourceSpecifier, java.lang.Class<? extends Resource> aResourceClass)
          Creates new ResourcePool_impl
ResourcePool(int aNumInstances, ResourceSpecifier aResourceSpecifier, java.lang.Class<? extends Resource> aResourceClass, java.util.Map<java.lang.String,java.lang.Object> aResourceInitParams)
          Creates new ResourcePool_impl
 
Method Summary
 void checkoutSpecificResource(Resource r)
           
 void destroy()
          Destroys all Resources in this pool.
protected  void fillPool(ResourceSpecifier aResourceSpecifier, java.lang.Class<? extends Resource> aResourceClass, java.util.Map<java.lang.String,java.lang.Object> aResourceInitParams)
          Utility method used in the constructor to fill the pool with Resource instances.
protected  java.util.Vector<Resource> getAllInstances()
           
protected  java.util.Vector<Resource> getFreeInstances()
           
 ResourceMetaData getMetaData()
          Gets the metadata for the Resources in this pool.
 Resource getResource()
          Checks out a Resource from the pool.
 Resource getResource(long aTimeout)
          Checks out a Resource from the pool.
 int getSize()
          Gets the size of this pool (the total number of instances that it can hold).
 void releaseResource(Resource aResource)
          Checks in a Resource to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourcePool

public ResourcePool(int aNumInstances,
                    ResourceSpecifier aResourceSpecifier,
                    java.lang.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,
                    java.lang.Class<? extends Resource> aResourceClass,
                    java.util.Map<java.lang.String,java.lang.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 Detail

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,
                        java.lang.Class<? extends Resource> aResourceClass,
                        java.util.Map<java.lang.String,java.lang.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 java.util.Vector<Resource> getAllInstances()

getFreeInstances

protected java.util.Vector<Resource> getFreeInstances()


Copyright © 2011. All Rights Reserved.