Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Project Rio
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jini.rio.resources.resource
Class ResourcePool

    java.lang.Object
      org.jini.rio.resources.resource.ResourcePool

Direct Known Subclasses:
  ThreadPool

    public abstract class ResourcePool

extends Object

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

### freed

    protected LinkedList freed

  The free list

### alloced

    protected LinkedList alloced

  The alloced list

### min

    protected int min

  The minimum # of resources to create at init time

### max

    protected int max

  The maximum # of resources allowed

### numCreated

    protected int numCreated

  The total number of resources currently created

### identifier

    protected String identifier

  Unique identifier for a resourcePool instance

Constructor Detail

### ResourcePool

    public ResourcePool()

Method Detail

### create

    protected abstract Object create()
                              throws ResourceUnavailableException

  Abstract method for creating a specific resource in the sub-class

  Returns:
    the resource
  Throws:
    `ResourceUnavailableException` - if an error occured in creating the resource

### dispose

    protected abstract void dispose(Object obj)

  Abstract method for disposing a specific resource in the sub-class

  Parameters:
    `obj` - the resource to dispose

### validate

    protected abstract boolean validate(Object obj)

  Abstract method for validating a resource

  Parameters:
    `obj` - the resource to validate
  Returns:
    true if resource is still valid

### release

    public void release(Object obj)

  Release a resource back to the pool after its use is completed.

  Parameters:
    `obj` - the resource object

### remove

    public void remove(Object obj)

  Remove a resource all together from the pool and dispose of it

  Parameters:
    `obj` - the resource object

### get

    public Object get()
               throws ResourceUnavailableException

  Get a Resource from the pool, blocking forever until a resource becomes available

  Returns:
    the resource object
  Throws:
    `ResourceUnavailableException` - if an error occured in creating the resource

### get

    public Object get(long timeout)
               throws ResourceUnavailableException

  Get a Resource from the pool, blocking for a specified time until a resource becomes available, a zero timeout blocks forever.

  Parameters:
    `timeout` - the time in milliseconds to wait for a resource to become available
  Returns:
    the resource object
  Throws:
    `ResourceUnavailableException` - if an error occured in creating the resource

### createResource

    protected Object createResource()
                             throws ResourceUnavailableException

  creates a new Resource and performs any initilization required to manage the resource

  Returns:
    the new resource
  Throws:
    `ResourceUnavailableException` - if an error occured in creating the resource

### allocResource

    protected void allocResource(Object resource)

  allocates a Resource and performs any initilization required to manage the alloced resource

  Parameters:
    `resource` - the resource to allocate

### freeResource

    protected void freeResource(Object resource)

  frees a Resource and performs any clean-up required to manage the resource

  Parameters:
    `resource` - the resource to free

### disposeResource

    protected void disposeResource(Object resource)

  disposes of a Resource and performs any clean-up required to manage the resource

  Parameters:
    `resource` - the resource to dispose

### getFreedSize

    public int getFreedSize()

  Gets the number of resources currently available for assignment

  Returns:
    the number of resources currently available for assignment

### getAllocedSize

    public int getAllocedSize()

  Gets the number of resources currently assigned

  Returns:
    the number of resources currently assigned

### getSize

    public int getSize()

  Gets the total number of resources created

  Returns:
    the total number of resources created

### getMin

    public int getMin()

  Gets the minimum number of resources

  Returns:
    the minimum number of resources

### getMax

    public int getMax()

  Gets the maximum number of resources allowed

  Returns:
    the maximum number of resources allowed

### setMin

    public 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.

  Parameters:
    `min` - the minimum number of resources
  Throws:
    `IllegalArgumentException` - if minimum is less than zero or the minimum is is greater than the maximum

### setIdentifier

    public void setIdentifier(String identifier)

  Sets the unique identifier for this instance

  Parameters:
    `identifier` - the unique identifier for this instance

### getIdentifier

    public String getIdentifier()

  Gets the unique identifier for this instance

  Returns:
    the unique identifier for this instance

### createResources

    protected void createResources()
                            throws ResourceUnavailableException

  Pre-creates the minimum number of resources

  Throws:
    `ResourceUnavailableException` - if an error occured in creating the resource

### createResources

    protected void createResources(int number)
                            throws ResourceUnavailableException

  Pre-creates the specified number of resources

  Parameters:
    `number` - the number of resources to create
  Throws:
    `ResourceUnavailableException` - if an error occured in creating the resource

### setMax

    public void setMax(int max)

  Sets the maximum number of resources

  Parameters:
    `max` - the maximum number of resources
  Throws:
    `IllegalArgumentException` - if maximum is less than the minimum

### getInstance

    public static ResourcePool getInstance(String key)

  Gets a registered ResourcePool

  Parameters:
    `key` - the identifier for the type of resource pool
  Returns:
    the resource pool or null, if one is not registered for the key.

### register

    protected void register()

  Registers this resource into the common ResourcePool

### register

    protected void register(String key)

  Registers this resource into the common ResourcePool

  Parameters:
    `key` - the identifier for the type of resource pool

### register

    public static void register(String key,
                                ResourcePool pool)

  Registers a resource into the common ResourcePool

  Parameters:
    `key` - the identifier for the type of resource pool
    `pool` - the ResourcePool being registered

### toString

    public String toString()

  Returns a string representation of the ResourcePool

  Overrides:
    `toString` in class `Object`
  Returns:
    a string representation of the ResourcePool

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Project Rio
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © Project Rio.