|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jini.rio.resources.resource.ResourcePool
public abstract class ResourcePool
A generic abstract class to handle a finite set of resources
Field Summary | |
---|---|
protected LinkedList |
alloced
The alloced list |
protected LinkedList |
freed
The free list |
protected String |
identifier
Unique identifier for a resourcePool instance |
protected int |
max
The maximum # of resources allowed |
protected int |
min
The minimum # of resources to create at init time |
protected int |
numCreated
The total number of resources currently created |
Constructor Summary | |
---|---|
ResourcePool()
|
Method Summary | |
---|---|
protected void |
allocResource(Object resource)
allocates a Resource and performs any initilization required to manage the alloced resource |
protected abstract Object |
create()
Abstract method for creating a specific resource in the sub-class |
protected Object |
createResource()
creates a new Resource and performs any initilization required to manage the resource |
protected void |
createResources()
Pre-creates the minimum number of resources |
protected void |
createResources(int number)
Pre-creates the specified number of resources |
protected abstract void |
dispose(Object obj)
Abstract method for disposing a specific resource in the sub-class |
protected void |
disposeResource(Object resource)
disposes of a Resource and performs any clean-up required to manage the resource |
protected void |
freeResource(Object resource)
frees a Resource and performs any clean-up required to manage the resource |
Object |
get()
Get a Resource from the pool, blocking forever until a resource becomes available |
Object |
get(long timeout)
Get a Resource from the pool, blocking for a specified time until a resource becomes available, a zero timeout blocks forever. |
int |
getAllocedSize()
Gets the number of resources currently assigned |
int |
getFreedSize()
Gets the number of resources currently available for assignment |
String |
getIdentifier()
Gets the unique identifier for this instance |
static ResourcePool |
getInstance(String key)
Gets a registered ResourcePool |
int |
getMax()
Gets the maximum number of resources allowed |
int |
getMin()
Gets the minimum number of resources |
int |
getSize()
Gets the total number of resources created |
protected void |
register()
Registers this resource into the common ResourcePool |
protected void |
register(String key)
Registers this resource into the common ResourcePool |
static void |
register(String key,
ResourcePool pool)
Registers a resource into the common ResourcePool |
void |
release(Object obj)
Release a resource back to the pool after its use is completed. |
void |
remove(Object obj)
Remove a resource all together from the pool and dispose of it |
void |
setIdentifier(String identifier)
Sets the unique identifier for this instance |
void |
setMax(int max)
Sets the maximum number of resources |
void |
setMin(int min)
Sets the minimum number of resources, this method has no effect on the number of created resources, if the new minimum is less than the old minimum. |
String |
toString()
Returns a string representation of the ResourcePool |
protected abstract boolean |
validate(Object obj)
Abstract method for validating a resource |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected LinkedList freed
protected LinkedList alloced
protected int min
protected int max
protected int numCreated
protected String identifier
Constructor Detail |
---|
public ResourcePool()
Method Detail |
---|
protected abstract Object create() throws ResourceUnavailableException
ResourceUnavailableException
- if an error occured in creating
the resourceprotected abstract void dispose(Object obj)
obj
- the resource to disposeprotected abstract boolean validate(Object obj)
obj
- the resource to validate
public void release(Object obj)
obj
- the resource objectpublic void remove(Object obj)
obj
- the resource objectpublic Object get() throws ResourceUnavailableException
ResourceUnavailableException
- if an error occured in creating
the resourcepublic Object get(long timeout) throws ResourceUnavailableException
timeout
- the time in milliseconds to wait for a resource to become
available
ResourceUnavailableException
- if an error occured in creating
the resource
ResourceUnavailableException
- if no resource becomes available
before the timeout period expiresprotected Object createResource() throws ResourceUnavailableException
ResourceUnavailableException
protected void allocResource(Object resource)
resource
- the resource to allocateprotected void freeResource(Object resource)
resource
- the resource to freeprotected void disposeResource(Object resource)
resource
- the resource to disposepublic int getFreedSize()
public int getAllocedSize()
public int getSize()
public int getMin()
public int getMax()
public void setMin(int min)
min
- the minimum number of resources
IllegalArgumentException
- if minimum is less than zero or the
minimum is is greater than the maximumpublic void setIdentifier(String identifier)
identifier
- the unique identifier for this instancepublic String getIdentifier()
protected void createResources() throws ResourceUnavailableException
ResourceUnavailableException
protected void createResources(int number) throws ResourceUnavailableException
number
- the number of resources to create
ResourceUnavailableException
public void setMax(int max)
max
- the maximum number of resources
IllegalArgumentException
- if maximum is less than the minimumpublic static ResourcePool getInstance(String key)
key
- the identifier for the type of resource pool
protected void register()
protected void register(String key)
key
- the identifier for the type of resource poolpublic static void register(String key, ResourcePool pool)
key
- the identifier for the type of resource poolpool
- the ResourcePool being registeredpublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |