Search in sources :

Example 11 with GenericObjectPool

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);
        }
    }
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 12 with GenericObjectPool

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);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) PoolableConnection(org.apache.commons.dbcp2.PoolableConnection) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 13 with GenericObjectPool

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);
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Field(java.lang.reflect.Field) BeanCreationException(org.springframework.beans.factory.BeanCreationException) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) BeanCreationException(org.springframework.beans.factory.BeanCreationException)

Example 14 with GenericObjectPool

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());
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) Test(org.testng.annotations.Test)

Example 15 with GenericObjectPool

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;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) NettyClientFactory(com.ctrip.xpipe.netty.commands.NettyClientFactory) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool)

Aggregations

GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)24 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)12 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)10 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)8 DriverManagerConnectionFactory (org.apache.commons.dbcp2.DriverManagerConnectionFactory)6 PoolableConnection (org.apache.commons.dbcp2.PoolableConnection)6 PoolingDataSource (org.apache.commons.dbcp2.PoolingDataSource)4 File (java.io.File)3 SQLException (java.sql.SQLException)3 Properties (java.util.Properties)3 IOException (java.io.IOException)2 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)2 lombok.val (lombok.val)2 PoolingDriver (org.apache.commons.dbcp2.PoolingDriver)2 MemcachedPooledClientConnectionFactory (org.apereo.cas.memcached.MemcachedPooledClientConnectionFactory)2 GenericObjectPool (org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool)2 Before (org.junit.Before)2 Bean (org.springframework.context.annotation.Bean)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 NettyClientFactory (com.ctrip.xpipe.netty.commands.NettyClientFactory)1