use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project jetcache by alibaba.
the class RedisCacheTest method readFromSlaveTest.
@Test
public void readFromSlaveTest() throws Exception {
GenericObjectPoolConfig pc = new GenericObjectPoolConfig();
pc.setMinIdle(2);
pc.setMaxIdle(10);
pc.setMaxTotal(10);
JedisPool pool1 = new JedisPool(pc, "127.0.0.1", 6379);
JedisPool pool2 = new JedisPool(pc, "127.0.0.1", 6380);
JedisPool pool3 = new JedisPool(pc, "127.0.0.1", 6381);
RedisCacheBuilder builder = RedisCacheBuilder.createRedisCacheBuilder();
builder.setJedisPool(pool1);
builder.setReadFromSlave(true);
builder.setJedisSlavePools(pool2, pool3);
builder.setSlaveReadWeights(1, 1);
builder.setKeyConvertor(FastjsonKeyConvertor.INSTANCE);
builder.setValueEncoder(JavaValueEncoder.INSTANCE);
builder.setValueDecoder(JavaValueDecoder.INSTANCE);
builder.setKeyPrefix(new Random().nextInt() + "");
builder.setExpireAfterWriteInMillis(500);
readFromSlaveTestAsserts(pool1, builder);
builder.setSlaveReadWeights(null);
readFromSlaveTestAsserts(pool1, builder);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project jetcache by alibaba.
the class RedisCacheTest method testSimplePool.
@Test
public void testSimplePool() throws Exception {
GenericObjectPoolConfig pc = new GenericObjectPoolConfig();
pc.setMinIdle(2);
pc.setMaxIdle(10);
pc.setMaxTotal(10);
JedisPool pool = new JedisPool(pc, "127.0.0.1", 6379);
testImpl(pool);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project jetcache by alibaba.
the class RedisCacheTest method testSentinel.
@Test
public void testSentinel() throws Exception {
GenericObjectPoolConfig pc = new GenericObjectPoolConfig();
pc.setMinIdle(2);
pc.setMaxIdle(10);
pc.setMaxTotal(10);
Set<String> sentinels = new HashSet<>();
sentinels.add("127.0.0.1:26379");
sentinels.add("127.0.0.1:26380");
sentinels.add("127.0.0.1:26381");
JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels, pc);
testImpl(pool);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project java-learn by laidu.
the class PoolApp method main.
public static void main(String[] args) throws Exception {
ProxyPooledFactory factory = new ProxyPooledFactory();
GenericObjectPoolConfig<ProxyInfo> poolConfig = new GenericObjectPoolConfig<>();
poolConfig.setMaxIdle(500);
poolConfig.setMaxTotal(20);
poolConfig.setMinIdle(150);
poolConfig.setMaxWaitMillis(50);
poolConfig.setTestOnBorrow(true);
poolConfig.setTestWhileIdle(true);
poolConfig.setTestOnCreate(false);
poolConfig.setMaxWaitMillis(100);
poolConfig.setTimeBetweenEvictionRunsMillis(1000);
ObjectPool<ProxyInfo> pool = new GenericObjectPool<>(factory, poolConfig);
while (true) {
ProxyInfo proxyInfo = pool.borrowObject();
Thread.sleep(1000000);
pool.returnObject(proxyInfo);
System.out.println(pool.getNumActive());
System.out.println(pool.getNumIdle());
}
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig 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);
}
Aggregations