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, byte whenExhaustedAction, long maxWait,
        boolean testOnBorrow, boolean testOnReturn) 

Source Link

Document

Create a new GenericObjectPool using the specified values.

Usage

From source file:com.sampas.socbs.core.data.arcsde.impl.ArcSDEConnectionPool.java

/**
 * Creates a new SdeConnectionPool object with the connection parameters
 * holded by <code>config</code>
 * /* www.j a v a2 s.  c o  m*/
 * @param config
 *            holds connection options such as server, user and password, as
 *            well as tuning options as maximun number of connections
 *            allowed
 * 
 * @throws DataSourceException
 *             DOCUMENT ME!
 * @throws NullPointerException
 *             DOCUMENT ME!
 */
protected ArcSDEConnectionPool(ArcSDEConnectionConfig config) throws DataSourceException {
    if (config == null) {
        throw new NullPointerException("parameter config can't be null");
    }

    this.config = config;
    LOGGER.fine("populating ArcSDE connection pool");

    this.seConnectionFactory = new SeConnectionFactory(this.config);

    int minConnections = config.getMinConnections().intValue();
    int maxConnections = config.getMaxConnections().intValue();
    // byte exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
    byte exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
    long maxWait = config.getConnTimeOut().longValue();

    this.pool = new GenericObjectPool(seConnectionFactory, maxConnections, exhaustedAction, maxWait, true,
            true);
    LOGGER.info("Created ArcSDE connection pool for " + config);

    ArcSDEPooledConnection[] preload = new ArcSDEPooledConnection[minConnections];

    try {
        for (int i = 0; i < minConnections; i++) {
            preload[i] = (ArcSDEPooledConnection) this.pool.borrowObject();
            if (i == 0) {
                SeRelease seRelease = preload[i].getRelease();
                String sdeDesc = seRelease.getDesc();
                int major = seRelease.getMajor();
                int minor = seRelease.getMinor();
                int bugFix = seRelease.getBugFix();
                String desc = "ArcSDE " + major + "." + minor + "." + bugFix + " " + sdeDesc;
                LOGGER.info("Connected to " + desc);
            }
        }

        for (int i = 0; i < minConnections; i++) {
            this.pool.returnObject(preload[i]);
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "can't connect to " + config, e);
        throw new DataSourceException(e);
    }
}