List of usage examples for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool
public GenericObjectPool(PoolableObjectFactory factory, int maxActive)
From source file:ca.sqlpower.sqlobject.SQLDatabase.java
synchronized BaseObjectPool getConnectionPool() { if (connectionPool == null) { Config poolConfig = new GenericObjectPool.Config(); poolConfig.maxActive = 5;//from w w w . j a v a2 s. c o m poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; connectionPool = new GenericObjectPool(null, poolConfig); ConnectionFactory cf = new JDBCDSConnectionFactory(dataSource); new PoolableConnectionFactory(cf, connectionPool, null, null, false, true); } return connectionPool; }
From source file:com.cloud.utils.db.Transaction.java
private static DataSource getDefaultDataSource(final String database) { final GenericObjectPool connectionPool = new GenericObjectPool(null, 5); final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( "jdbc:mysql://localhost:3306/" + database, "cloud", "cloud"); final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); return new PoolingDataSource(/* connectionPool */poolableConnectionFactory.getPool()); }
From source file:com.cloud.utils.db.TransactionLegacy.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static DataSource getDefaultDataSource(final String database) { final GenericObjectPool connectionPool = new GenericObjectPool(null, 5); final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( "jdbc:mysql://localhost:3306/" + database, "cloud", "cloud"); final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); return new PoolingDataSource(/* connectionPool */poolableConnectionFactory.getPool()); }
From source file:org.apache.airavata.api.server.util.ThriftClientPool.java
public ThriftClientPool(ClientFactory<T> clientFactory, ProtocolFactory protocolFactory, GenericObjectPool.Config poolConfig) { this.internalPool = new GenericObjectPool(new ThriftClientFactory(clientFactory, protocolFactory), poolConfig);/*from w w w. j a v a 2 s . co m*/ }
From source file:org.apache.camel.component.netty.NettyProducer.java
@Override protected void doStart() throws Exception { super.doStart(); if (configuration.isProducerPoolEnabled()) { // setup pool where we want an unbounded pool, which allows the pool to shrink on no demand GenericObjectPool.Config config = new GenericObjectPool.Config(); config.maxActive = configuration.getProducerPoolMaxActive(); config.minIdle = configuration.getProducerPoolMinIdle(); config.maxIdle = configuration.getProducerPoolMaxIdle(); // we should test on borrow to ensure the channel is still valid config.testOnBorrow = true;//from www. j av a 2 s. co m // only evict channels which are no longer valid config.testWhileIdle = true; // run eviction every 30th second config.timeBetweenEvictionRunsMillis = 30 * 1000L; config.minEvictableIdleTimeMillis = configuration.getProducerPoolMinEvictableIdle(); config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; pool = new GenericObjectPool<Channel>(new NettyProducerPoolableObjectFactory(), config); if (LOG.isDebugEnabled()) { LOG.debug( "Created NettyProducer pool[maxActive={}, minIdle={}, maxIdle={}, minEvictableIdleTimeMillis={}] -> {}", new Object[] { config.maxActive, config.minIdle, config.maxIdle, config.minEvictableIdleTimeMillis, pool }); } } else { pool = new SharedSingletonObjectPool<Channel>(new NettyProducerPoolableObjectFactory()); if (LOG.isDebugEnabled()) { LOG.info("Created NettyProducer shared singleton pool -> {}", pool); } } // setup pipeline factory ClientPipelineFactory factory = configuration.getClientPipelineFactory(); if (factory != null) { pipelineFactory = factory.createPipelineFactory(this); } else { pipelineFactory = new DefaultClientPipelineFactory(this); } if (isTcp()) { setupTCPCommunication(); } else { setupUDPCommunication(); } if (!configuration.isLazyChannelCreation()) { // ensure the connection can be established when we start up Channel channel = pool.borrowObject(); pool.returnObject(channel); } }
From source file:org.apache.camel.component.netty4.NettyProducer.java
@Override protected void doStart() throws Exception { super.doStart(); if (configuration.isProducerPoolEnabled()) { // setup pool where we want an unbounded pool, which allows the pool to shrink on no demand GenericObjectPool.Config config = new GenericObjectPool.Config(); config.maxActive = configuration.getProducerPoolMaxActive(); config.minIdle = configuration.getProducerPoolMinIdle(); config.maxIdle = configuration.getProducerPoolMaxIdle(); // we should test on borrow to ensure the channel is still valid config.testOnBorrow = true;//from w ww.ja v a 2s .c om // only evict channels which are no longer valid config.testWhileIdle = true; // run eviction every 30th second config.timeBetweenEvictionRunsMillis = 30 * 1000L; config.minEvictableIdleTimeMillis = configuration.getProducerPoolMinEvictableIdle(); config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; pool = new GenericObjectPool<Channel>(new NettyProducerPoolableObjectFactory(), config); if (LOG.isDebugEnabled()) { LOG.debug( "Created NettyProducer pool[maxActive={}, minIdle={}, maxIdle={}, minEvictableIdleTimeMillis={}] -> {}", new Object[] { config.maxActive, config.minIdle, config.maxIdle, config.minEvictableIdleTimeMillis, pool }); } } else { pool = new SharedSingletonObjectPool<Channel>(new NettyProducerPoolableObjectFactory()); if (LOG.isDebugEnabled()) { LOG.info("Created NettyProducer shared singleton pool -> {}", pool); } } timer = new HashedWheelTimer(); // setup pipeline factory ClientPipelineFactory factory = configuration.getClientPipelineFactory(); if (factory != null) { pipelineFactory = factory.createPipelineFactory(this); } else { pipelineFactory = new DefaultClientPipelineFactory(this); } if (!configuration.isLazyChannelCreation()) { // ensure the connection can be established when we start up Channel channel = pool.borrowObject(); pool.returnObject(channel); } }
From source file:org.apache.cayenne.conf.CustomDBCPDataSourceBuilder.java
private ObjectPool createConnectionPool() { ConnectionFactory factory = createConnectionFactory(); GenericObjectPool.Config poolConfig = createConnectionPoolConfig(); KeyedObjectPoolFactory statementPool = createPreparedStatementPool(); String validationQuery = config.getString(VALIDATION_QUERY); boolean defaultReadOnly = config.getBoolean(READ_ONLY, false); boolean defaultAutoCommit = config.getBoolean(AUTO_COMMIT, false); int defaultTransactionIsolation = config.getTransactionIsolation(TRANSACTION_ISOLATION, Connection.TRANSACTION_SERIALIZABLE); String defaultCatalog = config.getString(CATALOG); String initSql = config.getString(INIT_SQL); List<String> initSqls = null; if (initSql != null && !initSql.isEmpty()) { initSqls = new ArrayList<String>(); initSqls.add(initSql);/*from ww w .ja va 2 s .c o m*/ } ObjectPool connectionPool = new GenericObjectPool(null, poolConfig); // a side effect of PoolableConnectionFactory constructor call is that newly // created factory object is assigned to "connectionPool", which is // definitely a // very confusing part of DBCP - new object is not visibly assigned to // anything, // still it is preserved... new PoolableConnectionFactory(factory, connectionPool, statementPool, validationQuery, initSqls, defaultReadOnly ? Boolean.TRUE : Boolean.FALSE, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, null); return connectionPool; }
From source file:org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccess.java
/** * @param connectURI/*from ww w . j av a 2 s. com*/ * @param userName * @param password * @param maxActive max connetions * @throws Exception */ public void setupDriver(String connectURI, String userName, String password, int maxActive) throws Exception { // First, we'll need a ObjectPool that serves as the // actual pool of connections. // We'll use a GenericObjectPool instance, although // any ObjectPool implementation will suffice. ObjectPool connectionPool = new GenericObjectPool(null, maxActive); // TODO make configurable // By dfault the size is 8!!!!!!! ((GenericObjectPool) connectionPool).setMaxIdle(-1); // Next, we'll create a ConnectionFactory that the // pool will use to create Connections. // We'll use the DriverManagerConnectionFactory, // using the connect string passed in the command line // arguments. // Properties props = new Properties(); // props.setProperty( "user", userName ); // props.setProperty( "password", password ); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, userName, password); // Now we'll create the PoolableConnectionFactory, which wraps // the "real" Connections created by the ConnectionFactory with // the classes that implement the pooling functionality. // PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); // Finally, we create the PoolingDriver itself... Class.forName("org.apache.commons.dbcp.PoolingDriver"); PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(DRIVER_NAME); // ...and register our pool with it. driver.registerPool(this.getPoolName(), connectionPool); // Now we can just use the connect string // "jdbc:apache:commons:dbcp:jcs" // to access our pool of Connections. }
From source file:org.apache.kylin.query.adhoc.JdbcConnectionPool.java
public void createPool(JdbcConnectionFactory factory, GenericObjectPool.Config poolConfig) throws IOException { if (this.internalPool != null) this.close(); this.internalPool = new GenericObjectPool(factory, poolConfig); }
From source file:org.apache.metamodel.jdbc.JdbcCompiledQuery.java
public JdbcCompiledQuery(JdbcDataContext dc, Query query) { super(query); _query = query;/*from www. ja va 2 s. c o m*/ _sql = dc.getQueryRewriter().rewriteQuery(query); final Config config = new Config(); config.maxActive = getSystemPropertyValue(JdbcDataContext.SYSTEM_PROPERTY_COMPILED_QUERY_POOL_MAX_SIZE, -1); config.minEvictableIdleTimeMillis = getSystemPropertyValue( JdbcDataContext.SYSTEM_PROPERTY_COMPILED_QUERY_POOL_MIN_EVICTABLE_IDLE_TIME_MILLIS, 500); config.timeBetweenEvictionRunsMillis = getSystemPropertyValue( JdbcDataContext.SYSTEM_PROPERTY_COMPILED_QUERY_POOL_TIME_BETWEEN_EVICTION_RUNS_MILLIS, 1000); _pool = new GenericObjectPool<JdbcCompiledQueryLease>(new JdbcCompiledQueryLeaseFactory(dc, _sql), config); _closed = false; logger.debug("Created compiled JDBC query: {}", _sql); }