Example usage for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool

List of usage examples for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool.

Prototype

public GenericObjectPool(PoolableObjectFactory factory, int maxActive) 

Source Link

Document

Create a new GenericObjectPool using the specified values.

Usage

From source file:org.pivot4j.datasource.PooledOlapDataSource.java

/**
 * @param factory/*from ww w. j  a  v a 2s.  com*/
 * @param config
 * @return the pool
 */
protected GenericObjectPool<OlapConnection> createPool(PoolableObjectFactory<OlapConnection> factory,
        GenericObjectPool.Config config) {
    if (logger.isInfoEnabled()) {
        logger.info("Creating connection pool with following parameters : ");
        logger.info("   - max active : {}", config.maxActive);
        logger.info("   - max idle : {}", config.maxIdle);
        logger.info("   - min idle: {}", config.minIdle);
        logger.info("   - max wait : {}", config.maxWait);
    }
    return new GenericObjectPool<OlapConnection>(factory, config);
}

From source file:org.plasma.sdo.jdbc.connect.RDBConnectionManager.java

/**
 * //from w  ww  .  ja  va 2  s.  c o m
 * @param connectURI
 *            - JDBC Connection URI
 * @param username
 *            - JDBC Connection username
 * @param password
 *            - JDBC Connection password
 * @param minIdle
 *            - Minimum number of idel connection in the connection pool
 * @param maxActive
 *            - Connection Pool Maximum Capacity (Size)
 * @throws Exception
 */
private static DataSource setup(String connectURI, String username, String password, int minIdle, int maxActive,
        Map<String, String> props) throws Exception {
    //
    // Create an ObjectPool that serves as the
    // actual pool of connections.
    //
    // Use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    GenericObjectPool.Config config = createGenericObjectPoolConfig(props);

    GenericObjectPool connectionPool = new GenericObjectPool(null, config);

    connectionPool.setMinIdle(minIdle);
    connectionPool.setMaxActive(maxActive);

    RDBConnectionManager._pool = connectionPool;
    // We keep it for two reasons
    // #1 We need it for statistics/debugging
    // #2 PoolingDataSource does not have getPool()
    // method, for some obscure, weird reason.

    //
    // Create a ConnectionFactory that the
    // pool will use to create Connections.
    // Use the DriverManagerConnectionFactory,
    // using the connect string from configuration
    //
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, username, password);

    //
    // 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);

    String value = getValue(DBCP_VALIDATIONQUERY, props);
    if (value != null) {
        try {
            poolableConnectionFactory.setValidationQuery(value);
        } catch (Exception e) {
            throw new JDBCServiceException(e);
        }
    }

    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);

    return dataSource;
}

From source file:org.quickserver.net.server.impl.BasicPoolManager.java

public ObjectPool makeByteBufferPool(PoolableObjectFactory factory, PoolConfig opConfig) {
    GenericObjectPool.Config bconfig = configurePool(opConfig);
    bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
    return new GenericObjectPool(factory, bconfig);
}

From source file:org.quickserver.net.server.impl.BasicPoolManager.java

public ObjectPool makeClientPool(PoolableObjectFactory factory, PoolConfig opConfig) {
    GenericObjectPool.Config bconfig = configurePool(opConfig);
    bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
    return new GenericObjectPool(factory, bconfig);
}

From source file:org.quickserver.net.server.impl.BasicPoolManager.java

public ObjectPool makeClientHandlerPool(PoolableObjectFactory factory, PoolConfig opConfig) {
    GenericObjectPool.Config bconfig = configurePool(opConfig);
    bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
    return new GenericObjectPool(factory, bconfig);
}

From source file:org.quickserver.net.server.impl.BasicPoolManager.java

public ObjectPool makeClientDataPool(PoolableObjectFactory factory, PoolConfig opConfig) {
    GenericObjectPool.Config bconfig = configurePool(opConfig);
    bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
    return new GenericObjectPool(factory, bconfig);
}

From source file:org.ralasafe.db.DataSourceProviderDbcpImpl.java

public void setup(Properties prop) {
    this.prop = prop;

    GenericObjectPool.Config conPoolCfg = new GenericObjectPool.Config();
    conPoolCfg.maxActive = Integer.parseInt(prop.getProperty("connectionPoolMaxSize", "15"));
    conPoolCfg.maxIdle = Integer.parseInt(prop.getProperty("connectionPoolMaxIdle", "8"));
    conPoolCfg.maxWait = Integer.parseInt(prop.getProperty("connectionPoolMaxWait", "60000"));
    conPoolCfg.minIdle = Integer.parseInt(prop.getProperty("connectionPoolMinSize", "2"));

    ObjectPool connectionPool = new GenericObjectPool(null, conPoolCfg);
    try {/*from   ww w.ja v  a 2 s .c o  m*/
        Class.forName(prop.getProperty("jdbcDriver"));
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        throw new RuntimeException();
    }

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(prop.getProperty("jdbcUrl"),
            prop.getProperty("jdbcUser"), prop.getProperty("jdbcPassword"));

    new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);

    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);

    ds = dataSource;
}

From source file:org.speechforge.cairo.server.recog.sphinx.SphinxRecEngineFactory.java

/**
 * TODOC/*from w w w  .  ja  va 2 s. c  o  m*/
 * @param sphinxConfigURL
 * @param instances
 * @return
 * @throws InstantiationException if initializing the object pool triggers an exception.
 */
public static ObjectPool createObjectPool(URL sphinxConfigURL, int instances) throws InstantiationException {

    if (_logger.isDebugEnabled()) {
        _logger.debug("creating new rec engine pool... instances: " + instances);
    }

    PoolableObjectFactory factory = new SphinxRecEngineFactory(sphinxConfigURL);
    GenericObjectPool.Config config = ObjectPoolUtil.getGenericObjectPoolConfig(instances);

    ObjectPool objectPool = new GenericObjectPool(factory, config);
    initPool(objectPool);
    return objectPool;
}

From source file:org.speechforge.cairo.server.recorder.sphinx.SphinxRecorderFactory.java

/**
 * TODOC//ww w.  j a v  a  2s. c  om
 * @param sphinxConfigURL
 * @param instances
 * @return
 * @throws InstantiationException if initializing the object pool triggers an exception.
 */
public static ObjectPool createObjectPool(URL sphinxConfigURL, int instances) throws InstantiationException {

    if (_logger.isDebugEnabled()) {
        _logger.debug("creating new rec engine pool... instances: " + instances);
    }

    PoolableObjectFactory factory = new SphinxRecorderFactory(sphinxConfigURL);
    GenericObjectPool.Config config = ObjectPoolUtil.getGenericObjectPoolConfig(instances);

    ObjectPool objectPool = new GenericObjectPool(factory, config);
    initPool(objectPool);
    return objectPool;
}

From source file:org.speechforge.cairo.server.tts.PromptGeneratorFactory.java

/**
 * TODOC//www .  jav a 2  s  . co m
 * @param instances
 * @return
 */
public static ObjectPool createObjectPool(String voiceName, int instances, String speechSynthesizer)
        throws InstantiationException {

    if (_logger.isDebugEnabled()) {
        _logger.debug("creating new prompt generator pool... instances: " + instances);
    }

    PoolableObjectFactory factory = new PromptGeneratorFactory(voiceName, speechSynthesizer);

    // TODO: adapt config to prompt generator constraints
    GenericObjectPool.Config config = ObjectPoolUtil.getGenericObjectPoolConfig(instances);
    ObjectPool objectPool = new GenericObjectPool(factory, config);
    initPool(objectPool);
    return objectPool;
}