Class ResourceFactory
java.lang.Object
com.gargoylesoftware.base.resource.ResourceFactory
- Direct Known Subclasses:
JDBCResourceFactory,PooledResourceFactory
A class that can create instances of specific types of resources, such as
JDBC connections.
- Version:
- $Revision: 1.3 $
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidderegisterResource(ResourceManager resourceManager, ManagedResource resource) final ManagedResourcegetResource(ResourceManager resourceManager) Allocate a resource for the specified storeprotected abstract ManagedResourcegetResourceImpl(ResourceManager resourceManager) Subclasses will override this to perform the actual allocation of the resource.private voidregisterResource(ResourceManager resourceManager, ManagedResource resource) abstract booleanReinitialize the resource to a known state.voidreleaseAllResources(ResourceManager resourceManager) Release all the resources that had been allocated by the specified store.final voidreleaseResource(ResourceManager resourceManager, ManagedResource resource) Release the specified resource.protected abstract voidreleaseResourceImpl(ResourceManager resourceManager, ManagedResource resource) Subclasses will override this to perform the actual release of the resource.
-
Field Details
-
resourceManagerToResourceListMap_
-
-
Constructor Details
-
ResourceFactory
public ResourceFactory()Create a factory
-
-
Method Details
-
getResource
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:
resourceManager- The object that is managing the resource allocationresource- The resource that we are releasing- Throws:
ResourceException- If an error occurs
-
releaseAllResources
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
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 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:
Exception- If an error occurs
-
releaseResourceImpl
protected abstract void releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource) throws Exception Subclasses will override this to perform the actual release of the resource.- Parameters:
resourceManager- The object that is managing the resource allocationresource- The resource to release- Throws:
Exception- If an error occurs
-
registerResource
-
deregisterResource
private void deregisterResource(ResourceManager resourceManager, ManagedResource resource) throws ResourceException - Throws:
ResourceException
-