List of usage examples for org.apache.commons.pool2.impl GenericObjectPoolConfig setMaxWaitMillis
public void setMaxWaitMillis(long maxWaitMillis)
From source file:org.springframework.data.redis.connection.jredis.JRedisConnectionIntegrationTests.java
@Test public void testConnectionNotReturnedOnException() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(1);//from w w w . j ava2s .c o m config.setMaxWaitMillis(1); 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);/*from w w w . j a va 2 s . c o m*/ poolConfig.setMaxWaitMillis(1); 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);// w w w . j a va 2 s . c om poolConfig.setMaxWaitMillis(1); 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);/*from w w w .j a v a 2s . c om*/ poolConfig.setMaxWaitMillis(1); 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);/*w w w .j av a 2 s . co m*/ poolConfig.setMaxWaitMillis(1); 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);/* w w w .ja v a2 s .c o m*/ poolConfig.setMaxWaitMillis(1); 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);/*from w w w .j a v a2 s . co m*/ poolConfig.setMaxWaitMillis(1); 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 . java2 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); }
From source file:vn.ethicconsultant.commons.memcachedpool2.Test.Test.java
public static void main(String[] args) throws Exception { String host = "192.168.10.225"; int port = 11211; MemcachedPool memcachedPool = new MemcachedPool(); MemcachedPoolableFactory memcachedPoolableFactory = new MemcachedPoolableFactory(host, port); GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxWaitMillis(500); poolConfig.setMaxTotal(10);/*from w ww . ja v a2 s .co m*/ poolConfig.setMaxIdle(10); //poolConfig.setTestOnBorrow(true); //poolConfig.setTestOnCreate(true); memcachedPool.initPool(poolConfig, memcachedPoolableFactory); MemcachedClient mc = memcachedPool.getResource(); mc.set("hung1334", 3600, "heo"); mc.set("hung1335", 3600, "heo"); mc.set("hung1336", 3600, "heo"); memcachedPool.returnResource(mc); mc = memcachedPool.getResource(); System.out.println(mc.get("hung1334")); memcachedPool.returnResource(mc); mc = memcachedPool.getResource(); System.out.println(mc.get("hung1335")); memcachedPool.returnResource(mc); mc = memcachedPool.getResource(); System.out.println(mc.get("hung1336")); memcachedPool.returnResource(mc); }
From source file:za.co.wilderness.WildernessPoolingDriver.java
private void setupDriver() throws Exception { String jdbcDriverName = "com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource"; try {//from ww w. ja v a 2 s . co m java.lang.Class.forName(jdbcDriverName).newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { //System.out.println("Error when attempting to obtain DB Driver: " + jdbcDriverName + " on "+ new Date().toString() + e.getMessage()); logger.log(Level.SEVERE, "Error when attempting to obtain DB Driver: " + jdbcDriverName + " on " + new Date().toString(), e); throw new Exception(e); } ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(this.connectURI, this.properties); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); GenericObjectPoolConfig genConfig = new GenericObjectPoolConfig(); genConfig.setMaxIdle(this.config.getMaxIdle()); genConfig.setMaxTotal(this.config.getMaxActive()); genConfig.setMinIdle(this.config.getMinIdle()); genConfig.setMaxWaitMillis(this.config.getMaxWaitMillis()); genConfig.setTimeBetweenEvictionRunsMillis(5000); genConfig.setTestWhileIdle(true); ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, genConfig); // Set the factory's pool property to the owning pool poolableConnectionFactory.setPool(connectionPool); // // Finally, we create the PoolingDriver itself... // Class.forName("org.apache.commons.dbcp2.PoolingDriver"); PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:"); //System.out.println("Driver : " + driver.toString()); logger.log(Level.FINE, "Driver : " + driver.toString()); // // ...and register our pool with it. // driver.registerPool(EXTERNAL_SERVICE.name(), connectionPool); // // Now we can just use the connect string "jdbc:apache:commons:dbcp:example" // to access our pool of Connections. // }