redis.clients.util
Class FixedResourcePool<T>

java.lang.Object
  extended by redis.clients.util.FixedResourcePool<T>
Type Parameters:
T - The type of the resource to be managed.
Direct Known Subclasses:
JedisPool

public abstract class FixedResourcePool<T>
extends Object

Abstract resource pool of type T. Needs implementation for creation, validation and destruction of the resources. Keeps a fixed amount of resources

Author:
Luis Dario Simonassi

Nested Class Summary
static class FixedResourcePool.Metrics
           
protected  class FixedResourcePool.RepairThread
          Generic Repair Thread
 
Constructor Summary
FixedResourcePool()
           
 
Method Summary
protected  void checkInit()
           
protected abstract  T createResource()
          Create a resource for the pool.
 void destroy()
          Destroy the pool.
protected abstract  void destroyResource(T resource)
          Destroy a resource.
 long getDefaultPoolWait()
           
 long getDestructionWait()
           
 String getName()
           
 int getRepairThreadsNumber()
           
 T getResource()
          Get a resource from the pool waiting the default time.
 T getResource(long maxTime)
          Get a resource from the pool.
 int getResourcesNumber()
           
 long getTimeBetweenValidation()
           
 void init()
          Initialize the pool
protected abstract  boolean isResourceValid(T resource)
          Check if the resource is still valid.
 void returnBrokenResource(T resource)
          Return a broken resource to the pool.
 void returnResource(T resource)
          Return a resource to the pool.
 void setDefaultPoolWait(long defaultPoolWait)
           
 void setDestructionWait(long destructionWait)
           
 void setName(String name)
           
 void setRepairThreadsNumber(int repairThreadsNumber)
           
 void setResourcesNumber(int resourcesNumber)
           
 void setTimeBetweenValidation(long timeBetweenValidation)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FixedResourcePool

public FixedResourcePool()
Method Detail

getResourcesNumber

public int getResourcesNumber()

setResourcesNumber

public void setResourcesNumber(int resourcesNumber)

getRepairThreadsNumber

public int getRepairThreadsNumber()

setRepairThreadsNumber

public void setRepairThreadsNumber(int repairThreadsNumber)

getTimeBetweenValidation

public long getTimeBetweenValidation()

setTimeBetweenValidation

public void setTimeBetweenValidation(long timeBetweenValidation)

getDestructionWait

public long getDestructionWait()

setDestructionWait

public void setDestructionWait(long destructionWait)

setName

public void setName(String name)

getName

public String getName()

setDefaultPoolWait

public void setDefaultPoolWait(long defaultPoolWait)

getDefaultPoolWait

public long getDefaultPoolWait()

init

public void init()
Initialize the pool


destroy

public void destroy()
Destroy the pool. After being destroyed the pool can be initialized again.


checkInit

protected void checkInit()

returnResource

public void returnResource(T resource)
Return a resource to the pool. When no longer needed.

Parameters:
resource -

returnBrokenResource

public void returnBrokenResource(T resource)
Return a broken resource to the pool. If the application detects a malfunction of the resource. This resources will go directly to the repair queue.

Parameters:
resource -

getResource

public T getResource()
              throws TimeoutException
Get a resource from the pool waiting the default time. setDefaultPoolWait(long)

Returns:
the resource of type T
Throws:
TimeoutException

getResource

public T getResource(long maxTime)
              throws TimeoutException
Get a resource from the pool.

Parameters:
maxTime - Max time you would like to wait for the resource
Returns:
Throws:
TimeoutException

createResource

protected abstract T createResource()
Create a resource for the pool. This method is always called from the REPAIR threads. If it's impossible to create the resource, this method should wait or hold until resource creation becomes possible.


isResourceValid

protected abstract boolean isResourceValid(T resource)
Check if the resource is still valid.

Parameters:
resource -
Returns:

destroyResource

protected abstract void destroyResource(T resource)
Destroy a resource.

Parameters:
resource -

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010. All Rights Reserved.