Package org.apache.uima.internal.util
Class ResourcePool
- java.lang.Object
-
- org.apache.uima.internal.util.ResourcePool
-
public class ResourcePool extends java.lang.Object
This class represents a simple pool ofResource
instances.Clients check-out Resources from the pool using the
getResource()
method and check-in Resources using thereleaseResource(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
Constructors Constructor Description ResourcePool(int aNumInstances, ResourceSpecifier aResourceSpecifier, java.lang.Class<? extends Resource> aResourceClass)
Creates new ResourcePool_implResourcePool(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
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 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, 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 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 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 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
protected java.util.Vector<Resource> getAllInstances()
-
getFreeInstances
protected java.util.Vector<Resource> getFreeInstances()
-
-