List of usage examples for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool
public GenericObjectPool(PooledObjectFactory<T> factory, GenericObjectPoolConfig config)
GenericObjectPool
using a specific configuration. From source file:com.hgcode.jedis.JedisPool.java
/** * Initialize the internal pool with connection info and pool config. *///from w w w . j a v a 2 s .c o m protected void initInternalPool(HostAndPort address, ConnectionInfo connectionInfo, JedisPoolConfig config) { this.poolName = poolName; this.address = address; this.connectionInfo = connectionInfo; JedisFactory factory = new JedisFactory(address.getHost(), address.getPort(), connectionInfo.getTimeout(), connectionInfo.getPassword(), connectionInfo.getDatabase()); internalPool = new GenericObjectPool(factory, config); }
From source file:com.sky.projects.common.redis.pool.JedisPool.java
/** * Initialize the internal pool with connection info and pool config. *///from w w w.j a va2s . c om @SuppressWarnings({ "unchecked", "rawtypes" }) protected void initInternalPool(HostAndPort address, ConnectionInfo connectionInfo, JedisPoolConfig config) { this.address = address; this.connectionInfo = connectionInfo; JedisFactory factory = new JedisFactory(address.getHost(), address.getPort(), connectionInfo.getTimeout(), connectionInfo.getPassword(), connectionInfo.getDatabase()); internalPool = new GenericObjectPool(factory, config); }
From source file:com.zxy.commons.pool.objectpool.ObjectPool.java
/** * /* w w w .j ava 2s .c om*/ * * @param poolConfig poolConfig * @param factory factory */ public ObjectPool(PooledObjectFactory<T> factory, GenericObjectPoolConfig config) { this.internalPool = new GenericObjectPool<T>(factory, config); // this.config = config; }
From source file:me.smoe.hsn.buffer.pool.BufferPool.java
private GenericObjectPool<ChannelBuffer> buildPool(int corePoolSize, int maxPoolSize, int keepAliveTime, int bufferSize) { GenericObjectPoolConfig poolConfig = buildPoolConfig(corePoolSize, maxPoolSize, keepAliveTime); return new GenericObjectPool<>(new BufferFactory(bufferSize), poolConfig); }
From source file:com.skynetcomputing.database.Database.java
/** * Creates a new database connection pool so that statements and queries can be executed. *//*from www. j ava 2 s. c om*/ @SuppressWarnings("unchecked") private Database() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxIdle(5); config.setMaxTotal(10); // Configurable connectionstring. String connString = MiscUtils.getPropertyOrDefault("dbConnection", URL); String connUser = MiscUtils.getPropertyOrDefault("dbUser", USERNAME); String connPassword = MiscUtils.getPropertyOrDefault("dbPassword", PASSWORD); pool = new GenericObjectPool<>(new BasePooledObjectFactory() { @Override public Object create() throws Exception { return DriverManager.getConnection(connString, connUser, connPassword); } @Override public PooledObject wrap(Object o) { return new PooledSoftReference<>(new SoftReference<>(o)); } }, config); }
From source file:com.kurento.kmf.thrift.pool.AbstractPool.java
protected void init(BasePooledObjectFactory<T> factory) { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMinIdle(apiConfig.getClientPoolSize()); config.setTestOnBorrow(true);/*www . j a v a 2 s . c o m*/ config.setTestOnReturn(true); this.pool = PoolUtils.erodingPool(new GenericObjectPool<>(factory, config)); }
From source file:com.baidu.jprotobuf.pbrpc.transport.ChannelPool.java
/** * Instantiates a new channel pool./* w w w . jav a2s.c o m*/ * * @param rpcClient the rpc client * @param host the host * @param port the port */ public ChannelPool(RpcClient rpcClient, String host, int port) { this.clientConfig = rpcClient.getRpcClientOptions(); objectFactory = new ChannelPoolObjectFactory(rpcClient, host, port); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setJmxEnabled(clientConfig.isJmxEnabled()); pool = new GenericObjectPool<Connection>(objectFactory, config); pool.setMaxIdle(clientConfig.getMaxIdleSize()); pool.setMaxTotal(clientConfig.getThreadPoolSize()); pool.setMaxWaitMillis(clientConfig.getMaxWait()); pool.setMinIdle(clientConfig.getMinIdleSize()); pool.setMinEvictableIdleTimeMillis(clientConfig.getMinEvictableIdleTime()); pool.setTestOnBorrow(clientConfig.isTestOnBorrow()); pool.setTestOnReturn(clientConfig.isTestOnReturn()); pool.setLifo(clientConfig.isLifo()); }
From source file:net.sheehantech.cherry.pool.PooledPushClient.java
@Override public void init() throws ConnectionFailedException { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); if (maxTotal != null) config.setMaxTotal(maxTotal);/* w ww. j a va 2 s. c o m*/ if (maxIdle != null) config.setMaxIdle(maxIdle); if (minIdle != null) config.setMinIdle(minIdle); config.setTestOnBorrow(true); config.setTestWhileIdle(true); config.setBlockWhenExhausted(true); pool = new GenericObjectPool<PooledPushSocket>(new PooledPushSocketFactory(socketFactory, gateway, port), config); try { pool.preparePool(); } catch (Exception e) { throw (new ConnectionFailedException(e)); } logger.debug("Started new push socket pool with {} sockets", pool.getNumIdle()); }
From source file:com.reydentx.core.client.MySQLClient.java
private void _initPool() { _clientFactory = new MySqlClientFactory(_url); _maxActive = 100;// ww w. j a va 2 s .c o m _maxIdle = 10; _maxWaitTimeWhenExhausted = 5000L; GenericObjectPoolConfig poolConf = new GenericObjectPoolConfig(); poolConf.setMaxIdle(_maxIdle); poolConf.setMaxTotal(_maxActive); poolConf.setMaxWaitMillis(_maxWaitTimeWhenExhausted); _pool = new GenericObjectPool<Connection>(_clientFactory, poolConf); }
From source file:com.lambdaworks.redis.RedisConnectionPool.java
/** * Create a new connection pool// w w w . j a v a 2 s. com * * @param redisConnectionProvider the connection provider * @param maxActive max active connections * @param maxIdle max idle connections * @param maxWait max wait time (ms) for a connection */ public RedisConnectionPool(RedisConnectionProvider<T> redisConnectionProvider, int maxActive, int maxIdle, long maxWait) { this.redisConnectionProvider = redisConnectionProvider; GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxIdle(maxIdle); config.setMaxTotal(maxActive); config.setMaxWaitMillis(maxWait); config.setTestOnBorrow(true); objectPool = new GenericObjectPool<>(createFactory(redisConnectionProvider), config); }