use of org.apache.commons.pool.ObjectPool in project hive by apache.
the class TxnHandler method setupJdbcConnectionPool.
private static synchronized void setupJdbcConnectionPool(HiveConf conf) throws SQLException {
if (connPool != null)
return;
String driverUrl = HiveConf.getVar(conf, HiveConf.ConfVars.METASTORECONNECTURLKEY);
String user = getMetastoreJdbcUser(conf);
String passwd = getMetastoreJdbcPasswd(conf);
String connectionPooler = conf.getVar(HiveConf.ConfVars.METASTORE_CONNECTION_POOLING_TYPE).toLowerCase();
if ("bonecp".equals(connectionPooler)) {
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(driverUrl);
//if we are waiting for connection for 60s, something is really wrong
//better raise an error than hang forever
config.setConnectionTimeoutInMs(60000);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
config.setUser(user);
config.setPassword(passwd);
connPool = new BoneCPDataSource(config);
// Enable retries to work around BONECP bug.
doRetryOnConnPool = true;
} else if ("dbcp".equals(connectionPooler)) {
ObjectPool objectPool = new GenericObjectPool();
ConnectionFactory connFactory = new DriverManagerConnectionFactory(driverUrl, user, passwd);
// This doesn't get used, but it's still necessary, see
// http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/doc/ManualPoolingDataSourceExample.java?view=markup
PoolableConnectionFactory poolConnFactory = new PoolableConnectionFactory(connFactory, objectPool, null, null, false, true);
connPool = new PoolingDataSource(objectPool);
} else if ("hikaricp".equals(connectionPooler)) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(driverUrl);
config.setUsername(user);
config.setPassword(passwd);
connPool = new HikariDataSource(config);
} else if ("none".equals(connectionPooler)) {
LOG.info("Choosing not to pool JDBC connections");
connPool = new NoPoolConnectionPool(conf);
} else {
throw new RuntimeException("Unknown JDBC connection pooling " + connectionPooler);
}
}
use of org.apache.commons.pool.ObjectPool in project mondrian by pentaho.
the class RolapConnectionPool method getPool.
/**
* Gets or creates a connection pool for a particular connect
* specification.
*/
private synchronized ObjectPool getPool(Object key, ConnectionFactory connectionFactory) {
ObjectPool connectionPool = mapConnectKeyToPool.get(key);
if (connectionPool == null) {
// use GenericObjectPool, which provides for resource limits
connectionPool = new GenericObjectPool(// PoolableObjectFactory, can be null
null, // max active
50, // action when exhausted
GenericObjectPool.WHEN_EXHAUSTED_BLOCK, // max wait (milli seconds)
3000, // max idle
10, // test on borrow
false, // test on return
false, // time between eviction runs (millis)
60000, // number to test on eviction run
5, // min evictable idle time (millis)
30000, // test while idle
true);
// create a PoolableConnectionFactory
AbandonedConfig abandonedConfig = new AbandonedConfig();
// flag to remove abandoned connections from pool
abandonedConfig.setRemoveAbandoned(true);
// timeout (seconds) before removing abandoned connections
abandonedConfig.setRemoveAbandonedTimeout(300);
// Flag to log stack traces for application code which abandoned a
// Statement or Connection
abandonedConfig.setLogAbandoned(true);
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(// the connection factory
connectionFactory, // the object pool
connectionPool, // or null for no pooling
null, // null
null, // default "read only" setting for borrowed connections
false, // default "auto commit" setting for returned connections
true, // connections
abandonedConfig);
// "poolableConnectionFactory" has registered itself with
// "connectionPool", somehow, so we don't need the value any more.
Util.discard(poolableConnectionFactory);
mapConnectKeyToPool.put(key, connectionPool);
}
return connectionPool;
}
use of org.apache.commons.pool.ObjectPool in project pentaho-platform by pentaho.
the class PooledDatasourceSystemListener method shutdown.
@SuppressWarnings("unchecked")
public void shutdown() {
ICacheManager cacheManager = PentahoSystem.getCacheManager(null);
List<ObjectPool> objectPools = null;
objectPools = (List<ObjectPool>) cacheManager.getAllValuesFromRegionCache(IDBDatasourceService.JDBC_POOL);
// $NON-NLS-1$
Logger.debug(this, "DatasourceSystemListener: Called for shutdown ...");
try {
if (objectPools != null) {
for (ObjectPool objectPool : objectPools) {
if (null != objectPool) {
objectPool.clear();
}
}
}
} catch (Throwable ignored) {
// $NON-NLS-1$
Logger.error(this, "Failed to clear connection pool: " + ignored.getMessage(), ignored);
}
cacheManager.removeRegionCache(IDBDatasourceService.JDBC_POOL);
cacheManager.removeRegionCache(IDBDatasourceService.JDBC_DATASOURCE);
// $NON-NLS-1$
Logger.debug(this, "DatasourceSystemListener: Completed shutdown.");
}
Aggregations