Search in sources :

Example 6 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 7 with GenericObjectPool

use of org.apache.commons.pool2.impl.GenericObjectPool in project cloudstack by apache.

the class TransactionLegacy method createDataSource.

/**
 * Creates a data source
 */
private static DataSource createDataSource(String uri, String username, String password, Integer maxActive, Integer maxIdle, Long maxWait, Long timeBtwnEvictionRuns, Long minEvictableIdleTime, Boolean testWhileIdle, Boolean testOnBorrow, String validationQuery, Integer isolationLevel) {
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(uri, username, password);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    GenericObjectPoolConfig config = createPoolConfig(maxActive, maxIdle, maxWait, timeBtwnEvictionRuns, minEvictableIdleTime, testWhileIdle, testOnBorrow);
    ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, config);
    poolableConnectionFactory.setPool(connectionPool);
    if (validationQuery != null) {
        poolableConnectionFactory.setValidationQuery(validationQuery);
    }
    if (isolationLevel != null) {
        poolableConnectionFactory.setDefaultTransactionIsolation(isolationLevel);
    }
    return new PoolingDataSource<>(connectionPool);
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) PoolingDataSource(org.apache.commons.dbcp2.PoolingDataSource) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) 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 8 with GenericObjectPool

use of org.apache.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);
}
Also used : lombok.val(lombok.val) MemcachedPooledClientConnectionFactory(org.apereo.cas.memcached.MemcachedPooledClientConnectionFactory) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 9 with GenericObjectPool

use of org.apache.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;
}
Also used : lombok.val(lombok.val) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool)

Example 10 with GenericObjectPool

use of org.apache.commons.pool2.impl.GenericObjectPool in project spring-framework by spring-projects.

the class CommonsPool2TargetSource method createObjectPool.

/**
 * Subclasses can override this if they want to return a specific Commons pool.
 * They should apply any configuration properties to the pool here.
 * <p>Default is a GenericObjectPool instance with the given pool size.
 * @return an empty Commons {@code ObjectPool}.
 * @see GenericObjectPool
 * @see #setMaxSize
 */
protected ObjectPool createObjectPool() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(getMaxSize());
    config.setMaxIdle(getMaxIdle());
    config.setMinIdle(getMinIdle());
    config.setMaxWaitMillis(getMaxWait());
    config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
    config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
    config.setBlockWhenExhausted(isBlockWhenExhausted());
    return new GenericObjectPool(this, config);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) 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