com.gargoylesoftware.base.resource

Class PooledResourceFactory

public class PooledResourceFactory extends ResourceFactory

A resource factory that provides object pooling

Version: $Revision: 1.4 $

Author: Mike Bowler

Field Summary
Listcache_
intpreferredCacheSize_
ResourceFactorysourceFactory_
Constructor Summary
PooledResourceFactory(ResourceFactory sourceFactory)
Create an instance
Method Summary
intgetPreferredCacheSize()
Return the preferredCacheSize
protected ManagedResourcegetResourceImpl(ResourceManager resourceManager)
Get a resource
booleanreinitializeResourceIfPossible(ManagedResource resource)
Reinitialize the resource to a known state.
protected voidreleaseResourceImpl(ResourceManager resourceManager, ManagedResource resource)
Release a resource
voidsetPreferredCacheSize(int size)
Set the preferredCacheSize

Field Detail

cache_

private List cache_

preferredCacheSize_

private int preferredCacheSize_

sourceFactory_

private final ResourceFactory sourceFactory_

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

getPreferredCacheSize

public int getPreferredCacheSize()
Return the preferredCacheSize

Returns: The size

getResourceImpl

protected ManagedResource getResourceImpl(ResourceManager resourceManager)
Get a resource

Parameters: resourceManager The manager that owns this factory

Returns: A resource

Throws: Exception If an error occurs

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.

Parameters: resource the resource to reinitialize

Returns: true if the resource was successfully reinitialized

releaseResourceImpl

protected void releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource)
Release a resource

Parameters: resource The resource to release resourceManager The manager that owns this factory

Throws: Exception If an error occurs

setPreferredCacheSize

public void setPreferredCacheSize(int size)
Set the preferredCacheSize

Parameters: size The new size. May not be negative