use of org.apache.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 org.apache.commons.pool2.impl.GenericObjectPool in project athenz by yahoo.
the class DataSourceFactory method create.
static PoolableDataSource create(ConnectionFactory connectionFactory) {
// setup our pool config object
GenericObjectPoolConfig config = setupPoolConfig();
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
// Set max lifetime of a connection in milli-secs, after which it will
// always fail activation, passivation, and validation.
// Value of -1 means infinite life time. The default value
// defined in this class is 10 minutes.
long connTtlMillis = retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_TTL, MAX_TTL_CONN_MS);
poolableConnectionFactory.setMaxConnLifetimeMillis(connTtlMillis);
if (LOG.isInfoEnabled()) {
LOG.info("Setting Time-To-Live interval for live connections ({}) msecs", connTtlMillis);
}
// set the validation query for our jdbc connector
final String validationQuery = System.getProperty(ATHENZ_PROP_DBPOOL_VALIDATION_QUERY, MYSQL_VALIDATION_QUERY);
poolableConnectionFactory.setValidationQuery(validationQuery);
ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, config);
poolableConnectionFactory.setPool(connectionPool);
return new AthenzDataSource(connectionPool);
}
use of org.apache.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 org.apache.commons.pool2.impl.GenericObjectPool in project atmosphere by Atmosphere.
the class PoolableBroadcasterFactoryTest method testImplementation.
@Test
public void testImplementation() {
assertNotNull(factory.poolableProvider());
assertNotNull(factory.poolableProvider().implementation());
assertEquals(factory.poolableProvider().implementation().getClass(), GenericObjectPool.class);
GenericObjectPool nativePool = (GenericObjectPool) factory.poolableProvider().implementation();
assertTrue(nativePool.getLifo());
GenericObjectPoolConfig c = new GenericObjectPoolConfig();
c.setMaxTotal(1);
nativePool.setConfig(c);
assertEquals(1, nativePool.getMaxTotal());
}
use of org.apache.commons.pool2.impl.GenericObjectPool in project x-pipe by ctripcorp.
the class XpipeNettyClientPool method doInitialize.
@Override
protected void doInitialize() throws Exception {
this.factory = new NettyClientFactory(target);
this.factory.start();
GenericObjectPool<NettyClient> genericObjectPool = new GenericObjectPool<>(factory, config);
genericObjectPool.setTestOnBorrow(true);
genericObjectPool.setTestOnCreate(true);
this.objectPool = genericObjectPool;
}
Aggregations