Search in sources :

Example 6 with GenericObjectPool

use of org.apache.commons.pool.impl.GenericObjectPool in project camel by apache.

the class NettyProducer method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    if (configuration.getWorkerGroup() == null) {
        // create new pool which we should shutdown when stopping as its not shared
        workerGroup = new NettyWorkerPoolBuilder().withNativeTransport(configuration.isNativeTransport()).withWorkerCount(configuration.getWorkerCount()).withName("NettyClientTCPWorker").build();
    }
    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;
        // 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<ChannelFuture>(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<ChannelFuture>(new NettyProducerPoolableObjectFactory());
        if (LOG.isDebugEnabled()) {
            LOG.info("Created NettyProducer shared singleton pool -> {}", pool);
        }
    }
    // setup pipeline factory
    ClientInitializerFactory factory = configuration.getClientInitializerFactory();
    if (factory != null) {
        pipelineFactory = factory.createPipelineFactory(this);
    } else {
        pipelineFactory = new DefaultClientInitializerFactory(this);
    }
    // setup channel group
    if (configuration.getChannelGroup() == null) {
        allChannels = new DefaultChannelGroup("NettyProducer", ImmediateEventExecutor.INSTANCE);
    } else {
        allChannels = configuration.getChannelGroup();
    }
    if (!configuration.isLazyChannelCreation()) {
        // ensure the connection can be established when we start up
        ChannelFuture channelFuture = pool.borrowObject();
        channelFuture.get();
        pool.returnObject(channelFuture);
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) GenericObjectPool(org.apache.commons.pool.impl.GenericObjectPool)

Example 7 with GenericObjectPool

use of org.apache.commons.pool.impl.GenericObjectPool in project Solbase by Photobucket.

the class SolbaseHTablePool2 method getTable.

public HTableInterface getTable(String tableName) {
    GenericObjectPool pool = this.tablePools.get(tableName);
    if (pool == null) {
        // lazy initialization of pool
        PoolableObjectFactory factory = new SolbaseHTableInterfaceFactory(config, tableName);
        pool = new GenericObjectPool(factory, this.maxActive);
    }
    try {
        HTableInterface table = (HTableInterface) pool.borrowObject();
        return table;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : GenericObjectPool(org.apache.commons.pool.impl.GenericObjectPool) PoolableObjectFactory(org.apache.commons.pool.PoolableObjectFactory)

Example 8 with GenericObjectPool

use of org.apache.commons.pool.impl.GenericObjectPool in project Solbase by Photobucket.

the class SolbaseHTablePool2 method putTable.

public void putTable(HTableInterface table) {
    String tableName = Bytes.toString(table.getTableName());
    GenericObjectPool pool = this.tablePools.get(tableName);
    try {
        pool.returnObject(table);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : GenericObjectPool(org.apache.commons.pool.impl.GenericObjectPool)

Example 9 with GenericObjectPool

use of org.apache.commons.pool.impl.GenericObjectPool in project cloudstack by apache.

the class TransactionLegacy method getDefaultDataSource.

@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());
}
Also used : PoolableConnectionFactory(org.apache.commons.dbcp.PoolableConnectionFactory) ConnectionFactory(org.apache.commons.dbcp.ConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp.DriverManagerConnectionFactory) PoolingDataSource(org.apache.commons.dbcp.PoolingDataSource) DriverManagerConnectionFactory(org.apache.commons.dbcp.DriverManagerConnectionFactory) GenericObjectPool(org.apache.commons.pool.impl.GenericObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp.PoolableConnectionFactory)

Aggregations

GenericObjectPool (org.apache.commons.pool.impl.GenericObjectPool)9 ConnectionFactory (org.apache.commons.dbcp.ConnectionFactory)4 PoolableConnectionFactory (org.apache.commons.dbcp.PoolableConnectionFactory)4 PoolingDataSource (org.apache.commons.dbcp.PoolingDataSource)4 DriverManagerConnectionFactory (org.apache.commons.dbcp.DriverManagerConnectionFactory)3 SQLException (java.sql.SQLException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 BoneCPConfig (com.jolbox.bonecp.BoneCPConfig)1 BoneCPDataSource (com.jolbox.bonecp.BoneCPDataSource)1 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 ServiceException (com.zimbra.common.service.ServiceException)1 ChannelFuture (io.netty.channel.ChannelFuture)1 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)1 IOException (java.io.IOException)1 Savepoint (java.sql.Savepoint)1 KeyedObjectPoolFactory (org.apache.commons.pool.KeyedObjectPoolFactory)1 ObjectPool (org.apache.commons.pool.ObjectPool)1 PoolableObjectFactory (org.apache.commons.pool.PoolableObjectFactory)1