com.gargoylesoftware.base.resource
Class PooledResourceFactory

java.lang.Object
  extended bycom.gargoylesoftware.base.resource.ResourceFactory
      extended bycom.gargoylesoftware.base.resource.PooledResourceFactory

public class PooledResourceFactory
extends ResourceFactory

A resource factory that provides object pooling

Version:
$Revision: 1.5 $
Author:
Mike Bowler

Constructor Summary
PooledResourceFactory(ResourceFactory sourceFactory)
          Create an instance
 
Method Summary
 int getPreferredCacheSize()
          Return the preferredCacheSize
protected  ManagedResource getResourceImpl(ResourceManager resourceManager)
          Get a resource
 boolean reinitializeResourceIfPossible(ManagedResource resource)
          Reinitialize the resource to a known state.
protected  void releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource)
          Release a resource
 void setPreferredCacheSize(int size)
          Set the preferredCacheSize
 
Methods inherited from class com.gargoylesoftware.base.resource.ResourceFactory
getResource, releaseAllResources, releaseResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

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:
resource - The resource to release
resourceManager - The manager that owns this factory
Throws:
Exception - If an error occurs


Copyright © 1998-2005 Gargoyle Software Inc.. All Rights Reserved.