public class ResourcePool<R extends IResource> extends Object implements IResourcePool<R>
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() |
void |
forAllResources(IResourceProcedure<R> procedure) |
void |
freeResource(R resourceToFree)
Free the specified resource.
|
R |
getResource() |
R |
getResource(boolean waitIfNeeded)
Returns a Resource from the pool.
|
protected R |
handleFullPool(boolean waitIfNeeded) |
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>
public R getResource(boolean waitIfNeeded)
getResource
in interface IResourcePool<R extends IResource>
protected R tryAllocateNewPooledResource()
protected R handleFullPool(boolean waitIfNeeded)
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.