Class PooledResourceFactory

java.lang.Object
com.gargoylesoftware.base.resource.ResourceFactory
com.gargoylesoftware.base.resource.PooledResourceFactory

public class PooledResourceFactory extends ResourceFactory
A resource factory that provides object pooling
Version:
$Revision: 1.4 $
  • Field Details

    • sourceFactory_

      private final ResourceFactory sourceFactory_
    • preferredCacheSize_

      private int preferredCacheSize_
    • cache_

      private List cache_
  • Constructor Details

    • PooledResourceFactory

      public PooledResourceFactory(ResourceFactory sourceFactory)
      Create an instance
      Parameters:
      sourceFactory - The factory that will be used to actually create and destroy the pooled resources
  • Method Details

    • setPreferredCacheSize

      public void setPreferredCacheSize(int size)
      Set the preferredCacheSize
      Parameters:
      size - The new size. May not be negative
    • getPreferredCacheSize

      public int getPreferredCacheSize()
      Return the preferredCacheSize
      Returns:
      The size
    • reinitializeResourceIfPossible

      public boolean reinitializeResourceIfPossible(ManagedResource resource)
      Reinitialize the resource to a known state. This is required for resource pooling as all resources being returned from a pool must have been initialized to a known state.
      Specified by:
      reinitializeResourceIfPossible in class ResourceFactory
      Parameters:
      resource - the resource to reinitialize
      Returns:
      true if the resource was successfully reinitialized
    • getResourceImpl

      protected ManagedResource getResourceImpl(ResourceManager resourceManager) throws Exception
      Get a resource
      Specified by:
      getResourceImpl in class ResourceFactory
      Parameters:
      resourceManager - The manager that owns this factory
      Returns:
      A resource
      Throws:
      Exception - If an error occurs
    • releaseResourceImpl

      protected void releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource) throws Exception
      Release a resource
      Specified by:
      releaseResourceImpl in class ResourceFactory
      Parameters:
      resourceManager - The manager that owns this factory
      resource - The resource to release
      Throws:
      Exception - If an error occurs