Search in sources :

Example 1 with GenericObjectPool

use of org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool in project tomcat by apache.

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.
     * @param factory The connection factory
     */
protected void createConnectionPool(final PoolableConnectionFactory factory) {
    // Create an object pool to contain our active connections
    final 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())) {
        gop = new GenericObjectPool<>(factory, config, abandonedConfig);
    } else {
        gop = new GenericObjectPool<>(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.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
    gop.setTestWhileIdle(testWhileIdle);
    gop.setLifo(lifo);
    gop.setSwallowedExceptionListener(new SwallowedExceptionLogger(log, logExpiredConnections));
    gop.setEvictionPolicyClassName(evictionPolicyClassName);
    factory.setPool(gop);
    connectionPool = gop;
}
Also used : GenericObjectPoolConfig(org.apache.tomcat.dbcp.pool2.impl.GenericObjectPoolConfig)

Example 2 with GenericObjectPool

use of org.apache.tomcat.dbcp.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 3 with GenericObjectPool

use of org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool in project zeppelin by apache.

the class JDBCInterpreter method createConnectionPool.

private void createConnectionPool(String url, String user, String propertyKey, Properties properties) throws SQLException, ClassNotFoundException {
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, properties);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    ObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
    poolableConnectionFactory.setPool(connectionPool);
    Class.forName(properties.getProperty(DRIVER_KEY));
    PoolingDriver driver = new PoolingDriver();
    driver.registerPool(propertyKey + user, connectionPool);
    getJDBCConfiguration(user).saveDBDriverPool(propertyKey, driver);
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolingDriver(org.apache.commons.dbcp2.PoolingDriver) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) ObjectPool(org.apache.commons.pool2.ObjectPool) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 4 with GenericObjectPool

use of org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool in project tomcat by apache.

the class PerUserPoolDataSource method registerPool.

private synchronized void registerPool(final String username, final String password) throws NamingException, SQLException {
    final ConnectionPoolDataSource cpds = testCPDS(username, password);
    // Set up the factory we will use (passing the pool associates
    // the factory with the pool, so we do not have to do so
    // explicitly)
    final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, getValidationQuery(), getValidationQueryTimeout(), isRollbackAfterValidation(), username, password);
    factory.setMaxConnLifetimeMillis(getMaxConnLifetimeMillis());
    // Create an object pool to contain our PooledConnections
    final GenericObjectPool<PooledConnectionAndInfo> pool = new GenericObjectPool<>(factory);
    factory.setPool(pool);
    pool.setBlockWhenExhausted(getPerUserBlockWhenExhausted(username));
    pool.setEvictionPolicyClassName(getPerUserEvictionPolicyClassName(username));
    pool.setLifo(getPerUserLifo(username));
    pool.setMaxIdle(getPerUserMaxIdle(username));
    pool.setMaxTotal(getPerUserMaxTotal(username));
    pool.setMaxWaitMillis(getPerUserMaxWaitMillis(username));
    pool.setMinEvictableIdleTimeMillis(getPerUserMinEvictableIdleTimeMillis(username));
    pool.setMinIdle(getPerUserMinIdle(username));
    pool.setNumTestsPerEvictionRun(getPerUserNumTestsPerEvictionRun(username));
    pool.setSoftMinEvictableIdleTimeMillis(getPerUserSoftMinEvictableIdleTimeMillis(username));
    pool.setTestOnCreate(getPerUserTestOnCreate(username));
    pool.setTestOnBorrow(getPerUserTestOnBorrow(username));
    pool.setTestOnReturn(getPerUserTestOnReturn(username));
    pool.setTestWhileIdle(getPerUserTestWhileIdle(username));
    pool.setTimeBetweenEvictionRunsMillis(getPerUserTimeBetweenEvictionRunsMillis(username));
    pool.setSwallowedExceptionListener(new SwallowedExceptionLogger(log));
    final Object old = managers.put(getPoolKey(username), factory);
    if (old != null) {
        throw new IllegalStateException("Pool already contains an entry for this user/password: " + username);
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) SwallowedExceptionLogger(org.apache.tomcat.dbcp.dbcp2.SwallowedExceptionLogger) GenericObjectPool(org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool)

Example 5 with GenericObjectPool

use of org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool in project atmosphere by Atmosphere.

the class PoolableBroadcasterFactoryTest method testImplementation.

@Test
public void testImplementation() {
    assertNotNull(factory.poolableProvider());
    assertNotNull(factory.poolableProvider().implementation());
    assertEquals(factory.poolableProvider().implementation().getClass(), GenericObjectPool.class);
    GenericObjectPool nativePool = (GenericObjectPool) factory.poolableProvider().implementation();
    assertTrue(nativePool.getLifo());
    GenericObjectPoolConfig c = new GenericObjectPoolConfig();
    c.setMaxTotal(1);
    nativePool.setConfig(c);
    assertEquals(1, nativePool.getMaxTotal());
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) Test(org.testng.annotations.Test)

Aggregations

GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)3 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)2 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)1 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)1 DriverManagerConnectionFactory (org.apache.commons.dbcp2.DriverManagerConnectionFactory)1 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)1 PoolingDriver (org.apache.commons.dbcp2.PoolingDriver)1 ObjectPool (org.apache.commons.pool2.ObjectPool)1 SwallowedExceptionLogger (org.apache.tomcat.dbcp.dbcp2.SwallowedExceptionLogger)1 GenericObjectPool (org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool)1 GenericObjectPoolConfig (org.apache.tomcat.dbcp.pool2.impl.GenericObjectPoolConfig)1 Test (org.testng.annotations.Test)1