org.idevlab.rjc.ds
Class PoolableDataSourceFactory

java.lang.Object
  extended by org.idevlab.rjc.ds.PoolableDataSourceFactory
All Implemented Interfaces:
DataSourceFactory

public class PoolableDataSourceFactory
extends Object
implements DataSourceFactory

Author:
Evgeny Dolgov

Field Summary
protected  int initialSize
          The initial number of connections that are created when the pool is started.
protected  int maxActive
          The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.
protected  int maxIdle
          The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.
protected  long maxWait
          The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or <= 0 to wait indefinitely.
protected  long minEvictableIdleTimeMillis
          The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).
protected  int minIdle
          The minimum number of active connections that can remain idle in the pool, without extra ones being created, or 0 to create none.
protected  int numTestsPerEvictionRun
          The number of objects to examine during each run of the idle object evictor thread (if any).
protected  boolean testOnBorrow
          The indication of whether objects will be validated before being borrowed from the pool.
protected  boolean testOnReturn
          The indication of whether objects will be validated before being returned to the pool.
protected  boolean testWhileIdle
          The indication of whether objects will be validated by the idle object evictor (if any).
protected  long timeBetweenEvictionRunsMillis
          The number of milliseconds to sleep between runs of the idle object evictor thread.
 
Constructor Summary
PoolableDataSourceFactory()
           
 
Method Summary
 DataSource create(String host, int port)
          Creates Redis data source
 int getInitialSize()
          Returns the initial size of the connection pool.
 int getMaxActive()
          Returns the maximum number of active connections that can be allocated at the same time.
 int getMaxIdle()
          Returns the maximum number of connections that can remain idle in the pool.
 long getMaxWait()
          Returns the maximum number of milliseconds that the pool will wait for a connection to be returned before throwing an exception.
 long getMinEvictableIdleTimeMillis()
          Returns the minEvictableIdleTimeMillis property.
 int getMinIdle()
          Returns the minimum number of idle connections in the pool
 int getNumTestsPerEvictionRun()
          Returns the value of the numTestsPerEvictionRun property.
 String getPassword()
           
 boolean getTestOnBorrow()
          Returns the testOnBorrow property.
 boolean getTestOnReturn()
          Returns the value of the testOnReturn property.
 boolean getTestWhileIdle()
          Returns the value of the testWhileIdle property.
 long getTimeBetweenEvictionRunsMillis()
          Returns the value of the timeBetweenEvictionRunsMillis property.
 int getTimeout()
           
 boolean isInitAfterCreation()
           
 void setInitAfterCreation(boolean initAfterCreation)
           
 void setInitialSize(int initialSize)
          Sets the initial size of the connection pool.
 void setMaxActive(int maxActive)
          Sets the maximum number of active connections that can be allocated at the same time.
 void setMaxIdle(int maxIdle)
          Sets the maximum number of connections that can remain idle in the pool.
 void setMaxWait(long maxWait)
          Sets the maxWait property.
 void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
          Sets the minEvictableIdleTimeMillis property.
 void setMinIdle(int minIdle)
          Sets the minimum number of idle connections in the pool.
 void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
          Sets the value of the numTestsPerEvictionRun property.
 void setPassword(String password)
           
 void setTestOnBorrow(boolean testOnBorrow)
          Sets the testOnBorrow property.
 void setTestOnReturn(boolean testOnReturn)
          Sets the testOnReturn property.
 void setTestWhileIdle(boolean testWhileIdle)
          Sets the testWhileIdle property.
 void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
          Sets the timeBetweenEvictionRunsMillis property.
 void setTimeout(int timeout)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxActive

protected int maxActive
The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.


maxIdle

protected int maxIdle
The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit. If maxIdle is set too low on heavily loaded systems it is possible you will see connections being closed and almost immediately new connections being opened. This is a result of the active threads momentarily closing connections faster than they are opening them, causing the number of idle connections to rise above maxIdle. The best value for maxIdle for heavily loaded system will vary but the default is a good starting point.


minIdle

protected int minIdle
The minimum number of active connections that can remain idle in the pool, without extra ones being created, or 0 to create none.


initialSize

protected int initialSize
The initial number of connections that are created when the pool is started.


maxWait

protected long maxWait
The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or <= 0 to wait indefinitely.


testOnBorrow

protected boolean testOnBorrow
The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.


testOnReturn

protected boolean testOnReturn
The indication of whether objects will be validated before being returned to the pool.


timeBetweenEvictionRunsMillis

protected long timeBetweenEvictionRunsMillis
The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.


numTestsPerEvictionRun

protected int numTestsPerEvictionRun
The number of objects to examine during each run of the idle object evictor thread (if any).


minEvictableIdleTimeMillis

protected long minEvictableIdleTimeMillis
The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).


testWhileIdle

protected boolean testWhileIdle
The indication of whether objects will be validated by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool.

Constructor Detail

PoolableDataSourceFactory

public PoolableDataSourceFactory()
Method Detail

create

public DataSource create(String host,
                         int port)
Description copied from interface: DataSourceFactory
Creates Redis data source

Specified by:
create in interface DataSourceFactory
Parameters:
host - Redis host
port - Redis port
Returns:
Redis data source

isInitAfterCreation

public boolean isInitAfterCreation()

