use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project cas by apereo.
the class MemcachedPooledClientConnectionFactory method getObjectPool.
/**
* Gets object pool.
*
* @return the object pool
*/
public ObjectPool<MemcachedClientIF> getObjectPool() {
val pool = new GenericObjectPool<>(this);
pool.setMaxIdle(memcachedProperties.getMaxIdle());
pool.setMinIdle(memcachedProperties.getMinIdle());
pool.setMaxTotal(memcachedProperties.getMaxTotal());
return pool;
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project cas by apereo.
the class MemcachedMonitorConfiguration method memcachedHealthClientPool.
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "memcachedHealthClientPool")
public ObjectPool<MemcachedClientIF> memcachedHealthClientPool(@Qualifier("memcachedMonitorTranscoder") final Transcoder memcachedMonitorTranscoder, final CasConfigurationProperties casProperties) {
val memcached = casProperties.getMonitor().getMemcached();
val factory = new MemcachedPooledClientConnectionFactory(memcached, memcachedMonitorTranscoder);
return new GenericObjectPool<>(factory);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project ddf by codice.
the class SslLdapLoginModule method installLdapConnectionPool.
private void installLdapConnectionPool(String connectionPoolId) {
BundleContext bundleContext = getContext();
if (bundleContext != null) {
try {
Collection<ServiceReference<GenericObjectPool>> serviceReferences = bundleContext.getServiceReferences(GenericObjectPool.class, String.format("(id=%s)", connectionPoolId));
ServiceReference<GenericObjectPool> serviceReference = serviceReferences.stream().findFirst().orElseThrow(() -> new IllegalStateException("No LDAPConnectionPool service found with id:" + connectionPoolId));
ldapConnectionPool = bundleContext.getService(serviceReference);
} catch (InvalidSyntaxException | IllegalStateException e) {
LOGGER.error("Unable to get LDAP Connection pool. LDAP log in will not be possible.", e);
}
}
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project kork by spinnaker.
the class JedisHealthIndicatorFactory method build.
public static HealthIndicator build(Pool<Jedis> jedisPool) {
try {
final Pool<Jedis> src = jedisPool;
final Field poolAccess = Pool.class.getDeclaredField("internalPool");
poolAccess.setAccessible(true);
GenericObjectPool<Jedis> internal = (GenericObjectPool<Jedis>) poolAccess.get(jedisPool);
return () -> {
Jedis jedis = null;
Health.Builder health;
try {
jedis = src.getResource();
if ("PONG".equals(jedis.ping())) {
health = Health.up();
} else {
health = Health.down();
}
} catch (Exception ex) {
health = Health.down(ex);
} finally {
if (jedis != null)
jedis.close();
}
health.withDetail("maxIdle", internal.getMaxIdle());
health.withDetail("minIdle", internal.getMinIdle());
health.withDetail("numActive", internal.getNumActive());
health.withDetail("numIdle", internal.getNumIdle());
health.withDetail("numWaiters", internal.getNumWaiters());
return health.build();
};
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new BeanCreationException("Error creating Redis health indicator", e);
}
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project atlasdb by palantir.
the class CassandraClientPoolingContainer method createClientPool.
/**
* Pool size:
* Always keep {@link CassandraKeyValueServiceConfig#poolSize()} connections around, per host. Allow bursting
* up to {@link CassandraKeyValueServiceConfig#maxConnectionBurstSize()} connections per host under load.
*
* Borrowing from pool:
* On borrow, check if the connection is actually open. If it is not,
* immediately discard this connection from the pool, and try to take another.
* Borrow attempts against a fully in-use pool immediately throw a NoSuchElementException.
* {@code CassandraClientPool} when it sees this will:
* Follow an exponential backoff as a method of back pressure.
* Try 3 times against this host, and then give up and try against different hosts 3 additional times.
*
* In an asynchronous thread (using default values):
* Every 20-30 seconds, examine approximately a tenth of the connections in pool.
* Discard any connections in this tenth of the pool whose TCP connections are closed.
* Discard any connections in this tenth of the pool that have been idle for more than 10 minutes,
* while still keeping a minimum number of idle connections around for fast borrows.
*/
private GenericObjectPool<CassandraClient> createClientPool() {
CassandraClientConfig clientConfig = CassandraClientConfig.of(config);
CassandraClientFactory cassandraClientFactory = new CassandraClientFactory(metricsManager, proxy, clientConfig);
GenericObjectPoolConfig<CassandraClient> poolConfig = new GenericObjectPoolConfig<>();
poolConfig.setMinIdle(config.poolSize());
poolConfig.setMaxIdle(config.maxConnectionBurstSize());
poolConfig.setMaxTotal(config.maxConnectionBurstSize());
// immediately throw when we try and borrow from a full pool; dealt with at higher level
poolConfig.setBlockWhenExhausted(false);
// this test is free/just checks a boolean and does not block; borrow is still fast
poolConfig.setTestOnBorrow(true);
poolConfig.setSoftMinEvictableIdleTimeMillis(TimeUnit.MILLISECONDS.convert(Duration.ofSeconds(config.idleConnectionTimeoutSeconds())));
poolConfig.setMinEvictableIdleTimeMillis(Long.MAX_VALUE);
// the randomness here is to prevent all of the pools for all of the hosts
// evicting all at at once, which isn't great for C*.
int timeBetweenEvictionsSeconds = config.timeBetweenConnectionEvictionRunsSeconds();
int delta = ThreadLocalRandom.current().nextInt(Math.min(timeBetweenEvictionsSeconds / 2, 10));
poolConfig.setTimeBetweenEvictionRunsMillis(TimeUnit.MILLISECONDS.convert(Duration.ofSeconds(timeBetweenEvictionsSeconds + delta)));
poolConfig.setNumTestsPerEvictionRun(-(int) (1.0 / config.proportionConnectionsToCheckPerEvictionRun()));
poolConfig.setTestWhileIdle(true);
poolConfig.setJmxNamePrefix(proxy.getHostString());
poolConfig.setEvictionPolicy(new DefaultEvictionPolicy<>());
GenericObjectPool<CassandraClient> pool = new GenericObjectPool<>(cassandraClientFactory, poolConfig);
pool.setSwallowedExceptionListener(exception -> log.info("Swallowed exception within object pool", exception));
registerMetrics(pool);
log.info("Creating a Cassandra client pool for {} with the configuration {}", SafeArg.of("cassandraHost", cassandraServer.cassandraHostName()), SafeArg.of("proxy", proxy), SafeArg.of("poolConfig", poolConfig));
return pool;
}
Aggregations