use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project bboss by bbossgroups.
the class BasicDataSource method createConnectionPool.
/**
* Creates a connection pool for this datasource. This method only exists
* so subclasses can replace the implementation class.
*
* This implementation configures all pool properties other than
* timeBetweenEvictionRunsMillis. Setting that property is deferred to
* {@link #startPoolMaintenance()}, since setting timeBetweenEvictionRunsMillis
* to a positive value causes {@link GenericObjectPool}'s eviction timer
* to be started.
*/
protected void createConnectionPool(PoolableConnectionFactory factory) {
// Create an object pool to contain our active connections
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
updateJmxName(config);
// Disable JMX on the underlying pool if the DS is not registered.
config.setJmxEnabled(registeredJmxName != null);
GenericObjectPool<PoolableConnection> gop;
if (abandonedConfig != null && (abandonedConfig.getRemoveAbandonedOnBorrow() || abandonedConfig.getRemoveAbandonedOnMaintenance() || abandonedConfig.getLogAbandoned())) {
// 改造实现跟踪功能 biaoping.yin
gop = new GenericObjectPool<PoolableConnection>(factory, config, abandonedConfig);
} else {
gop = new GenericObjectPool<PoolableConnection>(factory, config);
}
gop.setMaxTotal(maxTotal);
gop.setMaxIdle(maxIdle);
gop.setMinIdle(minIdle);
gop.setMaxWaitMillis(maxWaitMillis);
gop.setTestOnCreate(testOnCreate);
gop.setTestOnBorrow(testOnBorrow);
gop.setTestOnReturn(testOnReturn);
gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
gop.setTestWhileIdle(testWhileIdle);
gop.setLifo(lifo);
gop.setSwallowedExceptionListener(new SwallowedExceptionLogger(log, logExpiredConnections));
gop.setEvictionPolicyClassName(evictionPolicyClassName);
factory.setPool(gop);
connectionPool = gop;
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project lettuce-core by lettuce-io.
the class AsyncConnectionPoolSupportIntegrationTests method asyncPoolShouldCloseConnectionsAboveMaxIdleSize.
@Test
void asyncPoolShouldCloseConnectionsAboveMaxIdleSize() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxIdle(2);
BoundedAsyncPool<StatefulRedisConnection<String, String>> pool = AsyncConnectionPoolSupport.createBoundedObjectPool(() -> client.connectAsync(StringCodec.ASCII, uri), CommonsPool2ConfigConverter.bounded(poolConfig));
borrowAndReturn(pool);
borrowAndClose(pool);
StatefulRedisConnection<String, String> c1 = TestFutures.getOrTimeout(pool.acquire());
StatefulRedisConnection<String, String> c2 = TestFutures.getOrTimeout(pool.acquire());
StatefulRedisConnection<String, String> c3 = TestFutures.getOrTimeout(pool.acquire());
assertThat(channels).hasSize(3);
CompletableFuture.allOf(pool.release(c1), pool.release(c2), pool.release(c3)).join();
assertThat(channels).hasSize(2);
pool.close();
assertThat(channels).isEmpty();
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project lettuce-core by lettuce-io.
the class GenericConnectionPoolBenchmark method setup.
@Setup
public void setup() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMinIdle(0);
config.setMaxIdle(20);
config.setMaxTotal(20);
pool = ConnectionPoolSupport.createGenericObjectPool(() -> new EmptyStatefulRedisConnection(EmptyRedisChannelWriter.INSTANCE), config);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project spring-data-redis by spring-projects.
the class DefaultLettucePoolTests method testReturnResource.
@Test
void testReturnResource() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
poolConfig.setMaxWaitMillis(1);
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
assertThat(client).isNotNull();
pool.returnResource(client);
assertThat(pool.getResource()).isNotNull();
client.close();
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project spring-data-redis by spring-projects.
the class DefaultLettucePoolTests method testReturnBrokenResource.
@Test
void testReturnBrokenResource() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
poolConfig.setMaxWaitMillis(1);
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
assertThat(client).isNotNull();
pool.returnBrokenResource(client);
StatefulRedisConnection<byte[], byte[]> client2 = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
assertThat(client2).isNotSameAs(client);
try {
client.sync().ping();
fail("Broken resouce connection should be closed");
} catch (RedisException e) {
} finally {
client.close();
client2.close();
}
}
Aggregations