Package org.apache.uima.internal.util
Class ResourcePool
java.lang.Object
org.apache.uima.internal.util.ResourcePool
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
ConstructorDescriptionResourcePool
(int aNumInstances, ResourceSpecifier aResourceSpecifier, Class<? extends Resource> aResourceClass) Creates new ResourcePool_implResourcePool
(int aNumInstances, ResourceSpecifier aResourceSpecifier, Class<? extends Resource> aResourceClass, Map<String, Object> aResourceInitParams) Creates new ResourcePool_impl -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
destroy()
Destroys all Resources in this pool.protected void
fillPool
(ResourceSpecifier aResourceSpecifier, Class<? extends Resource> aResourceClass, Map<String, Object> aResourceInitParams) Utility method used in the constructor to fill the pool with Resource instances.Gets the metadata for the Resources in this pool.Checks out a Resource from the pool.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.
-
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 poolaResourceSpecifier
- specifier that describes how to create the Resource instances for the poolaResourceClass
- 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 ResourceInitializationExceptionCreates new ResourcePool_impl- Parameters:
aNumInstances
- the number of Resource instances in the poolaResourceSpecifier
- specifier that describes how to create the Resource instances for the poolaResourceClass
- class of resource to instantiateaResourceInitParams
- additional parameters to be passed toResource.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
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
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
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
-
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
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 ResourceInitializationExceptionUtility 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 poolaResourceClass
- class of resource to instantiateaResourceInitParams
- initialization parameters to be passed to theResource.initialize(ResourceSpecifier,Map)
method.- Throws:
ResourceInitializationException
- if the Resource instances could not be created
-
getAllInstances
-
getFreeInstances
-