public class ResourcePool extends Object
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 and Description |
---|
ResourcePool(int aNumInstances,
ResourceSpecifier aResourceSpecifier,
Class<? extends Resource> aResourceClass)
Creates new ResourcePool_impl
|
ResourcePool(int aNumInstances,
ResourceSpecifier aResourceSpecifier,
Class<? extends Resource> aResourceClass,
Map<String,Object> aResourceInitParams)
Creates new ResourcePool_impl
|
Modifier and Type | Method and Description |
---|---|
void |
checkoutSpecificResource(Resource r) |
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.
|
protected Vector<Resource> |
getAllInstances() |
protected 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.
|
public ResourcePool(int aNumInstances, ResourceSpecifier aResourceSpecifier, Class<? extends Resource> aResourceClass) throws ResourceInitializationException
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 instantiateResourceInitializationException
- if the Resource instances could not be createdpublic ResourcePool(int aNumInstances, ResourceSpecifier aResourceSpecifier, Class<? extends Resource> aResourceClass, Map<String,Object> aResourceInitParams) throws ResourceInitializationException
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 to
Resource.initialize(ResourceSpecifier,Map)
methods. May be null if there are
no parameters.ResourceInitializationException
- if the Resource instances could not be createdpublic Resource getResource()
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).public void releaseResource(Resource aResource)
aResource
- the resource to releasepublic Resource getResource(long aTimeout)
aTimeout
- the time to wait in milliseconds. A value of <=0 will wait forever.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).public void checkoutSpecificResource(Resource r)
public void destroy()
public int getSize()
public ResourceMetaData getMetaData()
protected void fillPool(ResourceSpecifier aResourceSpecifier, Class<? extends Resource> aResourceClass, Map<String,Object> aResourceInitParams) throws ResourceInitializationException
aResourceSpecifier
- specifier that describes how to create the Resource instances for the poolaResourceClass
- class of resource to instantiateaResourceInitParams
- initialization parameters to be passed to the
Resource.initialize(ResourceSpecifier,Map)
method.ResourceInitializationException
- if the Resource instances could not be createdCopyright © 2006–2018 The Apache Software Foundation. All rights reserved.