com.gargoylesoftware.base.resource
Class ResourceFactory

java.lang.Object
  extended by com.gargoylesoftware.base.resource.ResourceFactory
Direct Known Subclasses:
JDBCResourceFactory, PooledResourceFactory

public abstract class ResourceFactory
extends java.lang.Object

A class that can create instances of specific types of resources, such as JDBC connections.

Version:
$Revision: 1.5 $
Author:
Mike Bowler

Field Summary
private  java.util.Map resourceManagerToResourceListMap_
           
 
Constructor Summary
ResourceFactory()
          Create a factory
 
Method Summary
private  void deregisterResource(ResourceManager resourceManager, ManagedResource resource)
           
 ManagedResource getResource(ResourceManager resourceManager)
          Allocate a resource for the specified store
protected abstract  ManagedResource getResourceImpl(ResourceManager resourceManager)
          Subclasses will override this to perform the actual allocation of the resource.
private  void registerResource(ResourceManager resourceManager, ManagedResource resource)
           
abstract  boolean reinitializeResourceIfPossible(ManagedResource resource)
          Reinitialize the resource to a known state.
 void releaseAllResources(ResourceManager resourceManager)
          Release all the resources that had been allocated by the specified store.
 void releaseResource(ResourceManager resourceManager, ManagedResource resource)
          Release the specified resource.
protected abstract  void releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource)
          Subclasses will override this to perform the actual release of the resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resourceManagerToResourceListMap_

private final java.util.Map resourceManagerToResourceListMap_
Constructor Detail

ResourceFactory

public ResourceFactory()
Create a factory

Method Detail

getResource

public final ManagedResource getResource(ResourceManager resourceManager)
                                  throws ResourceException
Allocate a resource for the specified store

Parameters:
resourceManager - The object that is managing the resource allocation
Returns:
The new resource
Throws:
ResourceException - If an error occurs

releaseResource

public final void releaseResource(ResourceManager resourceManager,
                                  ManagedResource resource)
                           throws ResourceException
Release the specified resource. It must have been allocated by the specified store

Parameters:
resource - The resource that we are releasing
resourceManager - The object that is managing the resource allocation
Throws:
ResourceException - If an error occurs

releaseAllResources

public void releaseAllResources(ResourceManager resourceManager)
                         throws ResourceException
Release all the resources that had been allocated by the specified store.

Parameters:
resourceManager - The object that is managing the resource allocation
Throws:
ResourceException - If an error occurs

reinitializeResourceIfPossible

public abstract 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

getResourceImpl

protected abstract ManagedResource getResourceImpl(ResourceManager resourceManager)
                                            throws java.lang.Exception
Subclasses will override this to perform the actual allocation of the resource.

Parameters:
resourceManager - The object that is managing the resource allocation
Returns:
The new resource
Throws:
java.lang.Exception - If an error occurs

releaseResourceImpl

protected abstract void releaseResourceImpl(ResourceManager resourceManager,
                                            ManagedResource resource)
                                     throws java.lang.Exception
Subclasses will override this to perform the actual release of the resource.

Parameters:
resource - The resource to release
resourceManager - The object that is managing the resource allocation
Throws:
java.lang.Exception - If an error occurs

registerResource

private void registerResource(ResourceManager resourceManager,
                              ManagedResource resource)

deregisterResource

private void deregisterResource(ResourceManager resourceManager,
                                ManagedResource resource)
                         throws ResourceException
Throws:
ResourceException