Search in sources :

Example 26 with GenericObjectPool

use of com.frameworkset.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)

Example 27 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project lcache by long172066912.

the class LettuceConnectionFactory method getLettuceClusterPoolConnection.

/**
 * 获取Lettuce集群连接池
 *
 * @param lettuceClusterConnectSourceConfig
 * @return
 */
public GenericObjectPool getLettuceClusterPoolConnection(LettuceClusterConnectSourceConfig lettuceClusterConnectSourceConfig) {
    // 设置线程
    DefaultClientResources res = this.getDefaultClientResources(lettuceClusterConnectSourceConfig.getHosts().toString(), 0, lettuceClusterConnectSourceConfig.getCommonCacheConfig().getIoThreadPoolSize(), lettuceClusterConnectSourceConfig.getCommonCacheConfig().getComputationThreadPoolSize());
    List<RedisURI> nodeConfigs = new ArrayList<>(lettuceClusterConnectSourceConfig.getNodes().size());
    for (LettuceConnectSourceConfig redisSourceConfig : lettuceClusterConnectSourceConfig.getNodes()) {
        nodeConfigs.add(this.getRedisUri(redisSourceConfig.getHost(), redisSourceConfig.getPort(), redisSourceConfig.getPwd(), redisSourceConfig.getDatabase(), redisSourceConfig.getTimeout()));
    }
    RedisClusterClient client = RedisClusterClient.create(res, nodeConfigs);
    client.setDefaultTimeout(Duration.ofMillis(lettuceClusterConnectSourceConfig.getSoTimeout()));
    client.setOptions(CacheConfigBuildUtils.getClusterClientOptions(lettuceClusterConnectSourceConfig));
    return (GenericObjectPool) this.execute(() -> {
        return ConnectionPoolSupport.createGenericObjectPool(() -> client.connect(), CacheConfigBuildUtils.getJedisPoolConfig(lettuceClusterConnectSourceConfig.getCommonCacheConfig()));
    });
}
Also used : RedisURI(io.lettuce.core.RedisURI) ArrayList(java.util.ArrayList) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) RedisClusterClient(io.lettuce.core.cluster.RedisClusterClient) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) DefaultClientResources(io.lettuce.core.resource.DefaultClientResources)

Example 28 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project lcache by long172066912.

the class LettuceConnectionFactory method getLettuceConnectionByPool.

/**
 * 获取Lettuce连接池
 *
 * @param redisSourceConfig
 * @return
 */
public GenericObjectPool getLettuceConnectionByPool(LettuceConnectSourceConfig redisSourceConfig) {
    // 设置线程
    DefaultClientResources res = this.getDefaultClientResources(redisSourceConfig.getHost(), redisSourceConfig.getPort(), redisSourceConfig.getCommonCacheConfig().getIoThreadPoolSize(), redisSourceConfig.getCommonCacheConfig().getComputationThreadPoolSize());
    RedisClient client = RedisClient.create(res, this.getRedisUri(redisSourceConfig.getHost(), redisSourceConfig.getPort(), redisSourceConfig.getPwd(), redisSourceConfig.getDatabase(), redisSourceConfig.getTimeout()));
    client.setOptions(CacheConfigBuildUtils.getClientOptions(redisSourceConfig));
    client.setDefaultTimeout(Duration.ofMillis(redisSourceConfig.getSoTimeout()));
    return (GenericObjectPool) this.execute(() -> {
        return ConnectionPoolSupport.createGenericObjectPool(() -> client.connect(), CacheConfigBuildUtils.getJedisPoolConfig(redisSourceConfig.getCommonCacheConfig()));
    });
}
Also used : RedisClient(io.lettuce.core.RedisClient) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) DefaultClientResources(io.lettuce.core.resource.DefaultClientResources)

Example 29 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project hive by apache.

