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);
}
}
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;
}
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();
}
}
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());
}
Aggregations