Add Closeable to JedisPool.
This allows JedisPool instances to also participate in try-with-resources. Adds tests (both for JedisPool and the Jedis code itself).
This commit is contained in:
committed by
Henning Schmiedehausen
parent
ddb1870a5f
commit
dc054268fa
@@ -1,5 +1,7 @@
|
||||
package redis.clients.util;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
import org.apache.commons.pool2.PooledObjectFactory;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
@@ -7,7 +9,7 @@ import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public abstract class Pool<T> {
|
||||
public abstract class Pool<T> implements Closeable {
|
||||
protected GenericObjectPool<T> internalPool;
|
||||
|
||||
/**
|
||||
@@ -17,6 +19,15 @@ public abstract class Pool<T> {
|
||||
public Pool() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
closeInternalPool();
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return this.internalPool.isClosed();
|
||||
}
|
||||
|
||||
public Pool(final GenericObjectPoolConfig poolConfig,
|
||||
PooledObjectFactory<T> factory) {
|
||||
initPool(poolConfig, factory);
|
||||
@@ -81,4 +92,4 @@ public abstract class Pool<T> {
|
||||
throw new JedisException("Could not destroy the pool", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user