Class PooledResourceFactory
java.lang.Object
com.gargoylesoftware.base.resource.ResourceFactory
com.gargoylesoftware.base.resource.PooledResourceFactory
A resource factory that provides object pooling
- Version:
- $Revision: 1.4 $
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
Return the preferredCacheSizeprotected ManagedResource
getResourceImpl
(ResourceManager resourceManager) Get a resourceboolean
Reinitialize the resource to a known state.protected void
releaseResourceImpl
(ResourceManager resourceManager, ManagedResource resource) Release a resourcevoid
setPreferredCacheSize
(int size) Set the preferredCacheSizeMethods inherited from class com.gargoylesoftware.base.resource.ResourceFactory
getResource, releaseAllResources, releaseResource
-
Field Details
-
sourceFactory_
-
preferredCacheSize_
private int preferredCacheSize_ -
cache_
-
-
Constructor Details
-
PooledResourceFactory
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
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
Get a resource- Specified by:
getResourceImpl
in classResourceFactory
- 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 classResourceFactory
- Parameters:
resourceManager
- The manager that owns this factoryresource
- The resource to release- Throws:
Exception
- If an error occurs
-