public class ResourcePool<R extends IResource> extends Object implements IResourcePool<R>
Modifier and Type | Field and Description |
---|---|
protected R[] |
_resourcesPool
pool of resources
|
Modifier | Constructor and Description |
---|---|
|
ResourcePool(IResourceFactory<R> resourceFactory,
int minResources,
int maxResources)
Creates a new Resources Pool with the specified resourceFactory, and max Resources.
|
protected |
ResourcePool(IResourceFactory<R> resourceFactory,
int minResources,
int maxResources,
R[] initialResources)
Creates a new Resources Pool with the specified resourceFactory, and max Resources.
|
Modifier and Type | Method and Description |
---|---|
int |
availableResources() |
protected R |
findFreeResource() |
void |
forAllResources(IResourceProcedure<R> procedure) |
void |
freeResource(R resourceToFree)
Free the specified resource.
|
R |
getResource()
Returns a Resource from the pool.
|
protected R |
handleFullPool() |
int |
size() |
protected R |
tryAllocateNewPooledResource() |
public ResourcePool(IResourceFactory<R> resourceFactory, int minResources, int maxResources)
resourceFactory
- resource factory instance for new resourcesminResources
- resources to pre-allocate; can be zeromaxResources
- upper bound on the number of resourcesprotected ResourcePool(IResourceFactory<R> resourceFactory, int minResources, int maxResources, R[] initialResources)
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 withpublic R getResource()
getResource
in interface IResourcePool<R extends IResource>
protected R tryAllocateNewPooledResource()
protected R findFreeResource()
protected R handleFullPool()
public void freeResource(R resourceToFree)
IResource.release()
freeResource
in interface IResourcePool<R extends IResource>
public int availableResources()
availableResources
in interface IResourcePool<R extends IResource>
public int size()
size
in interface IResourcePool<R extends IResource>
public void forAllResources(IResourceProcedure<R> procedure)
forAllResources
in interface IResourcePool<R extends IResource>
Copyright © GigaSpaces.