Class 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 Detail

      • 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
    • 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