ClusterKey - Anything, to identify a group of resources pools. For example String if your cluster
* keys are going to be "cluster1", "cluster2" etc. Or UUID for uuid's (or again String for UUID.toString()).PoolKey - The resource for which multiple objects will be created in a generic-object-pool object pool.Session object for which multiple Transport connections can be created.T - The resulting PoolableObject object that the allocators will create for the pool key.PoolKey is Session, then T could be Transport.public class ResourceClusters<ClusterKey,PoolKey,T> extends Object
Can be used to configure high performance clusters of expensive resources that have a time-to-live.
Example use case:
Say you have two different mail clusters, each with several servers and each server able to handle multiple concurrent SMTP connections.
The two cluster keys to the clusters, where each server is accessed round robin, and the objects in the respective cluster-pool are concurrent
open connections to the same mail server.
| Constructor and Description |
|---|
ResourceClusters(ClusterConfig<PoolKey,T> clusterConfig) |
| Modifier and Type | Method and Description |
|---|---|
@Nullable org.bbottema.genericobjectpool.PoolableObject<T> |
claimResourceFromCluster(ClusterKey clusterKey)
Tries to claim the next resources from a pool in the given cluster.
|
@Nullable org.bbottema.genericobjectpool.PoolableObject<T> |
claimResourceFromPool(ResourceKey<ClusterKey,PoolKey> key)
Tries to claim the next resources from the pool in the given cluster.
|
int |
countLiveResources() |
boolean |
isPoolRegistered(@NotNull ResourceKey<ClusterKey,PoolKey> key) |
void |
registerResourcePool(ResourceKey<ClusterKey,PoolKey> key)
Delegates to
registerResourcePool(ResourceKey, ExpirationPolicy, int, int), using the global defaults for expiration policy, max pool size and sizing mode. |
void |
registerResourcePool(@NotNull ResourceKey<ClusterKey,PoolKey> key,
@NotNull org.bbottema.genericobjectpool.ExpirationPolicy<T> expirationPolicy,
int corePoolSize,
int maxPoolSize)
Registers a new pool for the given cluster.
|
Future<?> |
shutDown()
Delegates to
shutdownPool(Object) with empty pool key. |
Future<Void> |
shutdownPool(PoolKey key)
Tells all generic-object-pool pools [for the specified pool key] to shutdown and removes them from the clusters.
|
public ResourceClusters(ClusterConfig<PoolKey,T> clusterConfig)
public void registerResourcePool(ResourceKey<ClusterKey,PoolKey> key)
registerResourcePool(ResourceKey, ExpirationPolicy, int, int), using the global defaults for expiration policy, max pool size and sizing mode.public void registerResourcePool(@NotNull
@NotNull ResourceKey<ClusterKey,PoolKey> key,
@NotNull
@NotNull org.bbottema.genericobjectpool.ExpirationPolicy<T> expirationPolicy,
int corePoolSize,
int maxPoolSize)
throws IllegalArgumentException
GenericObjectPool.IllegalArgumentException - if the pool already exists in the specified cluster.public boolean isPoolRegistered(@NotNull
@NotNull ResourceKey<ClusterKey,PoolKey> key)
@Nullable public @Nullable org.bbottema.genericobjectpool.PoolableObject<T> claimResourceFromCluster(ClusterKey clusterKey) throws InterruptedException
Either preregister pools using claimResourceFromPool(ResourceKey) or dynamically add pools on-the-fly
using registerResourcePool(ResourceKey) or registerResourcePool(ResourceKey, ExpirationPolicy, int, int).
InterruptedException@Nullable public @Nullable org.bbottema.genericobjectpool.PoolableObject<T> claimResourceFromPool(ResourceKey<ClusterKey,PoolKey> key) throws InterruptedException
InterruptedExceptionpublic int countLiveResources()
public Future<?> shutDown()
shutdownPool(Object) with empty pool key.Copyright © 2019–2024. All rights reserved.