K
- the type of the key to the resourceV
- the type of the resource being pooled@InterfaceAudience.Private public class PoolMap<K,V> extends Object
PoolMap
maps a key to a collection of values, the elements of which are managed
by a pool. In effect, that collection acts as a shared pool of resources, access to which is
closely controlled as per the semantics of the pool.
In case the size of the pool is set to a non-zero positive number, that is used to cap the number
of resources that a pool may contain for any given key. A size of Integer.MAX_VALUE
is
interpreted as an unbounded pool.
PoolMap is thread-safe. It does not remove elements automatically. Unused resources must be closed and removed explicitly.
Modifier and Type | Class and Description |
---|---|
protected static interface |
PoolMap.Pool<R> |
static interface |
PoolMap.PoolResourceSupplier<R> |
static class |
PoolMap.PoolType |
(package private) static class |
PoolMap.RoundRobinPool<R>
|
(package private) static class |
PoolMap.ThreadLocalPool<R>
|
Modifier and Type | Field and Description |
---|---|
private int |
poolMaxSize |
private Map<K,PoolMap.Pool<V>> |
pools |
private PoolMap.PoolType |
poolType |
Constructor and Description |
---|
PoolMap(PoolMap.PoolType poolType,
int poolMaxSize) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
protected PoolMap.Pool<V> |
createPool() |
protected static <V> V |
createResource(PoolMap.PoolResourceSupplier<V> supplier) |
V |
getOrCreate(K key,
PoolMap.PoolResourceSupplier<V> supplier) |
boolean |
remove(K key,
V value) |
List<V> |
values() |
private final Map<K,PoolMap.Pool<V>> pools
private final PoolMap.PoolType poolType
private final int poolMaxSize
public PoolMap(PoolMap.PoolType poolType, int poolMaxSize)
public V getOrCreate(K key, PoolMap.PoolResourceSupplier<V> supplier) throws IOException
IOException
public void clear()
protected static <V> V createResource(PoolMap.PoolResourceSupplier<V> supplier) throws IOException
IOException
protected PoolMap.Pool<V> createPool()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.