Class ResourcePool<K,V>
- java.lang.Object
-
- org.apache.druid.java.util.http.client.pool.ResourcePool<K,V>
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class ResourcePool<K,V> extends Object implements Closeable
A resource pool based onLoadingCache. When a resource is first requested for a new key, If the flag: eagerInitialization is true: useResourcePool.EagerCreationResourceHolderResourcePoolConfig.getMaxPerKey()resources are initialized and cached in thepool. Else: Initialize a single resource and further lazily usingResourcePool.LazyCreationResourceHolderThe individual resource inResourcePool.ResourceHolderPerKeyis valid while (current time - last access time) <=ResourcePoolConfig.getUnusedConnectionTimeoutMillis(). A resource is closed and reinitialized ifResourceFactory.isGood(V)returns false or it's expired based onResourcePoolConfig.getUnusedConnectionTimeoutMillis().is a hard limit for the max number of resources per cache entry. The total number of resources in {@link ResourceHolderPerKey} cannot be larger than the limit in any case.
-
-
Constructor Summary
Constructors Constructor Description ResourcePool(ResourceFactory<K,V> factory, ResourcePoolConfig config, boolean eagerInitialization)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ResourceContainer<V>take(K key)Returns aResourceContainerfor the given key or null if this pool is already closed.
-
-
-
Constructor Detail
-
ResourcePool
public ResourcePool(ResourceFactory<K,V> factory, ResourcePoolConfig config, boolean eagerInitialization)
-
-
Method Detail
-
take
@Nullable public ResourceContainer<V> take(K key)
Returns aResourceContainerfor the given key or null if this pool is already closed.
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-