creamtec.core.util
Class ResourcePool

java.lang.Object
  extended by creamtec.core.util.ResourcePool

public class ResourcePool
extends java.lang.Object


Constructor Summary
ResourcePool(ResourceFactory factory, int maxSize)
           
ResourcePool(ResourceFactory factory, int initSize, int maxSize, int maxFree)
          Manages a pool of resources.
 
Method Summary
 void clear()
          Frees all allocated resources
 int getAllocatedResourceCount()
          Returns the total number of created resources, in and out of the pool
 int getAvailableResourceCount()
          Returns the number of resources currently available in the pool
 int getMaxSize()
          Returns the maximum number of resources allowed
 java.lang.String getName()
           
 java.lang.Object getResource()
          Obtains a resource from the pool if there is one available.
 void putResource(java.lang.Object resource)
          Returns the resource to the pool.
 void setName(java.lang.String name)
          Sets pool name that will be used in tracing
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourcePool

public ResourcePool(ResourceFactory factory,
                    int maxSize)
             throws java.lang.Exception
Throws:
java.lang.Exception

ResourcePool

public ResourcePool(ResourceFactory factory,
                    int initSize,
                    int maxSize,
                    int maxFree)
             throws java.lang.Exception
Manages a pool of resources. Useful to cut down on the number of creating/freeing resources such as database connections, threads and others

Parameters:
factory - Factory responsible for creating and freeing of resources
initSize - Initial size of the pool. initSize resources will be pre-created when the pool is created
maxSize - Maximum size of the pool. No more then maxSize resources can be created
maxFree - Maximum number of free resources to keep in the pool. When maxFree resources are available in the pool and another resource is returned, it will be freed using the Factory rather then pooled
Throws:
java.lang.Exception
Method Detail

getResource

public java.lang.Object getResource()
                             throws java.lang.Exception
Obtains a resource from the pool if there is one available. Otherwise creates it using a factory

Throws:
java.lang.Exception

putResource

public void putResource(java.lang.Object resource)
                 throws java.lang.Exception
Returns the resource to the pool. The resource can be freed if the number of free resources exeeds the number of maximum free resources specified

Throws:
java.lang.Exception

getAvailableResourceCount

public int getAvailableResourceCount()
Returns the number of resources currently available in the pool


getAllocatedResourceCount

public int getAllocatedResourceCount()
Returns the total number of created resources, in and out of the pool


getMaxSize

public int getMaxSize()
Returns the maximum number of resources allowed


clear

public void clear()
           throws java.lang.Exception
Frees all allocated resources

Throws:
java.lang.Exception

setName

public void setName(java.lang.String name)
Sets pool name that will be used in tracing


getName

public java.lang.String getName()


Copyright © 2000-2006 CreamTec LLC. All Rights Reserved.