add defaults to pool config

This commit is contained in:
Jonathan Leibiusky
2011-01-20 16:02:23 -03:00
parent 1d5589f247
commit 2896ddddeb

View File

@@ -4,144 +4,128 @@ import org.apache.commons.pool.impl.GenericObjectPool.Config;
/** /**
* Subclass of org.apache.commons.pool.impl.GenericObjectPool.Config that * Subclass of org.apache.commons.pool.impl.GenericObjectPool.Config that
* includes getters/setters so it can be more easily configured by Spring * includes getters/setters so it can be more easily configured by Spring and
* and other IoC frameworks. * other IoC frameworks.
* *
* Spring example: * Spring example:
* *
* <bean id="jedisConfig" class="redis.clients.jedis.JedisPoolConfig"> * <bean id="jedisConfig" class="redis.clients.jedis.JedisPoolConfig"> <property
* <property name="testWhileIdle" value="true"/> * name="testWhileIdle" value="true"/> </bean>
* </bean>
* *
* <bean id="jedisPool" class="redis.clients.jedis.JedisPool" destroy-method="destroy"> * <bean id="jedisPool" class="redis.clients.jedis.JedisPool"
* <constructor-arg ref="jedisConfig" /> * destroy-method="destroy"> <constructor-arg ref="jedisConfig" />
* <constructor-arg value="localhost" /> * <constructor-arg value="localhost" /> <constructor-arg type="int"
* <constructor-arg type="int" value="6379" /> * value="6379" /> </bean>
* </bean>
* *
* For information on parameters refer to: * For information on parameters refer to:
* *
* http://commons.apache.org/pool/apidocs/org/apache/commons/pool/impl/GenericObjectPool.html * http://commons.apache.org/pool/apidocs/org/apache/commons/pool/impl/
* GenericObjectPool.html
*/ */
public class JedisPoolConfig extends Config public class JedisPoolConfig extends Config {
{ public JedisPoolConfig() {
public int getMaxIdle() // defaults to make your life with connection pool easier :)
{ setTestWhileIdle(true);
setMinEvictableIdleTimeMillis(60000);
setTimeBetweenEvictionRunsMillis(30000);
setNumTestsPerEvictionRun(-1);
}
public int getMaxIdle() {
return maxIdle; return maxIdle;
} }
public void setMaxIdle(int maxIdle) public void setMaxIdle(int maxIdle) {
{
this.maxIdle = maxIdle; this.maxIdle = maxIdle;
} }
public int getMinIdle() public int getMinIdle() {
{
return minIdle; return minIdle;
} }
public void setMinIdle(int minIdle) public void setMinIdle(int minIdle) {
{
this.minIdle = minIdle; this.minIdle = minIdle;
} }
public int getMaxActive() public int getMaxActive() {
{
return maxActive; return maxActive;
} }
public void setMaxActive(int maxActive) public void setMaxActive(int maxActive) {
{
this.maxActive = maxActive; this.maxActive = maxActive;
} }
public long getMaxWait() public long getMaxWait() {
{
return maxWait; return maxWait;
} }
public void setMaxWait(long maxWait) public void setMaxWait(long maxWait) {
{
this.maxWait = maxWait; this.maxWait = maxWait;
} }
public byte getWhenExhaustedAction() public byte getWhenExhaustedAction() {
{
return whenExhaustedAction; return whenExhaustedAction;
} }
public void setWhenExhaustedAction(byte whenExhaustedAction) public void setWhenExhaustedAction(byte whenExhaustedAction) {
{
this.whenExhaustedAction = whenExhaustedAction; this.whenExhaustedAction = whenExhaustedAction;
} }
public boolean isTestOnBorrow() public boolean isTestOnBorrow() {
{
return testOnBorrow; return testOnBorrow;
} }
public void setTestOnBorrow(boolean testOnBorrow) public void setTestOnBorrow(boolean testOnBorrow) {
{
this.testOnBorrow = testOnBorrow; this.testOnBorrow = testOnBorrow;
} }
public boolean isTestOnReturn() public boolean isTestOnReturn() {
{
return testOnReturn; return testOnReturn;
} }
public void setTestOnReturn(boolean testOnReturn) public void setTestOnReturn(boolean testOnReturn) {
{
this.testOnReturn = testOnReturn; this.testOnReturn = testOnReturn;
} }
public boolean isTestWhileIdle() public boolean isTestWhileIdle() {
{
return testWhileIdle; return testWhileIdle;
} }
public void setTestWhileIdle(boolean testWhileIdle) public void setTestWhileIdle(boolean testWhileIdle) {
{
this.testWhileIdle = testWhileIdle; this.testWhileIdle = testWhileIdle;
} }
public long getTimeBetweenEvictionRunsMillis() public long getTimeBetweenEvictionRunsMillis() {
{
return timeBetweenEvictionRunsMillis; return timeBetweenEvictionRunsMillis;
} }
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) public void setTimeBetweenEvictionRunsMillis(
{ long timeBetweenEvictionRunsMillis) {
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
} }
public int getNumTestsPerEvictionRun() public int getNumTestsPerEvictionRun() {
{
return numTestsPerEvictionRun; return numTestsPerEvictionRun;
} }
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
{
this.numTestsPerEvictionRun = numTestsPerEvictionRun; this.numTestsPerEvictionRun = numTestsPerEvictionRun;
} }
public long getMinEvictableIdleTimeMillis() public long getMinEvictableIdleTimeMillis() {
{
return minEvictableIdleTimeMillis; return minEvictableIdleTimeMillis;
} }
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
{
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
} }
public long getSoftMinEvictableIdleTimeMillis() public long getSoftMinEvictableIdleTimeMillis() {
{
return softMinEvictableIdleTimeMillis; return softMinEvictableIdleTimeMillis;
} }
public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) public void setSoftMinEvictableIdleTimeMillis(
{ long softMinEvictableIdleTimeMillis) {
this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
} }