List of usage examples for org.apache.commons.pool2.impl GenericObjectPoolConfig setMaxTotal
public void setMaxTotal(int maxTotal)
From source file:org.power.commons.redis.RedisClient.java
private GenericObjectPoolConfig getPoolConfig() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); // maxIdle?pool size???????redis poolConfig.setMaxTotal(this.maxTotal); if (this.maxIdle > 0) { poolConfig.setMaxIdle(this.maxIdle); }/* w w w . jav a 2 s . co m*/ poolConfig.setMaxWaitMillis(this.maxWait); /* if (this.whenExhaustedAction >= 0 && this.whenExhaustedAction < 3) { poolConfig.whenExhaustedAction = this.whenExhaustedAction; }*/ poolConfig.setBlockWhenExhausted(this.blockWhenExhausted); poolConfig.setTestOnBorrow(this.testOnBorrow); poolConfig.setMinIdle(this.minIdle); poolConfig.setTestOnReturn(testOnReturn); poolConfig.setTestWhileIdle(testWhileIdle); poolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); poolConfig.setNumTestsPerEvictionRun(numTestsPerEvictionRun); poolConfig.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); poolConfig.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis); poolConfig.setLifo(lifo); return poolConfig; }
From source file:org.springframework.aop.target.CommonsPool2TargetSource.java
/** * 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//from w w w.j av a 2 s . c om * @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); }
From source file:org.springframework.data.redis.connection.jredis.JRedisConnectionIntegrationTests.java
@Test public void testConnectionNotReturnedOnException() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(1); config.setMaxWaitMillis(1);/* www. j av a 2 s. co m*/ JredisConnectionFactory factory2 = new JredisConnectionFactory( new JredisPool(SettingsUtils.getHost(), SettingsUtils.getPort(), config)); RedisConnection conn2 = factory2.getConnection(); ((JRedis) conn2.getNativeConnection()).quit(); try { conn2.ping(); fail("Expected RedisConnectionFailureException trying to use a closed connection"); } catch (RedisConnectionFailureException e) { } conn2.close(); // Verify we get a new connection from the pool and not the broken one RedisConnection conn3 = factory2.getConnection(); conn3.ping(); }
From source file:org.springframework.data.redis.connection.jredis.JredisPoolTests.java
@Test public void testGetResourcePoolExhausted() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(1); poolConfig.setMaxWaitMillis(1);//from ww w.j a va 2 s. c om this.pool = new JredisPool(connectionSpec, poolConfig); JRedis client = pool.getResource(); assertNotNull(client); try { pool.getResource(); fail("PoolException should be thrown when pool exhausted"); } catch (PoolException e) { } }
From source file:org.springframework.data.redis.connection.jredis.JredisPoolTests.java
@Test public void testReturnResource() throws RedisException { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(1); poolConfig.setMaxWaitMillis(1);/*from w w w .ja v a 2 s .c om*/ this.pool = new JredisPool(connectionSpec); JRedis client = pool.getResource(); assertNotNull(client); pool.returnResource(client); assertNotNull(pool.getResource()); }
From source file:org.springframework.data.redis.connection.jredis.JredisPoolTests.java
@Test public void testReturnBrokenResource() throws RedisException { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(1); poolConfig.setMaxWaitMillis(1);//from w w w . ja v a 2s . com this.pool = new JredisPool(connectionSpec, poolConfig); JRedis client = pool.getResource(); assertNotNull(client); pool.returnBrokenResource(client); JRedis client2 = pool.getResource(); assertNotSame(client, client2); try { client.ping(); fail("Broken resouce connection should be closed"); } catch (NotConnectedException e) { } }
From source file:org.springframework.data.redis.connection.lettuce.DefaultLettucePoolTests.java
@Test public void testGetResourcePoolExhausted() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(1); poolConfig.setMaxWaitMillis(1);//from ww w. j av a 2 s. c om pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig); pool.setClientResources(LettuceTestClientResources.getSharedClientResources()); pool.afterPropertiesSet(); RedisAsyncConnection<byte[], byte[]> client = pool.getResource(); assertNotNull(client); try { pool.getResource(); fail("PoolException should be thrown when pool exhausted"); } catch (PoolException e) { } finally { client.close(); } }
From source file:org.springframework.data.redis.connection.lettuce.DefaultLettucePoolTests.java
@Test public void testReturnResource() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(1); poolConfig.setMaxWaitMillis(1);//from w w w .j a v a 2 s . com pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig); pool.setClientResources(LettuceTestClientResources.getSharedClientResources()); pool.afterPropertiesSet(); RedisAsyncConnection<byte[], byte[]> client = pool.getResource(); assertNotNull(client); pool.returnResource(client); assertNotNull(pool.getResource()); client.close(); }
From source file:org.springframework.data.redis.connection.lettuce.DefaultLettucePoolTests.java
@Test public void testReturnBrokenResource() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(1); poolConfig.setMaxWaitMillis(1);//from www . j a va 2s . co m pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig); pool.setClientResources(LettuceTestClientResources.getSharedClientResources()); pool.afterPropertiesSet(); RedisAsyncConnection<byte[], byte[]> client = pool.getResource(); assertNotNull(client); pool.returnBrokenResource(client); RedisAsyncConnection<byte[], byte[]> client2 = pool.getResource(); assertNotSame(client, client2); try { client.ping(); fail("Broken resouce connection should be closed"); } catch (RedisException e) { } finally { client.close(); client2.close(); } }
From source file:org.wso2.carbon.transport.jms.factory.JMSClientConnectionFactory.java
/** * Initialize the session pool with provided configuration. *///from w w w. j a v a2 s.c o m private void initSessionPool() { SessionPoolFactory sessionPoolFactory = new SessionPoolFactory(this); //create pool configurations GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(maxNumberOfConnections * maxSessionsPerConnection); //todo: set the ideal limit and make the idle sessions timedout config.setMaxIdle(maxNumberOfConnections * maxSessionsPerConnection); config.setBlockWhenExhausted(true); config.setMaxWaitMillis(poolWaitTimeout); //initialize the pool sessionPool = new GenericObjectPool<SessionWrapper>(sessionPoolFactory, config); }