Package com.j_spaces.kernel.pool
Class ResourcePool<R extends IResource>
java.lang.Object
com.j_spaces.kernel.pool.ResourcePool<R>
- All Implemented Interfaces:
IResourcePool<R>
- Direct Known Subclasses:
BlockingResourcePool,MemoryBoundedResourcePool
A Bound Pool of Resource objects. At construction,
the pool consumes as many as minResources resources. When a resource requests is
submitted, and less than maxResources are being used, a free resource will be returned
from the pool. When all resources are in use, a new Resource will be allocated by the resourceFactory. There can be no more than
maxResources in the pool, and excessive resources are discarded.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionResourcePool(IResourceFactory<R> resourceFactory, int minResources, int maxResources) Creates a new Resources Pool with the specified resourceFactory, and max Resources.protectedResourcePool(IResourceFactory<R> resourceFactory, int minResources, int maxResources, R[] initialResources) Creates a new Resources Pool with the specified resourceFactory, and max Resources. -
Method Summary
Modifier and TypeMethodDescriptionintvoidforAllResources(IResourceProcedure<R> procedure) voidfreeResource(R resourceToFree) Free the specified resource.getResource(boolean waitIfNeeded) Returns a Resource from the pool.protected RhandleFullPool(boolean waitIfNeeded) intsize()protected R
-
Constructor Details
-
ResourcePool
Creates a new Resources Pool with the specified resourceFactory, and max Resources.- Parameters:
resourceFactory- resource factory instance for new resourcesminResources- resources to pre-allocate; can be zeromaxResources- upper bound on the number of resources
-
ResourcePool
protected ResourcePool(IResourceFactory<R> resourceFactory, int minResources, int maxResources, R[] initialResources) Creates a new Resources Pool with the specified resourceFactory, and max Resources.- Parameters:
resourceFactory- resource factory instance for new resourcesminResources- resources to pre-allocate; can be zeromaxResources- upper bound on the number of resourcesinitialResources- initial array of resources to init the pool with
-
-
Method Details
-
getResource
- Specified by:
getResourcein interfaceIResourcePool<R extends IResource>
-
getResource
Returns a Resource from the pool. If there is an un-used Resource in the pool, it is returned; otherwise, a new Resource is created and added to the pool.- Specified by:
getResourcein interfaceIResourcePool<R extends IResource>- Returns:
- free Resource allocated to this request
-
tryAllocateNewPooledResource
-
handleFullPool
-
freeResource
Free the specified resource. Same as callingIResource.release()- Specified by:
freeResourcein interfaceIResourcePool<R extends IResource>
-
availableResources
public int availableResources()- Specified by:
availableResourcesin interfaceIResourcePool<R extends IResource>
-
size
public int size()- Specified by:
sizein interfaceIResourcePool<R extends IResource>
-
forAllResources
- Specified by:
forAllResourcesin interfaceIResourcePool<R extends IResource>
-