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 Summary
Fields Modifier and Type Field Description private java.util.List
cache_
private int
preferredCacheSize_
private ResourceFactory
sourceFactory_
-
Constructor Summary
Constructors Constructor Description PooledResourceFactory(ResourceFactory sourceFactory)
Create an instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getPreferredCacheSize()
Return the preferredCacheSizeprotected ManagedResource
getResourceImpl(ResourceManager resourceManager)
Get a resourceboolean
reinitializeResourceIfPossible(ManagedResource resource)
Reinitialize the resource to a known state.protected void
releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource)
Release a resourcevoid
setPreferredCacheSize(int size)
Set the preferredCacheSize-
Methods inherited from class com.gargoylesoftware.base.resource.ResourceFactory
getResource, releaseAllResources, releaseResource
-
-
-
-
Field Detail
-
sourceFactory_
private final ResourceFactory sourceFactory_
-
preferredCacheSize_
private int preferredCacheSize_
-
cache_
private java.util.List cache_
-
-
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 classResourceFactory
- Parameters:
resource
- the resource to reinitialize- Returns:
- true if the resource was successfully reinitialized
-
getResourceImpl
protected ManagedResource getResourceImpl(ResourceManager resourceManager) throws java.lang.Exception
Get a resource- Specified by:
getResourceImpl
in classResourceFactory
- Parameters:
resourceManager
- The manager that owns this factory- Returns:
- A resource
- Throws:
java.lang.Exception
- If an error occurs
-
releaseResourceImpl
protected void releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource) throws java.lang.Exception
Release a resource- Specified by:
releaseResourceImpl
in classResourceFactory
- Parameters:
resource
- The resource to releaseresourceManager
- The manager that owns this factory- Throws:
java.lang.Exception
- If an error occurs
-
-