Package redis.clients.jedis.util
Class Pool<T>
- java.lang.Object
-
- redis.clients.jedis.util.Pool<T>
-
- Type Parameters:
T- the type of objects managed by this pool
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
ConnectionPool,JedisPool
public abstract class Pool<T> extends java.lang.Object implements java.io.CloseableBase pool class for Jedis connections. This class provides the foundation for connection pooling using Apache Commons Pool, matching the original Jedis Pool architecture.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.pool2.impl.GenericObjectPool<T>internalPool
-
Constructor Summary
Constructors Constructor Description Pool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObjects(int count)Add objects to the pool to reach the minimum idle count.voidclose()protected voidcloseInternalPool()Close the internal pool.longgetCreatedCount()Get the total number of resources created by this pool.longgetDestroyedCount()Get the total number of resources destroyed by this pool.longgetMaxBorrowWaitTimeMillis()Get the maximum time threads have waited for resources.intgetMaxTotal()Get the maximum total number of resources in the pool.longgetMeanBorrowWaitTimeMillis()Get the mean time threads wait for resources.intgetNumActive()Get the number of active resources in the pool.intgetNumIdle()Get the number of idle resources in the pool.intgetNumWaiters()Get the number of threads waiting for resources.TgetResource()Get a resource from the pool.voidinitPool(org.apache.commons.pool2.impl.GenericObjectPoolConfig<T> poolConfig, org.apache.commons.pool2.PooledObjectFactory<T> pooledObjectFactory)Initialize the pool with configuration and factory.voidinitPool(org.apache.commons.pool2.PooledObjectFactory<T> pooledObjectFactory)Initialize the pool with a factory.protected voidinvalidateObject(T resource)Invalidate a resource in the pool.booleanisClosed()Check if the pool is closed.voidreturnResource(T resource)Return a resource to the pool (public method following original Jedis pattern).protected voidreturnResourceObject(T resource)Return a resource to the pool.
-
-
-
Field Detail
-
internalPool
protected org.apache.commons.pool2.impl.GenericObjectPool<T> internalPool
-
-
Method Detail
-
initPool
public void initPool(org.apache.commons.pool2.PooledObjectFactory<T> pooledObjectFactory)
Initialize the pool with a factory.- Parameters:
pooledObjectFactory- the factory for creating pooled objects
-
initPool
public void initPool(org.apache.commons.pool2.impl.GenericObjectPoolConfig<T> poolConfig, org.apache.commons.pool2.PooledObjectFactory<T> pooledObjectFactory)
Initialize the pool with configuration and factory.- Parameters:
poolConfig- the pool configurationpooledObjectFactory- the factory for creating pooled objects
-
getResource
public T getResource()
Get a resource from the pool.- Returns:
- a resource from the pool
- Throws:
JedisException- if unable to get a resource
-
returnResourceObject
protected void returnResourceObject(T resource)
Return a resource to the pool.- Parameters:
resource- the resource to return
-
returnResource
public void returnResource(T resource)
Return a resource to the pool (public method following original Jedis pattern).- Parameters:
resource- the resource to return
-
invalidateObject
protected void invalidateObject(T resource)
Invalidate a resource in the pool.- Parameters:
resource- the resource to invalidate
-
getNumActive
public int getNumActive()
Get the number of active resources in the pool.- Returns:
- number of active resources
-
getNumIdle
public int getNumIdle()
Get the number of idle resources in the pool.- Returns:
- number of idle resources
-
getNumWaiters
public int getNumWaiters()
Get the number of threads waiting for resources.- Returns:
- number of waiting threads
-
getMeanBorrowWaitTimeMillis
public long getMeanBorrowWaitTimeMillis()
Get the mean time threads wait for resources.- Returns:
- mean wait time in milliseconds
-
getMaxBorrowWaitTimeMillis
public long getMaxBorrowWaitTimeMillis()
Get the maximum time threads have waited for resources.- Returns:
- maximum wait time in milliseconds
-
getCreatedCount
public long getCreatedCount()
Get the total number of resources created by this pool.- Returns:
- total created count
-
getDestroyedCount
public long getDestroyedCount()
Get the total number of resources destroyed by this pool.- Returns:
- total destroyed count
-
getMaxTotal
public int getMaxTotal()
Get the maximum total number of resources in the pool.- Returns:
- maximum total resources
-
isClosed
public boolean isClosed()
Check if the pool is closed.- Returns:
- true if closed, false otherwise
-
addObjects
public void addObjects(int count)
Add objects to the pool to reach the minimum idle count.
-
closeInternalPool
protected void closeInternalPool()
Close the internal pool.
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-