replace custom pool implementation with apache's

This commit is contained in:
Jonathan Leibiusky
2010-11-21 18:16:31 -03:00
parent e7582644b1
commit 71eb4c5b4a
6 changed files with 236 additions and 238 deletions

View File

@@ -0,0 +1,30 @@
package redis.clients.util;
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.impl.GenericObjectPool;
public abstract class Pool<T> {
private final GenericObjectPool internalPool;
public Pool(final GenericObjectPool.Config poolConfig,
PoolableObjectFactory factory) {
this.internalPool = new GenericObjectPool(factory, poolConfig);
}
@SuppressWarnings("unchecked")
public T getResource() throws Exception {
return (T) internalPool.borrowObject();
}
public void returnResource(final T resource) throws Exception {
internalPool.returnObject(resource);
}
public void returnBrokenResource(final T resource) throws Exception {
internalPool.invalidateObject(resource);
}
public void destroy() throws Exception {
internalPool.close();
}
}