the class DbCPDataSourceProvider method create.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public DataSource create(Configuration hdpConfig, int maxPoolSize) throws SQLException {
    LOG.debug("Creating dbcp connection pool for the MetaStore");
    String driverUrl = DataSourceProvider.getMetastoreJdbcDriverUrl(hdpConfig);
    String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig);
    String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig);
    BasicDataSource dbcpDs = new BasicDataSource();
    dbcpDs.setUrl(driverUrl);
    dbcpDs.setUsername(user);
    dbcpDs.setPassword(passwd);
    dbcpDs.setDefaultReadOnly(false);
    dbcpDs.setDefaultAutoCommit(true);
    DatabaseProduct dbProduct = DatabaseProduct.determineDatabaseProduct(driverUrl, hdpConfig);
    Map<String, String> props = dbProduct.getDataSourceProperties();
    for (Map.Entry<String, String> kv : props.entrySet()) {
        dbcpDs.setConnectionProperties(kv.getKey() + "=" + kv.getValue());
    }
    long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L);
    int connectionMaxIlde = hdpConfig.getInt(CONNECTION_MAX_IDLE_PROPERTY, 8);
    int connectionMinIlde = hdpConfig.getInt(CONNECTION_MIN_IDLE_PROPERTY, 0);
    boolean testOnBorrow = hdpConfig.getBoolean(CONNECTION_TEST_BORROW_PROPERTY, BaseObjectPoolConfig.DEFAULT_TEST_ON_BORROW);
    long evictionTimeMillis = hdpConfig.getLong(CONNECTION_MIN_EVICT_MILLIS_PROPERTY, BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    boolean testWhileIdle = hdpConfig.getBoolean(CONNECTION_TEST_IDLEPROPERTY, BaseObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE);
    long timeBetweenEvictionRuns = hdpConfig.getLong(CONNECTION_TIME_BETWEEN_EVICTION_RUNS_MILLIS, BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
    int numTestsPerEvictionRun = hdpConfig.getInt(CONNECTION_NUM_TESTS_PER_EVICTION_RUN, BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN);
    boolean testOnReturn = hdpConfig.getBoolean(CONNECTION_TEST_ON_RETURN, BaseObjectPoolConfig.DEFAULT_TEST_ON_RETURN);
    long softMinEvictableIdleTimeMillis = hdpConfig.getLong(CONNECTION_SOFT_MIN_EVICTABLE_IDLE_TIME, BaseObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    boolean lifo = hdpConfig.getBoolean(CONNECTION_LIFO, BaseObjectPoolConfig.DEFAULT_LIFO);
    ConnectionFactory connFactory = new DataSourceConnectionFactory(dbcpDs);
    PoolableConnectionFactory poolableConnFactory = new PoolableConnectionFactory(connFactory, null);
    GenericObjectPool objectPool = new GenericObjectPool(poolableConnFactory);
    objectPool.setMaxTotal(maxPoolSize);
    objectPool.setMaxWaitMillis(connectionTimeout);
    objectPool.setMaxIdle(connectionMaxIlde);
    objectPool.setMinIdle(connectionMinIlde);
    objectPool.setTestOnBorrow(testOnBorrow);
    objectPool.setTestWhileIdle(testWhileIdle);
    objectPool.setMinEvictableIdleTimeMillis(evictionTimeMillis);
    objectPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns);
    objectPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    objectPool.setTestOnReturn(testOnReturn);
    objectPool.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
    objectPool.setLifo(lifo);
    String stmt = dbProduct.getPrepareTxnStmt();
    if (stmt != null) {
        poolableConnFactory.setValidationQuery(stmt);
    }
    return new PoolingDataSource(objectPool);
}
Also used : PoolingDataSource(org.apache.commons.dbcp2.PoolingDataSource) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) DatabaseProduct(org.apache.hadoop.hive.metastore.DatabaseProduct) ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) DataSourceConnectionFactory(org.apache.commons.dbcp2.DataSourceConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) DataSourceConnectionFactory(org.apache.commons.dbcp2.DataSourceConnectionFactory) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) Map(java.util.Map) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 30 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project cas by apereo.

the class MemcachedMonitorConfiguration method memcachedHealthIndicator.

@Bean
public HealthIndicator memcachedHealthIndicator() {
    final MonitorProperties.Memcached memcached = casProperties.getMonitor().getMemcached();
    final MemcachedPooledClientConnectionFactory factory = new MemcachedPooledClientConnectionFactory(memcached, memcachedMonitorTranscoder());
    final ObjectPool<MemcachedClientIF> pool = new GenericObjectPool<>(factory);
    return new MemcachedHealthIndicator(pool, casProperties);
}
Also used : MemcachedPooledClientConnectionFactory(org.apereo.cas.memcached.MemcachedPooledClientConnectionFactory) MemcachedClientIF(net.spy.memcached.MemcachedClientIF) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) MemcachedHealthIndicator(org.apereo.cas.monitor.MemcachedHealthIndicator) MonitorProperties(org.apereo.cas.configuration.model.core.monitor.MonitorProperties) Bean(org.springframework.context.annotation.Bean)

Aggregations

GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)79 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)32 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)27 PoolableConnection (org.apache.commons.dbcp2.PoolableConnection)23 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)19 DriverManagerConnectionFactory (org.apache.commons.dbcp2.DriverManagerConnectionFactory)16 Test (org.junit.jupiter.api.Test)13 Properties (java.util.Properties)11 PoolingDataSource (org.apache.commons.dbcp2.PoolingDataSource)9 SQLException (java.sql.SQLException)8 PoolingDriver (org.apache.commons.dbcp2.PoolingDriver)8 Connection (java.sql.Connection)7 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)5 Bean (org.springframework.context.annotation.Bean)5 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)4 IOException (java.io.IOException)3 PooledObject (org.apache.commons.pool2.PooledObject)3 Test (org.junit.Test)3 TimeInterval (com.adaptris.util.TimeInterval)2 ThresholdedRandomCutForestMapper (com.amazon.randomcutforest.parkservices.state.ThresholdedRandomCutForestMapper)2