setInitAfterCreation

public void setInitAfterCreation(boolean initAfterCreation)

getTimeout

public int getTimeout()

setTimeout

public void setTimeout(int timeout)

getPassword

public String getPassword()

setPassword

public void setPassword(String password)

getMaxActive

public int getMaxActive()

Returns the maximum number of active connections that can be allocated at the same time.

A negative number means that there is no limit.

Returns:
the maximum number of active connections

setMaxActive

public void setMaxActive(int maxActive)
Sets the maximum number of active connections that can be allocated at the same time. Use a negative value for no limit.

Parameters:
maxActive - the new value for maxActive
See Also:
getMaxActive()

getMaxIdle

public int getMaxIdle()

Returns the maximum number of connections that can remain idle in the pool.

A negative value indicates that there is no limit

Returns:
the maximum number of idle connections

setMaxIdle

public void setMaxIdle(int maxIdle)
Sets the maximum number of connections that can remain idle in the pool.

Parameters:
maxIdle - the new value for maxIdle
See Also:
getMaxIdle()

getMinIdle

public int getMinIdle()
Returns the minimum number of idle connections in the pool

Returns:
the minimum number of idle connections
See Also:
GenericObjectPool.getMinIdle()

setMinIdle

public void setMinIdle(int minIdle)
Sets the minimum number of idle connections in the pool.

Parameters:
minIdle - the new value for minIdle
See Also:
GenericObjectPool.setMinIdle(int)

getInitialSize

public int getInitialSize()
Returns the initial size of the connection pool.

Returns:
the number of connections created when the pool is initialized

setInitialSize

public void setInitialSize(int initialSize)

Sets the initial size of the connection pool.

Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first time one of the getConnection method is invoked.

Parameters:
initialSize - the number of connections created when the pool is initialized

getMaxWait

public long getMaxWait()

Returns the maximum number of milliseconds that the pool will wait for a connection to be returned before throwing an exception.

A value less than or equal to zero means the pool is set to wait indefinitely.

Returns:
the maxWait property value

setMaxWait

public void setMaxWait(long maxWait)

Sets the maxWait property.

Use -1 to make the pool wait indefinitely.

Parameters:
maxWait - the new value for maxWait
See Also:
getMaxWait()

getTestOnBorrow

public boolean getTestOnBorrow()
Returns the testOnBorrow property.

Returns:
true if objects are validated before being borrowed from the pool
See Also:
testOnBorrow

setTestOnBorrow

public void setTestOnBorrow(boolean testOnBorrow)
Sets the testOnBorrow property. This property determines whether or not the pool will validate objects before they are borrowed from the pool. For a true value to have any effect, the validationQuery property must be set to a non-null string.

Parameters:
testOnBorrow - new value for testOnBorrow property

getTestOnReturn

public boolean getTestOnReturn()
Returns the value of the testOnReturn property.

Returns:
true if objects are validated before being returned to the pool
See Also:
testOnReturn

setTestOnReturn

public void setTestOnReturn(boolean testOnReturn)
Sets the testOnReturn property. This property determines whether or not the pool will validate objects before they are returned to the pool. For a true value to have any effect, the validationQuery property must be set to a non-null string.

Parameters:
testOnReturn - new value for testOnReturn property

getTimeBetweenEvictionRunsMillis

public long getTimeBetweenEvictionRunsMillis()
Returns the value of the timeBetweenEvictionRunsMillis property.

Returns:
the time (in miliseconds) between evictor runs
See Also:
timeBetweenEvictionRunsMillis

setTimeBetweenEvictionRunsMillis

public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Sets the timeBetweenEvictionRunsMillis property.

Parameters:
timeBetweenEvictionRunsMillis - the new time between evictor runs
See Also:
timeBetweenEvictionRunsMillis

getNumTestsPerEvictionRun

public int getNumTestsPerEvictionRun()
Returns the value of the numTestsPerEvictionRun property.

Returns:
the number of objects to examine during idle object evictor runs
See Also:
numTestsPerEvictionRun

setNumTestsPerEvictionRun

public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Sets the value of the numTestsPerEvictionRun property.

Parameters:
numTestsPerEvictionRun - the new numTestsPerEvictionRun value
See Also:
numTestsPerEvictionRun

getMinEvictableIdleTimeMillis

public long getMinEvictableIdleTimeMillis()
Returns the minEvictableIdleTimeMillis property.

Returns:
the value of the minEvictableIdleTimeMillis property
See Also:
minEvictableIdleTimeMillis

setMinEvictableIdleTimeMillis

public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Sets the minEvictableIdleTimeMillis property.

Parameters:
minEvictableIdleTimeMillis - the minimum amount of time an object may sit idle in the pool
See Also:
minEvictableIdleTimeMillis

getTestWhileIdle

public boolean getTestWhileIdle()
Returns the value of the testWhileIdle property.

Returns:
true if objects examined by the idle object evictor are validated
See Also:
testWhileIdle

setTestWhileIdle

public void setTestWhileIdle(boolean testWhileIdle)
Sets the testWhileIdle property. This property determines whether or not the idle object evictor will validate connections. For a true value to have any effect, the validationQuery property must be set to a non-null string.

Parameters:
testWhileIdle - new value for testWhileIdle property


Copyright © 2011. All Rights Reserved.